[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> |
[email protected] | 5285d97 | 2011-10-18 18:56:34 | [diff] [blame] | 13 | #include <string> |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 14 | #include <utility> |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 15 | #include <vector> |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 16 | |
[email protected] | 68bf915 | 2008-09-25 19:47:30 | [diff] [blame] | 17 | #include "base/compiler_specific.h" |
[email protected] | 5799981 | 2013-02-24 05:40:52 | [diff] [blame] | 18 | #include "base/files/file_path.h" |
thestig | d8df033 | 2014-09-04 06:33:29 | [diff] [blame] | 19 | #include "base/files/file_util.h" |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 20 | #include "base/json/json_writer.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 21 | #include "base/logging.h" |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 22 | #include "base/macros.h" |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 23 | #include "base/memory/ptr_util.h" |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 24 | #include "base/memory/weak_ptr.h" |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 25 | #include "base/run_loop.h" |
[email protected] | 125ef48 | 2013-06-11 18:32:47 | [diff] [blame] | 26 | #include "base/strings/string_util.h" |
[email protected] | 750b2f3c | 2013-06-07 18:41:05 | [diff] [blame] | 27 | #include "base/strings/utf_string_conversions.h" |
[email protected] | f36a813 | 2011-09-02 18:36:33 | [diff] [blame] | 28 | #include "base/test/test_file_util.h" |
gab | f767595f | 2016-05-11 18:50:35 | [diff] [blame] | 29 | #include "base/threading/thread_task_runner_handle.h" |
[email protected] | 277d594 | 2010-08-11 21:02:35 | [diff] [blame] | 30 | #include "net/base/auth.h" |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 31 | #include "net/base/chunked_upload_data_stream.h" |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 32 | #include "net/base/completion_callback.h" |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 33 | #include "net/base/elements_upload_data_stream.h" |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 34 | #include "net/base/load_timing_info.h" |
| 35 | #include "net/base/load_timing_info_test_util.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 36 | #include "net/base/net_errors.h" |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 37 | #include "net/base/proxy_delegate.h" |
[email protected] | ac790b4 | 2009-12-02 04:31:31 | [diff] [blame] | 38 | #include "net/base/request_priority.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 39 | #include "net/base/test_completion_callback.h" |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 40 | #include "net/base/test_proxy_delegate.h" |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 41 | #include "net/base/upload_bytes_element_reader.h" |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 42 | #include "net/base/upload_file_element_reader.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 43 | #include "net/cert/mock_cert_verifier.h" |
[email protected] | bc71b877 | 2013-04-10 20:55:16 | [diff] [blame] | 44 | #include "net/dns/host_cache.h" |
[email protected] | f2cb3cf | 2013-03-21 01:40:53 | [diff] [blame] | 45 | #include "net/dns/mock_host_resolver.h" |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 46 | #include "net/http/http_auth_challenge_tokenizer.h" |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 47 | #include "net/http/http_auth_handler_digest.h" |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 48 | #include "net/http/http_auth_handler_mock.h" |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 49 | #include "net/http/http_auth_handler_ntlm.h" |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 50 | #include "net/http/http_auth_scheme.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 51 | #include "net/http/http_basic_state.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 52 | #include "net/http/http_basic_stream.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 53 | #include "net/http/http_network_session.h" |
[email protected] | 87bfa3f | 2010-09-30 14:54:56 | [diff] [blame] | 54 | #include "net/http/http_network_session_peer.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 55 | #include "net/http/http_request_headers.h" |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 56 | #include "net/http/http_response_info.h" |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 57 | #include "net/http/http_server_properties_impl.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 58 | #include "net/http/http_stream.h" |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 59 | #include "net/http/http_stream_factory.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 60 | #include "net/http/http_stream_parser.h" |
[email protected] | c41737d | 2014-05-14 07:47:19 | [diff] [blame] | 61 | #include "net/http/http_transaction_test_util.h" |
eroman | 87c53d6 | 2015-04-02 06:51:07 | [diff] [blame] | 62 | #include "net/log/net_log.h" |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 63 | #include "net/log/net_log_event_type.h" |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 64 | #include "net/log/test_net_log.h" |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 65 | #include "net/log/test_net_log_entry.h" |
| 66 | #include "net/log/test_net_log_util.h" |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 67 | #include "net/proxy/mock_proxy_resolver.h" |
[email protected] | 51fff29d | 2008-12-19 22:17:53 | [diff] [blame] | 68 | #include "net/proxy/proxy_config_service_fixed.h" |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 69 | #include "net/proxy/proxy_info.h" |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 70 | #include "net/proxy/proxy_resolver.h" |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 71 | #include "net/proxy/proxy_server.h" |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 72 | #include "net/proxy/proxy_service.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 73 | #include "net/socket/client_socket_factory.h" |
mmenke | d3641e1 | 2016-01-28 16:06:15 | [diff] [blame] | 74 | #include "net/socket/client_socket_pool.h" |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 75 | #include "net/socket/client_socket_pool_manager.h" |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 76 | #include "net/socket/connection_attempts.h" |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 77 | #include "net/socket/mock_client_socket_pool_manager.h" |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 78 | #include "net/socket/next_proto.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 79 | #include "net/socket/socket_test_util.h" |
| 80 | #include "net/socket/ssl_client_socket.h" |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 81 | #include "net/spdy/spdy_framer.h" |
| 82 | #include "net/spdy/spdy_session.h" |
| 83 | #include "net/spdy/spdy_session_pool.h" |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 84 | #include "net/spdy/spdy_test_util_common.h" |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 85 | #include "net/ssl/default_channel_id_store.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 86 | #include "net/ssl/ssl_cert_request_info.h" |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 87 | #include "net/ssl/ssl_config_service.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 88 | #include "net/ssl/ssl_config_service_defaults.h" |
| 89 | #include "net/ssl/ssl_info.h" |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 90 | #include "net/ssl/ssl_private_key.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 91 | #include "net/test/cert_test_util.h" |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 92 | #include "net/test/gtest_util.h" |
rsleevi | a69c79a | 2016-06-22 03:28:43 | [diff] [blame] | 93 | #include "net/test/test_data_directory.h" |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 94 | #include "net/websockets/websocket_handshake_stream_base.h" |
bnc | f458840 | 2015-11-24 13:33:18 | [diff] [blame] | 95 | #include "testing/gmock/include/gmock/gmock.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 96 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | 23887f04f | 2008-12-02 19:20:15 | [diff] [blame] | 97 | #include "testing/platform_test.h" |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 98 | #include "url/gurl.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 99 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 100 | using net::test::IsError; |
| 101 | using net::test::IsOk; |
| 102 | |
[email protected] | ad65a3e | 2013-12-25 18:18:01 | [diff] [blame] | 103 | using base::ASCIIToUTF16; |
| 104 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 105 | //----------------------------------------------------------------------------- |
| 106 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 107 | namespace net { |
| 108 | |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 109 | namespace { |
| 110 | |
[email protected] | 42cba2fb | 2013-03-29 19:58:57 | [diff] [blame] | 111 | const base::string16 kBar(ASCIIToUTF16("bar")); |
| 112 | const base::string16 kBar2(ASCIIToUTF16("bar2")); |
| 113 | const base::string16 kBar3(ASCIIToUTF16("bar3")); |
| 114 | const base::string16 kBaz(ASCIIToUTF16("baz")); |
| 115 | const base::string16 kFirst(ASCIIToUTF16("first")); |
| 116 | const base::string16 kFoo(ASCIIToUTF16("foo")); |
| 117 | const base::string16 kFoo2(ASCIIToUTF16("foo2")); |
| 118 | const base::string16 kFoo3(ASCIIToUTF16("foo3")); |
| 119 | const base::string16 kFou(ASCIIToUTF16("fou")); |
| 120 | const base::string16 kSecond(ASCIIToUTF16("second")); |
| 121 | const base::string16 kTestingNTLM(ASCIIToUTF16("testing-ntlm")); |
| 122 | const base::string16 kWrongPassword(ASCIIToUTF16("wrongpassword")); |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 123 | |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 124 | const char kAlternativeServiceHttpHeader[] = |
| 125 | "Alt-Svc: h2=\"mail.example.org:443\"\r\n"; |
| 126 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 127 | int GetIdleSocketCountInTransportSocketPool(HttpNetworkSession* session) { |
| 128 | return session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 129 | ->IdleSocketCount(); |
[email protected] | e5c02664 | 2012-03-17 00:14:02 | [diff] [blame] | 130 | } |
| 131 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 132 | int GetIdleSocketCountInSSLSocketPool(HttpNetworkSession* session) { |
| 133 | return session->GetSSLSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 134 | ->IdleSocketCount(); |
[email protected] | e5c02664 | 2012-03-17 00:14:02 | [diff] [blame] | 135 | } |
| 136 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 137 | bool IsTransportSocketPoolStalled(HttpNetworkSession* session) { |
| 138 | return session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 139 | ->IsStalled(); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 140 | } |
| 141 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 142 | // Takes in a Value created from a NetLogHttpResponseParameter, and returns |
| 143 | // a JSONified list of headers as a single string. Uses single quotes instead |
| 144 | // of double quotes for easier comparison. Returns false on failure. |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 145 | bool GetHeaders(base::DictionaryValue* params, std::string* headers) { |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 146 | if (!params) |
| 147 | return false; |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 148 | base::ListValue* header_list; |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 149 | if (!params->GetList("headers", &header_list)) |
| 150 | return false; |
| 151 | std::string double_quote_headers; |
estade | 8d04646 | 2015-05-16 01:02:34 | [diff] [blame] | 152 | base::JSONWriter::Write(*header_list, &double_quote_headers); |
[email protected] | 466c986 | 2013-12-03 22:05:28 | [diff] [blame] | 153 | base::ReplaceChars(double_quote_headers, "\"", "'", headers); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 154 | return true; |
| 155 | } |
| 156 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 157 | // Tests LoadTimingInfo in the case a socket is reused and no PAC script is |
| 158 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 159 | void TestLoadTimingReused(const LoadTimingInfo& load_timing_info) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 160 | EXPECT_TRUE(load_timing_info.socket_reused); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 161 | EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 162 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 163 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 164 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 165 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 166 | ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 167 | EXPECT_FALSE(load_timing_info.send_start.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 168 | |
| 169 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 170 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 171 | // Set at a higher level. |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 172 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 173 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 174 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 175 | } |
| 176 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 177 | // Tests LoadTimingInfo in the case a new socket is used and no PAC script is |
| 178 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 179 | void TestLoadTimingNotReused(const LoadTimingInfo& load_timing_info, |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 180 | int connect_timing_flags) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 181 | EXPECT_FALSE(load_timing_info.socket_reused); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 182 | EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 183 | |
| 184 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 185 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 186 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 187 | ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 188 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 189 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 190 | load_timing_info.send_start); |
| 191 | |
| 192 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 193 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 194 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 195 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 196 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 197 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | // Tests LoadTimingInfo in the case a socket is reused and a PAC script is |
| 201 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 202 | void TestLoadTimingReusedWithPac(const LoadTimingInfo& load_timing_info) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 203 | EXPECT_TRUE(load_timing_info.socket_reused); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 204 | EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 205 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 206 | ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 207 | |
| 208 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 209 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 210 | load_timing_info.proxy_resolve_end); |
| 211 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 212 | load_timing_info.send_start); |
| 213 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 214 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 215 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 216 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 217 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 218 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | // Tests LoadTimingInfo in the case a new socket is used and a PAC script is |
| 222 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 223 | void TestLoadTimingNotReusedWithPac(const LoadTimingInfo& load_timing_info, |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 224 | int connect_timing_flags) { |
| 225 | EXPECT_FALSE(load_timing_info.socket_reused); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 226 | EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 227 | |
| 228 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 229 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 230 | load_timing_info.proxy_resolve_end); |
| 231 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 232 | load_timing_info.connect_timing.connect_start); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 233 | ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 234 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 235 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 236 | load_timing_info.send_start); |
| 237 | |
| 238 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 239 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 240 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 241 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 242 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 243 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 244 | } |
| 245 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 246 | void AddWebSocketHeaders(HttpRequestHeaders* headers) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 247 | headers->SetHeader("Connection", "Upgrade"); |
| 248 | headers->SetHeader("Upgrade", "websocket"); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 249 | headers->SetHeader("Origin", "http://www.example.org"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 250 | headers->SetHeader("Sec-WebSocket-Version", "13"); |
| 251 | headers->SetHeader("Sec-WebSocket-Key", "dGhlIHNhbXBsZSBub25jZQ=="); |
| 252 | } |
| 253 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 254 | std::unique_ptr<HttpNetworkSession> CreateSession( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 255 | SpdySessionDependencies* session_deps) { |
[email protected] | c6bf815 | 2012-12-02 07:43:34 | [diff] [blame] | 256 | return SpdySessionDependencies::SpdyCreateSession(session_deps); |
[email protected] | e8d53619 | 2008-10-17 22:21:14 | [diff] [blame] | 257 | } |
| 258 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 259 | } // namespace |
| 260 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 261 | class HttpNetworkTransactionTest : public PlatformTest { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 262 | public: |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 263 | ~HttpNetworkTransactionTest() override { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 264 | // Important to restore the per-pool limit first, since the pool limit must |
| 265 | // always be greater than group limit, and the tests reduce both limits. |
| 266 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 267 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_pool_sockets_); |
| 268 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 269 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_group_sockets_); |
| 270 | } |
| 271 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 272 | protected: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 273 | HttpNetworkTransactionTest() |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 274 | : old_max_group_sockets_(ClientSocketPoolManager::max_sockets_per_group( |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 275 | HttpNetworkSession::NORMAL_SOCKET_POOL)), |
| 276 | old_max_pool_sockets_(ClientSocketPoolManager::max_sockets_per_pool( |
| 277 | HttpNetworkSession::NORMAL_SOCKET_POOL)) { |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 278 | session_deps_.enable_http2_alternative_service_with_different_host = true; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 279 | } |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 280 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 281 | struct SimpleGetHelperResult { |
| 282 | int rv; |
| 283 | std::string status_line; |
| 284 | std::string response_data; |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 285 | int64_t total_received_bytes; |
| 286 | int64_t total_sent_bytes; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 287 | LoadTimingInfo load_timing_info; |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 288 | ConnectionAttempts connection_attempts; |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 289 | IPEndPoint remote_endpoint_after_start; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 290 | }; |
| 291 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 292 | void SetUp() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 293 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 294 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 295 | } |
| 296 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 297 | void TearDown() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 298 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 299 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 300 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 301 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 302 | PlatformTest::TearDown(); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 303 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 304 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 305 | } |
| 306 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 307 | // Either |write_failure| specifies a write failure or |read_failure| |
| 308 | // specifies a read failure when using a reused socket. In either case, the |
| 309 | // failure should cause the network transaction to resend the request, and the |
| 310 | // other argument should be NULL. |
| 311 | void KeepAliveConnectionResendRequestTest(const MockWrite* write_failure, |
| 312 | const MockRead* read_failure); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 313 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 314 | // Either |write_failure| specifies a write failure or |read_failure| |
| 315 | // specifies a read failure when using a reused socket. In either case, the |
| 316 | // failure should cause the network transaction to resend the request, and the |
| 317 | // other argument should be NULL. |
| 318 | void PreconnectErrorResendRequestTest(const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 319 | const MockRead* read_failure, |
| 320 | bool use_spdy); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 321 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 322 | SimpleGetHelperResult SimpleGetHelperForData(StaticSocketDataProvider* data[], |
| 323 | size_t data_count) { |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 324 | SimpleGetHelperResult out; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 325 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 326 | HttpRequestInfo request; |
| 327 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 328 | request.url = GURL("http://www.example.org/"); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 329 | request.load_flags = 0; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 330 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 331 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 332 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 333 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 334 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 335 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 336 | for (size_t i = 0; i < data_count; ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 337 | session_deps_.socket_factory->AddSocketDataProvider(data[i]); |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 338 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 339 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 340 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 341 | |
eroman | 24bc6a1 | 2015-05-06 19:55:48 | [diff] [blame] | 342 | EXPECT_TRUE(log.bound().IsCapturing()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 343 | int rv = trans.Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 344 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 345 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 346 | out.rv = callback.WaitForResult(); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 347 | out.total_received_bytes = trans.GetTotalReceivedBytes(); |
| 348 | out.total_sent_bytes = trans.GetTotalSentBytes(); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 349 | |
| 350 | // Even in the failure cases that use this function, connections are always |
| 351 | // successfully established before the error. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 352 | EXPECT_TRUE(trans.GetLoadTimingInfo(&out.load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 353 | TestLoadTimingNotReused(out.load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 354 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 355 | if (out.rv != OK) |
| 356 | return out; |
| 357 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 358 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 359 | // Can't use ASSERT_* inside helper functions like this, so |
| 360 | // return an error. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 361 | if (!response || !response->headers) { |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 362 | out.rv = ERR_UNEXPECTED; |
| 363 | return out; |
| 364 | } |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 365 | out.status_line = response->headers->GetStatusLine(); |
| 366 | |
[email protected] | 80a09a8 | 2012-11-16 17:40:06 | [diff] [blame] | 367 | EXPECT_EQ("127.0.0.1", response->socket_address.host()); |
| 368 | EXPECT_EQ(80, response->socket_address.port()); |
[email protected] | 6d81b48 | 2011-02-22 19:47:19 | [diff] [blame] | 369 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 370 | bool got_endpoint = |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 371 | trans.GetRemoteEndpoint(&out.remote_endpoint_after_start); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 372 | EXPECT_EQ(got_endpoint, |
| 373 | out.remote_endpoint_after_start.address().size() > 0); |
| 374 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 375 | rv = ReadTransaction(&trans, &out.response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 376 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 377 | |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 378 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 379 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 380 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 381 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_REQUEST_HEADERS, |
| 382 | NetLogEventPhase::NONE); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 383 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 384 | entries, pos, NetLogEventType::HTTP_TRANSACTION_READ_RESPONSE_HEADERS, |
| 385 | NetLogEventPhase::NONE); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 386 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 387 | std::string line; |
| 388 | EXPECT_TRUE(entries[pos].GetStringValue("line", &line)); |
| 389 | EXPECT_EQ("GET / HTTP/1.1\r\n", line); |
| 390 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 391 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 392 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 393 | std::string value; |
| 394 | EXPECT_TRUE(request_headers.GetHeader("Host", &value)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 395 | EXPECT_EQ("www.example.org", value); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 396 | EXPECT_TRUE(request_headers.GetHeader("Connection", &value)); |
| 397 | EXPECT_EQ("keep-alive", value); |
| 398 | |
| 399 | std::string response_headers; |
| 400 | EXPECT_TRUE(GetHeaders(entries[pos].params.get(), &response_headers)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 401 | EXPECT_EQ("['Host: www.example.org','Connection: keep-alive']", |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 402 | response_headers); |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 403 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 404 | out.total_received_bytes = trans.GetTotalReceivedBytes(); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 405 | // The total number of sent bytes should not have changed. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 406 | EXPECT_EQ(out.total_sent_bytes, trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 407 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 408 | trans.GetConnectionAttempts(&out.connection_attempts); |
[email protected] | aecfbf2 | 2008-10-16 02:02:47 | [diff] [blame] | 409 | return out; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 410 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 411 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 412 | SimpleGetHelperResult SimpleGetHelper(MockRead data_reads[], |
| 413 | size_t reads_count) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 414 | MockWrite data_writes[] = { |
| 415 | MockWrite("GET / HTTP/1.1\r\n" |
| 416 | "Host: www.example.org\r\n" |
| 417 | "Connection: keep-alive\r\n\r\n"), |
| 418 | }; |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 419 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 420 | StaticSocketDataProvider reads(data_reads, reads_count, data_writes, |
| 421 | arraysize(data_writes)); |
| 422 | StaticSocketDataProvider* data[] = {&reads}; |
| 423 | SimpleGetHelperResult out = SimpleGetHelperForData(data, 1); |
| 424 | |
| 425 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
| 426 | out.total_sent_bytes); |
| 427 | return out; |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 428 | } |
| 429 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 430 | void ConnectStatusHelperWithExpectedStatus(const MockRead& status, |
| 431 | int expected_status); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 432 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 433 | void ConnectStatusHelper(const MockRead& status); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 434 | |
| 435 | void BypassHostCacheOnRefreshHelper(int load_flags); |
| 436 | |
| 437 | void CheckErrorIsPassedBack(int error, IoMode mode); |
| 438 | |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 439 | SpdyTestUtil spdy_util_; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 440 | SpdySessionDependencies session_deps_; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 441 | |
| 442 | // Original socket limits. Some tests set these. Safest to always restore |
| 443 | // them once each test has been run. |
| 444 | int old_max_group_sockets_; |
| 445 | int old_max_pool_sockets_; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 446 | }; |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 447 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 448 | namespace { |
| 449 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 450 | class BeforeHeadersSentHandler { |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 451 | public: |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 452 | BeforeHeadersSentHandler() |
| 453 | : observed_before_headers_sent_with_proxy_(false), |
| 454 | observed_before_headers_sent_(false) {} |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 455 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 456 | void OnBeforeHeadersSent(const ProxyInfo& proxy_info, |
| 457 | HttpRequestHeaders* request_headers) { |
| 458 | observed_before_headers_sent_ = true; |
| 459 | if (!proxy_info.is_http() && !proxy_info.is_https() && |
| 460 | !proxy_info.is_quic()) { |
| 461 | return; |
| 462 | } |
| 463 | observed_before_headers_sent_with_proxy_ = true; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 464 | observed_proxy_server_uri_ = proxy_info.proxy_server().ToURI(); |
| 465 | } |
| 466 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 467 | bool observed_before_headers_sent_with_proxy() const { |
| 468 | return observed_before_headers_sent_with_proxy_; |
| 469 | } |
| 470 | |
| 471 | bool observed_before_headers_sent() const { |
| 472 | return observed_before_headers_sent_; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 473 | } |
| 474 | |
| 475 | std::string observed_proxy_server_uri() const { |
| 476 | return observed_proxy_server_uri_; |
| 477 | } |
| 478 | |
| 479 | private: |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 480 | bool observed_before_headers_sent_with_proxy_; |
| 481 | bool observed_before_headers_sent_; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 482 | std::string observed_proxy_server_uri_; |
| 483 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 484 | DISALLOW_COPY_AND_ASSIGN(BeforeHeadersSentHandler); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 485 | }; |
| 486 | |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 487 | // Fill |str| with a long header list that consumes >= |size| bytes. |
| 488 | void FillLargeHeadersString(std::string* str, int size) { |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 489 | const char row[] = |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 490 | "SomeHeaderName: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n"; |
| 491 | const int sizeof_row = strlen(row); |
| 492 | const int num_rows = static_cast<int>( |
| 493 | ceil(static_cast<float>(size) / sizeof_row)); |
| 494 | const int sizeof_data = num_rows * sizeof_row; |
| 495 | DCHECK(sizeof_data >= size); |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 496 | str->reserve(sizeof_data); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 497 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 498 | for (int i = 0; i < num_rows; ++i) |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 499 | str->append(row, sizeof_row); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 500 | } |
| 501 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 502 | #if defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 503 | // Alternative functions that eliminate randomness and dependency on the local |
| 504 | // host name so that the generated NTLM messages are reproducible. |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 505 | void MockGenerateRandom1(uint8_t* output, size_t n) { |
| 506 | static const uint8_t bytes[] = {0x55, 0x29, 0x66, 0x26, |
| 507 | 0x6b, 0x9c, 0x73, 0x54}; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 508 | static size_t current_byte = 0; |
| 509 | for (size_t i = 0; i < n; ++i) { |
| 510 | output[i] = bytes[current_byte++]; |
| 511 | current_byte %= arraysize(bytes); |
| 512 | } |
| 513 | } |
| 514 | |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 515 | void MockGenerateRandom2(uint8_t* output, size_t n) { |
| 516 | static const uint8_t bytes[] = {0x96, 0x79, 0x85, 0xe7, 0x49, 0x93, |
| 517 | 0x70, 0xa1, 0x4e, 0xe7, 0x87, 0x45, |
| 518 | 0x31, 0x5b, 0xd3, 0x1f}; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 519 | static size_t current_byte = 0; |
| 520 | for (size_t i = 0; i < n; ++i) { |
| 521 | output[i] = bytes[current_byte++]; |
| 522 | current_byte %= arraysize(bytes); |
| 523 | } |
| 524 | } |
| 525 | |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 526 | std::string MockGetHostName() { |
| 527 | return "WTC-WIN7"; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 528 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 529 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 530 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 531 | template<typename ParentPool> |
| 532 | class CaptureGroupNameSocketPool : public ParentPool { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 533 | public: |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 534 | CaptureGroupNameSocketPool(HostResolver* host_resolver, |
| 535 | CertVerifier* cert_verifier); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 536 | |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 537 | const std::string last_group_name_received() const { |
| 538 | return last_group_name_; |
| 539 | } |
| 540 | |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 541 | int RequestSocket(const std::string& group_name, |
| 542 | const void* socket_params, |
| 543 | RequestPriority priority, |
mmenke | d3641e1 | 2016-01-28 16:06:15 | [diff] [blame] | 544 | ClientSocketPool::RespectLimits respect_limits, |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 545 | ClientSocketHandle* handle, |
| 546 | const CompletionCallback& callback, |
| 547 | const BoundNetLog& net_log) override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 548 | last_group_name_ = group_name; |
| 549 | return ERR_IO_PENDING; |
| 550 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 551 | void CancelRequest(const std::string& group_name, |
| 552 | ClientSocketHandle* handle) override {} |
| 553 | void ReleaseSocket(const std::string& group_name, |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 554 | std::unique_ptr<StreamSocket> socket, |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 555 | int id) override {} |
| 556 | void CloseIdleSockets() override {} |
| 557 | int IdleSocketCount() const override { return 0; } |
| 558 | int IdleSocketCountInGroup(const std::string& group_name) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 559 | return 0; |
| 560 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 561 | LoadState GetLoadState(const std::string& group_name, |
| 562 | const ClientSocketHandle* handle) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 563 | return LOAD_STATE_IDLE; |
| 564 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 565 | base::TimeDelta ConnectionTimeout() const override { |
[email protected] | a796bcec | 2010-03-22 17:17:26 | [diff] [blame] | 566 | return base::TimeDelta(); |
| 567 | } |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 568 | |
| 569 | private: |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 570 | std::string last_group_name_; |
| 571 | }; |
| 572 | |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 573 | typedef CaptureGroupNameSocketPool<TransportClientSocketPool> |
| 574 | CaptureGroupNameTransportSocketPool; |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 575 | typedef CaptureGroupNameSocketPool<HttpProxyClientSocketPool> |
| 576 | CaptureGroupNameHttpProxySocketPool; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 577 | typedef CaptureGroupNameSocketPool<SOCKSClientSocketPool> |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 578 | CaptureGroupNameSOCKSSocketPool; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 579 | typedef CaptureGroupNameSocketPool<SSLClientSocketPool> |
| 580 | CaptureGroupNameSSLSocketPool; |
| 581 | |
rkaplow | d90695c | 2015-03-25 22:12:41 | [diff] [blame] | 582 | template <typename ParentPool> |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 583 | CaptureGroupNameSocketPool<ParentPool>::CaptureGroupNameSocketPool( |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 584 | HostResolver* host_resolver, |
| 585 | CertVerifier* /* cert_verifier */) |
tbansal | 7b403bcc | 2016-04-13 22:33:21 | [diff] [blame] | 586 | : ParentPool(0, 0, host_resolver, NULL, NULL, NULL) {} |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 587 | |
hashimoto | 0d3e4fb | 2015-01-09 05:02:50 | [diff] [blame] | 588 | template <> |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 589 | CaptureGroupNameHttpProxySocketPool::CaptureGroupNameSocketPool( |
hashimoto | dae13b0 | 2015-01-15 04:28:21 | [diff] [blame] | 590 | HostResolver* /* host_resolver */, |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 591 | CertVerifier* /* cert_verifier */) |
rkaplow | d90695c | 2015-03-25 22:12:41 | [diff] [blame] | 592 | : HttpProxyClientSocketPool(0, 0, NULL, NULL, NULL) { |
hashimoto | 0d3e4fb | 2015-01-09 05:02:50 | [diff] [blame] | 593 | } |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 594 | |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 595 | template <> |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 596 | CaptureGroupNameSSLSocketPool::CaptureGroupNameSocketPool( |
hashimoto | dae13b0 | 2015-01-15 04:28:21 | [diff] [blame] | 597 | HostResolver* /* host_resolver */, |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 598 | CertVerifier* cert_verifier) |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 599 | : SSLClientSocketPool(0, |
| 600 | 0, |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 601 | cert_verifier, |
| 602 | NULL, |
| 603 | NULL, |
[email protected] | 284303b6 | 2013-11-28 15:11:54 | [diff] [blame] | 604 | NULL, |
eranm | 6571b2b | 2014-12-03 15:53:23 | [diff] [blame] | 605 | NULL, |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 606 | std::string(), |
| 607 | NULL, |
| 608 | NULL, |
| 609 | NULL, |
| 610 | NULL, |
| 611 | NULL, |
[email protected] | 8e45855 | 2014-08-05 00:02:15 | [diff] [blame] | 612 | NULL) { |
| 613 | } |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 614 | |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 615 | //----------------------------------------------------------------------------- |
| 616 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 617 | // Helper functions for validating that AuthChallengeInfo's are correctly |
| 618 | // configured for common cases. |
| 619 | bool CheckBasicServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 620 | if (!auth_challenge) |
| 621 | return false; |
| 622 | EXPECT_FALSE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 623 | EXPECT_EQ("http://www.example.org", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 624 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 625 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 626 | return true; |
| 627 | } |
| 628 | |
| 629 | bool CheckBasicProxyAuth(const AuthChallengeInfo* auth_challenge) { |
| 630 | if (!auth_challenge) |
| 631 | return false; |
| 632 | EXPECT_TRUE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 633 | EXPECT_EQ("http://myproxy:70", auth_challenge->challenger.Serialize()); |
| 634 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
| 635 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
| 636 | return true; |
| 637 | } |
| 638 | |
| 639 | bool CheckBasicSecureProxyAuth(const AuthChallengeInfo* auth_challenge) { |
| 640 | if (!auth_challenge) |
| 641 | return false; |
| 642 | EXPECT_TRUE(auth_challenge->is_proxy); |
| 643 | EXPECT_EQ("https://myproxy:70", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 644 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 645 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 646 | return true; |
| 647 | } |
| 648 | |
| 649 | bool CheckDigestServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 650 | if (!auth_challenge) |
| 651 | return false; |
| 652 | EXPECT_FALSE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 653 | EXPECT_EQ("http://www.example.org", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 654 | EXPECT_EQ("digestive", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 655 | EXPECT_EQ(kDigestAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 656 | return true; |
| 657 | } |
| 658 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 659 | #if defined(NTLM_PORTABLE) |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 660 | bool CheckNTLMServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 661 | if (!auth_challenge) |
| 662 | return false; |
| 663 | EXPECT_FALSE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 664 | EXPECT_EQ("http://172.22.68.17", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 665 | EXPECT_EQ(std::string(), auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 666 | EXPECT_EQ(kNtlmAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 667 | return true; |
| 668 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 669 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 670 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 671 | } // namespace |
| 672 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 673 | TEST_F(HttpNetworkTransactionTest, Basic) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 674 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 675 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 676 | } |
| 677 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 678 | TEST_F(HttpNetworkTransactionTest, SimpleGET) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 679 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 680 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 681 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 682 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 683 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 684 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 685 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 686 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 687 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 688 | EXPECT_EQ("hello world", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 689 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 690 | EXPECT_EQ(reads_size, out.total_received_bytes); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 691 | EXPECT_EQ(0u, out.connection_attempts.size()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 692 | |
| 693 | EXPECT_FALSE(out.remote_endpoint_after_start.address().empty()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 694 | } |
| 695 | |
| 696 | // Response with no status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 697 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeaders) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 698 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 699 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 700 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 701 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 702 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 703 | arraysize(data_reads)); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 704 | EXPECT_THAT(out.rv, IsOk()); |
| 705 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 706 | EXPECT_EQ("hello world", out.response_data); |
| 707 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 708 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 709 | } |
| 710 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 711 | // Response with no status line, and a weird port. Should fail by default. |
| 712 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeadersWeirdPort) { |
| 713 | MockRead data_reads[] = { |
| 714 | MockRead("hello world"), MockRead(SYNCHRONOUS, OK), |
| 715 | }; |
| 716 | |
| 717 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), nullptr, 0); |
| 718 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 719 | |
| 720 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 721 | |
| 722 | std::unique_ptr<HttpTransaction> trans( |
| 723 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 724 | |
| 725 | HttpRequestInfo request; |
| 726 | request.method = "GET"; |
| 727 | request.url = GURL("http://www.example.com:2000/"); |
| 728 | TestCompletionCallback callback; |
| 729 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 730 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_INVALID_HTTP_RESPONSE)); |
| 731 | } |
| 732 | |
| 733 | // Response with no status line, and a weird port. Option to allow weird ports |
| 734 | // enabled. |
| 735 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeadersWeirdPortAllowed) { |
| 736 | MockRead data_reads[] = { |
| 737 | MockRead("hello world"), MockRead(SYNCHRONOUS, OK), |
| 738 | }; |
| 739 | |
| 740 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), nullptr, 0); |
| 741 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 742 | session_deps_.http_09_on_non_default_ports_enabled = true; |
| 743 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 744 | |
| 745 | std::unique_ptr<HttpTransaction> trans( |
| 746 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 747 | |
| 748 | HttpRequestInfo request; |
| 749 | request.method = "GET"; |
| 750 | request.url = GURL("http://www.example.com:2000/"); |
| 751 | TestCompletionCallback callback; |
| 752 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 753 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 754 | |
| 755 | const HttpResponseInfo* info = trans->GetResponseInfo(); |
| 756 | ASSERT_TRUE(info->headers); |
| 757 | EXPECT_EQ("HTTP/0.9 200 OK", info->headers->GetStatusLine()); |
| 758 | |
| 759 | // Don't bother to read the body - that's verified elsewhere, important thing |
| 760 | // is that the option to allow HTTP/0.9 on non-default ports is respected. |
| 761 | } |
| 762 | |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 763 | // Allow up to 4 bytes of junk to precede status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 764 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk3Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 765 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 766 | MockRead("xxxHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 767 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 768 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 769 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 770 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 771 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 772 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 773 | EXPECT_EQ("DATA", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 774 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 775 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 776 | } |
| 777 | |
| 778 | // Allow up to 4 bytes of junk to precede status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 779 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk4Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 780 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 781 | MockRead("\n\nQJHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 782 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 783 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 784 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 785 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 786 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 787 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 788 | EXPECT_EQ("DATA", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 789 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 790 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 791 | } |
| 792 | |
| 793 | // Beyond 4 bytes of slop and it should fail to find a status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 794 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk5Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 795 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 796 | MockRead("xxxxxHTTP/1.1 404 Not Found\nServer: blah"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 797 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 798 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 799 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 800 | arraysize(data_reads)); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 801 | EXPECT_THAT(out.rv, IsOk()); |
| 802 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 803 | EXPECT_EQ("xxxxxHTTP/1.1 404 Not Found\nServer: blah", out.response_data); |
| 804 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 805 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 806 | } |
| 807 | |
| 808 | // Same as StatusLineJunk4Bytes, except the read chunks are smaller. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 809 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk4Bytes_Slow) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 810 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 811 | MockRead("\n"), |
| 812 | MockRead("\n"), |
| 813 | MockRead("Q"), |
| 814 | MockRead("J"), |
| 815 | MockRead("HTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 816 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 817 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 818 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 819 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 820 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 821 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 822 | EXPECT_EQ("DATA", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 823 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 824 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 825 | } |
| 826 | |
| 827 | // Close the connection before enough bytes to have a status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 828 | TEST_F(HttpNetworkTransactionTest, StatusLinePartial) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 829 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 830 | MockRead("HTT"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 831 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 832 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 833 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 834 | arraysize(data_reads)); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 835 | EXPECT_THAT(out.rv, IsOk()); |
| 836 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 837 | EXPECT_EQ("HTT", out.response_data); |
| 838 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 839 | EXPECT_EQ(reads_size, out.total_received_bytes); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 840 | } |
| 841 | |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 842 | // Simulate a 204 response, lacking a Content-Length header, sent over a |
| 843 | // persistent connection. The response should still terminate since a 204 |
| 844 | // cannot have a response body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 845 | TEST_F(HttpNetworkTransactionTest, StopsReading204) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 846 | char junk[] = "junk"; |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 847 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 848 | MockRead("HTTP/1.1 204 No Content\r\n\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 849 | MockRead(junk), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 850 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 851 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 852 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 853 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 854 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 855 | EXPECT_EQ("HTTP/1.1 204 No Content", out.status_line); |
| 856 | EXPECT_EQ("", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 857 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 858 | int64_t response_size = reads_size - strlen(junk); |
| 859 | EXPECT_EQ(response_size, out.total_received_bytes); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 860 | } |
| 861 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 862 | // A simple request using chunked encoding with some extra data after. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 863 | TEST_F(HttpNetworkTransactionTest, ChunkedEncoding) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 864 | std::string final_chunk = "0\r\n\r\n"; |
| 865 | std::string extra_data = "HTTP/1.1 200 OK\r\n"; |
| 866 | std::string last_read = final_chunk + extra_data; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 867 | MockRead data_reads[] = { |
| 868 | MockRead("HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n"), |
| 869 | MockRead("5\r\nHello\r\n"), |
| 870 | MockRead("1\r\n"), |
| 871 | MockRead(" \r\n"), |
| 872 | MockRead("5\r\nworld\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 873 | MockRead(last_read.data()), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 874 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 875 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 876 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 877 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 878 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 879 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 880 | EXPECT_EQ("Hello world", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 881 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 882 | int64_t response_size = reads_size - extra_data.size(); |
| 883 | EXPECT_EQ(response_size, out.total_received_bytes); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 884 | } |
| 885 | |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 886 | // Next tests deal with http://crbug.com/56344. |
| 887 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 888 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 889 | MultipleContentLengthHeadersNoTransferEncoding) { |
| 890 | MockRead data_reads[] = { |
| 891 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 892 | MockRead("Content-Length: 10\r\n"), |
| 893 | MockRead("Content-Length: 5\r\n\r\n"), |
| 894 | }; |
| 895 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 896 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 897 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH)); |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 898 | } |
| 899 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 900 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 901 | DuplicateContentLengthHeadersNoTransferEncoding) { |
| 902 | MockRead data_reads[] = { |
| 903 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 904 | MockRead("Content-Length: 5\r\n"), |
| 905 | MockRead("Content-Length: 5\r\n\r\n"), |
| 906 | MockRead("Hello"), |
| 907 | }; |
| 908 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 909 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 910 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 911 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 912 | EXPECT_EQ("Hello", out.response_data); |
| 913 | } |
| 914 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 915 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 916 | ComplexContentLengthHeadersNoTransferEncoding) { |
| 917 | // More than 2 dupes. |
| 918 | { |
| 919 | MockRead data_reads[] = { |
| 920 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 921 | MockRead("Content-Length: 5\r\n"), |
| 922 | MockRead("Content-Length: 5\r\n"), |
| 923 | MockRead("Content-Length: 5\r\n\r\n"), |
| 924 | MockRead("Hello"), |
| 925 | }; |
| 926 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 927 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 928 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 929 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 930 | EXPECT_EQ("Hello", out.response_data); |
| 931 | } |
| 932 | // HTTP/1.0 |
| 933 | { |
| 934 | MockRead data_reads[] = { |
| 935 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 936 | MockRead("Content-Length: 5\r\n"), |
| 937 | MockRead("Content-Length: 5\r\n"), |
| 938 | MockRead("Content-Length: 5\r\n\r\n"), |
| 939 | MockRead("Hello"), |
| 940 | }; |
| 941 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 942 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 943 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 944 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 945 | EXPECT_EQ("Hello", out.response_data); |
| 946 | } |
| 947 | // 2 dupes and one mismatched. |
| 948 | { |
| 949 | MockRead data_reads[] = { |
| 950 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 951 | MockRead("Content-Length: 10\r\n"), |
| 952 | MockRead("Content-Length: 10\r\n"), |
| 953 | MockRead("Content-Length: 5\r\n\r\n"), |
| 954 | }; |
| 955 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 956 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 957 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH)); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 958 | } |
| 959 | } |
| 960 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 961 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 962 | MultipleContentLengthHeadersTransferEncoding) { |
| 963 | MockRead data_reads[] = { |
| 964 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 965 | MockRead("Content-Length: 666\r\n"), |
| 966 | MockRead("Content-Length: 1337\r\n"), |
| 967 | MockRead("Transfer-Encoding: chunked\r\n\r\n"), |
| 968 | MockRead("5\r\nHello\r\n"), |
| 969 | MockRead("1\r\n"), |
| 970 | MockRead(" \r\n"), |
| 971 | MockRead("5\r\nworld\r\n"), |
| 972 | MockRead("0\r\n\r\nHTTP/1.1 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 973 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 974 | }; |
| 975 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 976 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 977 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 978 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 979 | EXPECT_EQ("Hello world", out.response_data); |
| 980 | } |
| 981 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 982 | // Next tests deal with http://crbug.com/98895. |
| 983 | |
| 984 | // Checks that a single Content-Disposition header results in no error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 985 | TEST_F(HttpNetworkTransactionTest, SingleContentDispositionHeader) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 986 | MockRead data_reads[] = { |
| 987 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 988 | MockRead("Content-Disposition: attachment;filename=\"salutations.txt\"r\n"), |
| 989 | MockRead("Content-Length: 5\r\n\r\n"), |
| 990 | MockRead("Hello"), |
| 991 | }; |
| 992 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 993 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 994 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 995 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 996 | EXPECT_EQ("Hello", out.response_data); |
| 997 | } |
| 998 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 999 | // Checks that two identical Content-Disposition headers result in no error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1000 | TEST_F(HttpNetworkTransactionTest, TwoIdenticalContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1001 | MockRead data_reads[] = { |
| 1002 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1003 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1004 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1005 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1006 | MockRead("Hello"), |
| 1007 | }; |
| 1008 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1009 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1010 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1011 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1012 | EXPECT_EQ("Hello", out.response_data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1013 | } |
| 1014 | |
| 1015 | // Checks that two distinct Content-Disposition headers result in an error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1016 | TEST_F(HttpNetworkTransactionTest, TwoDistinctContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1017 | MockRead data_reads[] = { |
| 1018 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1019 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1020 | MockRead("Content-Disposition: attachment;filename=\"hi.txt\"r\n"), |
| 1021 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1022 | MockRead("Hello"), |
| 1023 | }; |
| 1024 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1025 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1026 | EXPECT_THAT(out.rv, |
| 1027 | IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1028 | } |
| 1029 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1030 | // Checks that two identical Location headers result in no error. |
| 1031 | // Also tests Location header behavior. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1032 | TEST_F(HttpNetworkTransactionTest, TwoIdenticalLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1033 | MockRead data_reads[] = { |
| 1034 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 1035 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1036 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1037 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1038 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1039 | }; |
| 1040 | |
| 1041 | HttpRequestInfo request; |
| 1042 | request.method = "GET"; |
| 1043 | request.url = GURL("http://redirect.com/"); |
| 1044 | request.load_flags = 0; |
| 1045 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1046 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1047 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1048 | |
| 1049 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1050 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1051 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1052 | TestCompletionCallback callback; |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1053 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1054 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1055 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1056 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1057 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1058 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1059 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1060 | ASSERT_TRUE(response); |
| 1061 | ASSERT_TRUE(response->headers); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1062 | EXPECT_EQ("HTTP/1.1 302 Redirect", response->headers->GetStatusLine()); |
| 1063 | std::string url; |
| 1064 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 1065 | EXPECT_EQ("http://good.com/", url); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 1066 | EXPECT_TRUE(response->proxy_server.IsEmpty()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1067 | } |
| 1068 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1069 | // Checks that two distinct Location headers result in an error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1070 | TEST_F(HttpNetworkTransactionTest, TwoDistinctLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1071 | MockRead data_reads[] = { |
| 1072 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 1073 | MockRead("Location: http://good.com/\r\n"), |
| 1074 | MockRead("Location: http://evil.com/\r\n"), |
| 1075 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1076 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1077 | }; |
| 1078 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1079 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1080 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_LOCATION)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1081 | } |
| 1082 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1083 | // Do a request using the HEAD method. Verify that we don't try to read the |
| 1084 | // message body (since HEAD has none). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1085 | TEST_F(HttpNetworkTransactionTest, Head) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1086 | HttpRequestInfo request; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1087 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1088 | request.url = GURL("http://www.example.org/"); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1089 | request.load_flags = 0; |
| 1090 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1091 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1092 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1093 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1094 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1095 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 1096 | base::Unretained(&headers_handler))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1097 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1098 | MockWrite data_writes1[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 1099 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 1100 | "Host: www.example.org\r\n" |
| 1101 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1102 | }; |
| 1103 | MockRead data_reads1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 1104 | MockRead("HTTP/1.1 404 Not Found\r\n"), MockRead("Server: Blah\r\n"), |
| 1105 | MockRead("Content-Length: 1234\r\n\r\n"), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1106 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 1107 | // No response body because the test stops reading here. |
| 1108 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1109 | }; |
| 1110 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1111 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 1112 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1113 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1114 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1115 | TestCompletionCallback callback1; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1116 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1117 | int rv = trans.Start(&request, callback1.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1118 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1119 | |
| 1120 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1121 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1122 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1123 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1124 | ASSERT_TRUE(response); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1125 | |
| 1126 | // Check that the headers got parsed. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1127 | EXPECT_TRUE(response->headers); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1128 | EXPECT_EQ(1234, response->headers->GetContentLength()); |
| 1129 | EXPECT_EQ("HTTP/1.1 404 Not Found", response->headers->GetStatusLine()); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 1130 | EXPECT_TRUE(response->proxy_server.IsEmpty()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1131 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 1132 | EXPECT_FALSE(headers_handler.observed_before_headers_sent_with_proxy()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1133 | |
| 1134 | std::string server_header; |
olli.raula | ee489a5 | 2016-01-25 08:37:10 | [diff] [blame] | 1135 | size_t iter = 0; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1136 | bool has_server_header = response->headers->EnumerateHeader( |
| 1137 | &iter, "Server", &server_header); |
| 1138 | EXPECT_TRUE(has_server_header); |
| 1139 | EXPECT_EQ("Blah", server_header); |
| 1140 | |
| 1141 | // Reading should give EOF right away, since there is no message body |
| 1142 | // (despite non-zero content-length). |
| 1143 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1144 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1145 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1146 | EXPECT_EQ("", response_data); |
| 1147 | } |
| 1148 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1149 | TEST_F(HttpNetworkTransactionTest, ReuseConnection) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1150 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1151 | |
| 1152 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1153 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1154 | MockRead("hello"), |
| 1155 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1156 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1157 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1158 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1159 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1160 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1161 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1162 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1163 | "hello", "world" |
| 1164 | }; |
| 1165 | |
| 1166 | for (int i = 0; i < 2; ++i) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1167 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1168 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1169 | request.url = GURL("http://www.example.org/"); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1170 | request.load_flags = 0; |
| 1171 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1172 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1173 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1174 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1175 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1176 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1177 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1178 | |
| 1179 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1180 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1181 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1182 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1183 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1184 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1185 | EXPECT_TRUE(response->headers); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1186 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 1187 | EXPECT_TRUE(response->proxy_server.IsEmpty()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1188 | |
| 1189 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1190 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1191 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1192 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1193 | } |
| 1194 | } |
| 1195 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1196 | TEST_F(HttpNetworkTransactionTest, Ignores100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1197 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 1198 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 1199 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 1200 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1201 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1202 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1203 | request.method = "POST"; |
| 1204 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1205 | request.upload_data_stream = &upload_data_stream; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1206 | request.load_flags = 0; |
| 1207 | |
shivanisha | b9a14395 | 2016-09-19 17:23:41 | [diff] [blame^] | 1208 | // Check the upload progress returned before initialization is correct. |
| 1209 | UploadProgress progress = request.upload_data_stream->GetUploadProgress(); |
| 1210 | EXPECT_EQ(0u, progress.size()); |
| 1211 | EXPECT_EQ(0u, progress.position()); |
| 1212 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1213 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1214 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1215 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1216 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1217 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 1218 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 1219 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1220 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1221 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1222 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1223 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1224 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1225 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1226 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1227 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1228 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1229 | |
| 1230 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1231 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1232 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1233 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1234 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1235 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1236 | EXPECT_TRUE(response->headers); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1237 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1238 | |
| 1239 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1240 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1241 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1242 | EXPECT_EQ("hello world", response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1243 | } |
| 1244 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1245 | // This test is almost the same as Ignores100 above, but the response contains |
| 1246 | // 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] | 1247 | // HTTP/1.1 and the two status headers are read in one read. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1248 | TEST_F(HttpNetworkTransactionTest, Ignores1xx) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1249 | HttpRequestInfo request; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1250 | request.method = "GET"; |
| 1251 | request.url = GURL("http://www.foo.com/"); |
| 1252 | request.load_flags = 0; |
| 1253 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1254 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1255 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1256 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1257 | MockRead data_reads[] = { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1258 | MockRead("HTTP/1.1 102 Unspecified status code\r\n\r\n" |
| 1259 | "HTTP/1.1 200 OK\r\n\r\n"), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1260 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1261 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1262 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1263 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1264 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1265 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1266 | TestCompletionCallback callback; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1267 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1268 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1269 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1270 | |
| 1271 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1272 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1273 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1274 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1275 | ASSERT_TRUE(response); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1276 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1277 | EXPECT_TRUE(response->headers); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1278 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1279 | |
| 1280 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1281 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1282 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1283 | EXPECT_EQ("hello world", response_data); |
| 1284 | } |
| 1285 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1286 | TEST_F(HttpNetworkTransactionTest, Incomplete100ThenEOF) { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1287 | HttpRequestInfo request; |
| 1288 | request.method = "POST"; |
| 1289 | request.url = GURL("http://www.foo.com/"); |
| 1290 | request.load_flags = 0; |
| 1291 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1292 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1293 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1294 | |
| 1295 | MockRead data_reads[] = { |
| 1296 | MockRead(SYNCHRONOUS, "HTTP/1.0 100 Continue\r\n"), |
| 1297 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1298 | }; |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1299 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 1300 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1301 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1302 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1303 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1304 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1305 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1306 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1307 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1308 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1309 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1310 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1311 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1312 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1313 | EXPECT_EQ("", response_data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1314 | } |
| 1315 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1316 | TEST_F(HttpNetworkTransactionTest, EmptyResponse) { |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1317 | HttpRequestInfo request; |
| 1318 | request.method = "POST"; |
| 1319 | request.url = GURL("http://www.foo.com/"); |
| 1320 | request.load_flags = 0; |
| 1321 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1322 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1323 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1324 | |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1325 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1326 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1327 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1328 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1329 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1330 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1331 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1332 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1333 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1334 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1335 | |
| 1336 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1337 | EXPECT_THAT(rv, IsError(ERR_EMPTY_RESPONSE)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1338 | } |
| 1339 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1340 | void HttpNetworkTransactionTest::KeepAliveConnectionResendRequestTest( |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1341 | const MockWrite* write_failure, |
| 1342 | const MockRead* read_failure) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1343 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1344 | request.method = "GET"; |
| 1345 | request.url = GURL("http://www.foo.com/"); |
| 1346 | request.load_flags = 0; |
| 1347 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1348 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1349 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1350 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1351 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1352 | // Written data for successfully sending both requests. |
| 1353 | MockWrite data1_writes[] = { |
| 1354 | MockWrite("GET / HTTP/1.1\r\n" |
| 1355 | "Host: www.foo.com\r\n" |
| 1356 | "Connection: keep-alive\r\n\r\n"), |
| 1357 | MockWrite("GET / HTTP/1.1\r\n" |
| 1358 | "Host: www.foo.com\r\n" |
| 1359 | "Connection: keep-alive\r\n\r\n") |
| 1360 | }; |
| 1361 | |
| 1362 | // Read results for the first request. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1363 | MockRead data1_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1364 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1365 | MockRead("hello"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1366 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1367 | }; |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1368 | |
| 1369 | if (write_failure) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1370 | ASSERT_FALSE(read_failure); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1371 | data1_writes[1] = *write_failure; |
| 1372 | } else { |
| 1373 | ASSERT_TRUE(read_failure); |
| 1374 | data1_reads[2] = *read_failure; |
| 1375 | } |
| 1376 | |
| 1377 | StaticSocketDataProvider data1(data1_reads, arraysize(data1_reads), |
| 1378 | data1_writes, arraysize(data1_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1379 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1380 | |
| 1381 | MockRead data2_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1382 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1383 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1384 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1385 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1386 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1387 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1388 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 1389 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1390 | "hello", "world" |
| 1391 | }; |
| 1392 | |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 1393 | uint32_t first_socket_log_id = NetLog::Source::kInvalidId; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1394 | for (int i = 0; i < 2; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1395 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1396 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1397 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1398 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1399 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1400 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1401 | |
| 1402 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1403 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1404 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1405 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1406 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1407 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1408 | if (i == 0) { |
| 1409 | first_socket_log_id = load_timing_info.socket_log_id; |
| 1410 | } else { |
| 1411 | // The second request should be using a new socket. |
| 1412 | EXPECT_NE(first_socket_log_id, load_timing_info.socket_log_id); |
| 1413 | } |
| 1414 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1415 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1416 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1417 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1418 | EXPECT_TRUE(response->headers); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1419 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1420 | |
| 1421 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1422 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1423 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1424 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1425 | } |
| 1426 | } |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1427 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1428 | void HttpNetworkTransactionTest::PreconnectErrorResendRequestTest( |
| 1429 | const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1430 | const MockRead* read_failure, |
| 1431 | bool use_spdy) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1432 | HttpRequestInfo request; |
| 1433 | request.method = "GET"; |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1434 | request.url = GURL("https://www.foo.com/"); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1435 | request.load_flags = 0; |
| 1436 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1437 | TestNetLog net_log; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1438 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1439 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1440 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1441 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 1442 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 1443 | if (use_spdy) { |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 1444 | ssl1.next_proto = kProtoHTTP2; |
| 1445 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1446 | } |
| 1447 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 1448 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1449 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1450 | // SPDY versions of the request and response. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1451 | SpdySerializedFrame spdy_request(spdy_util_.ConstructSpdyGet( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 1452 | request.url.spec().c_str(), 1, DEFAULT_PRIORITY)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1453 | SpdySerializedFrame spdy_response( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 1454 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1455 | SpdySerializedFrame spdy_data( |
| 1456 | spdy_util_.ConstructSpdyDataFrame(1, "hello", 5, true)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1457 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1458 | // HTTP/1.1 versions of the request and response. |
| 1459 | const char kHttpRequest[] = "GET / HTTP/1.1\r\n" |
| 1460 | "Host: www.foo.com\r\n" |
| 1461 | "Connection: keep-alive\r\n\r\n"; |
| 1462 | const char kHttpResponse[] = "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"; |
| 1463 | const char kHttpData[] = "hello"; |
| 1464 | |
| 1465 | std::vector<MockRead> data1_reads; |
| 1466 | std::vector<MockWrite> data1_writes; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1467 | if (write_failure) { |
| 1468 | ASSERT_FALSE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1469 | data1_writes.push_back(*write_failure); |
| 1470 | data1_reads.push_back(MockRead(ASYNC, OK)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1471 | } else { |
| 1472 | ASSERT_TRUE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1473 | if (use_spdy) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1474 | data1_writes.push_back(CreateMockWrite(spdy_request)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1475 | } else { |
| 1476 | data1_writes.push_back(MockWrite(kHttpRequest)); |
| 1477 | } |
| 1478 | data1_reads.push_back(*read_failure); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1479 | } |
| 1480 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1481 | StaticSocketDataProvider data1(&data1_reads[0], data1_reads.size(), |
| 1482 | &data1_writes[0], data1_writes.size()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1483 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1484 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1485 | std::vector<MockRead> data2_reads; |
| 1486 | std::vector<MockWrite> data2_writes; |
| 1487 | |
| 1488 | if (use_spdy) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1489 | data2_writes.push_back(CreateMockWrite(spdy_request, 0, ASYNC)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1490 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1491 | data2_reads.push_back(CreateMockRead(spdy_response, 1, ASYNC)); |
| 1492 | data2_reads.push_back(CreateMockRead(spdy_data, 2, ASYNC)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1493 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1494 | } else { |
| 1495 | data2_writes.push_back( |
| 1496 | MockWrite(ASYNC, kHttpRequest, strlen(kHttpRequest), 0)); |
| 1497 | |
| 1498 | data2_reads.push_back( |
| 1499 | MockRead(ASYNC, kHttpResponse, strlen(kHttpResponse), 1)); |
| 1500 | data2_reads.push_back(MockRead(ASYNC, kHttpData, strlen(kHttpData), 2)); |
| 1501 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1502 | } |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 1503 | SequencedSocketData data2(&data2_reads[0], data2_reads.size(), |
| 1504 | &data2_writes[0], data2_writes.size()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1505 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1506 | |
| 1507 | // Preconnect a socket. |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 1508 | session->http_stream_factory()->PreconnectStreams(1, request); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1509 | // Wait for the preconnect to complete. |
| 1510 | // TODO(davidben): Some way to wait for an idle socket count might be handy. |
| 1511 | base::RunLoop().RunUntilIdle(); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1512 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1513 | |
| 1514 | // Make the request. |
| 1515 | TestCompletionCallback callback; |
| 1516 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1517 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1518 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1519 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1520 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1521 | |
| 1522 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1523 | EXPECT_THAT(rv, IsOk()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1524 | |
| 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] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1527 | TestLoadTimingNotReused( |
| 1528 | load_timing_info, |
| 1529 | CONNECT_TIMING_HAS_DNS_TIMES|CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1530 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1531 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1532 | ASSERT_TRUE(response); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1533 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1534 | EXPECT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1535 | if (response->was_fetched_via_spdy) { |
| 1536 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 1537 | } else { |
| 1538 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1539 | } |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1540 | |
| 1541 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1542 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1543 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1544 | EXPECT_EQ(kHttpData, response_data); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1545 | } |
| 1546 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1547 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionNotConnectedOnWrite) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1548 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1549 | KeepAliveConnectionResendRequestTest(&write_failure, NULL); |
| 1550 | } |
| 1551 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1552 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionReset) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1553 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1554 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1555 | } |
| 1556 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1557 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionEOF) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1558 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1559 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1560 | } |
| 1561 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1562 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1563 | // if the socket was a reused keep alive socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1564 | TEST_F(HttpNetworkTransactionTest, KeepAlive408) { |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1565 | MockRead read_failure(SYNCHRONOUS, |
| 1566 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1567 | "Connection: Keep-Alive\r\n" |
| 1568 | "Content-Length: 6\r\n\r\n" |
| 1569 | "Pickle"); |
| 1570 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
| 1571 | } |
| 1572 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1573 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorNotConnectedOnWrite) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1574 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1575 | PreconnectErrorResendRequestTest(&write_failure, NULL, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1576 | } |
| 1577 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1578 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorReset) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1579 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1580 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1581 | } |
| 1582 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1583 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorEOF) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1584 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1585 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1586 | } |
| 1587 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1588 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorAsyncEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1589 | MockRead read_failure(ASYNC, OK); // EOF |
| 1590 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1591 | } |
| 1592 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1593 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1594 | // if the socket was a preconnected (UNUSED_IDLE) socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1595 | TEST_F(HttpNetworkTransactionTest, RetryOnIdle408) { |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1596 | MockRead read_failure(SYNCHRONOUS, |
| 1597 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1598 | "Connection: Keep-Alive\r\n" |
| 1599 | "Content-Length: 6\r\n\r\n" |
| 1600 | "Pickle"); |
| 1601 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
| 1602 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1603 | } |
| 1604 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1605 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorNotConnectedOnWrite) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1606 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
| 1607 | PreconnectErrorResendRequestTest(&write_failure, NULL, true); |
| 1608 | } |
| 1609 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1610 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorReset) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1611 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
| 1612 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
| 1613 | } |
| 1614 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1615 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1616 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
| 1617 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
| 1618 | } |
| 1619 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1620 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorAsyncEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1621 | MockRead read_failure(ASYNC, OK); // EOF |
| 1622 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1623 | } |
| 1624 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1625 | TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionReset) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1626 | HttpRequestInfo request; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1627 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1628 | request.url = GURL("http://www.example.org/"); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1629 | request.load_flags = 0; |
| 1630 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1631 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1632 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1633 | |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1634 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1635 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1636 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 1637 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1638 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1639 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1640 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1641 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1642 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1643 | TestCompletionCallback callback; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1644 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1645 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1646 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1647 | |
| 1648 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1649 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 1650 | |
| 1651 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1652 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 1653 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1654 | } |
| 1655 | |
| 1656 | // What do various browsers do when the server closes a non-keepalive |
| 1657 | // connection without sending any response header or body? |
| 1658 | // |
| 1659 | // IE7: error page |
| 1660 | // Safari 3.1.2 (Windows): error page |
| 1661 | // Firefox 3.0.1: blank page |
| 1662 | // Opera 9.52: after five attempts, blank page |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1663 | // Us with WinHTTP: error page (ERR_INVALID_RESPONSE) |
| 1664 | // Us: error page (EMPTY_RESPONSE) |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1665 | TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionEOF) { |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1666 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1667 | MockRead(SYNCHRONOUS, OK), // EOF |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1668 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 1669 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1670 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1671 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1672 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1673 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1674 | EXPECT_THAT(out.rv, IsError(ERR_EMPTY_RESPONSE)); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1675 | } |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1676 | |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1677 | // Next 2 cases (KeepAliveEarlyClose and KeepAliveEarlyClose2) are regression |
| 1678 | // tests. There was a bug causing HttpNetworkTransaction to hang in the |
| 1679 | // destructor in such situations. |
| 1680 | // See http://crbug.com/154712 and http://crbug.com/156609. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1681 | TEST_F(HttpNetworkTransactionTest, KeepAliveEarlyClose) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1682 | HttpRequestInfo request; |
| 1683 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1684 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1685 | request.load_flags = 0; |
| 1686 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1687 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1688 | std::unique_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1689 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1690 | |
| 1691 | MockRead data_reads[] = { |
| 1692 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1693 | MockRead("Connection: keep-alive\r\n"), |
| 1694 | MockRead("Content-Length: 100\r\n\r\n"), |
| 1695 | MockRead("hello"), |
| 1696 | MockRead(SYNCHRONOUS, 0), |
| 1697 | }; |
| 1698 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1699 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1700 | |
| 1701 | TestCompletionCallback callback; |
| 1702 | |
| 1703 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1704 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1705 | |
| 1706 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1707 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1708 | |
| 1709 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1710 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1711 | if (rv == ERR_IO_PENDING) |
| 1712 | rv = callback.WaitForResult(); |
| 1713 | EXPECT_EQ(5, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1714 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1715 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1716 | |
| 1717 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 1718 | base::RunLoop().RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1719 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 1720 | } |
| 1721 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1722 | TEST_F(HttpNetworkTransactionTest, KeepAliveEarlyClose2) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1723 | HttpRequestInfo request; |
| 1724 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1725 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1726 | request.load_flags = 0; |
| 1727 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1728 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1729 | std::unique_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1730 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1731 | |
| 1732 | MockRead data_reads[] = { |
| 1733 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1734 | MockRead("Connection: keep-alive\r\n"), |
| 1735 | MockRead("Content-Length: 100\r\n\r\n"), |
| 1736 | MockRead(SYNCHRONOUS, 0), |
| 1737 | }; |
| 1738 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1739 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1740 | |
| 1741 | TestCompletionCallback callback; |
| 1742 | |
| 1743 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1744 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1745 | |
| 1746 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1747 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1748 | |
| 1749 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1750 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1751 | if (rv == ERR_IO_PENDING) |
| 1752 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1753 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1754 | |
| 1755 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 1756 | base::RunLoop().RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1757 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 1758 | } |
| 1759 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1760 | // Test that we correctly reuse a keep-alive connection after not explicitly |
| 1761 | // reading the body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1762 | TEST_F(HttpNetworkTransactionTest, KeepAliveAfterUnreadBody) { |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1763 | HttpRequestInfo request; |
| 1764 | request.method = "GET"; |
| 1765 | request.url = GURL("http://www.foo.com/"); |
| 1766 | request.load_flags = 0; |
| 1767 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1768 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1769 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1770 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1771 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1772 | const char* request_data = |
| 1773 | "GET / HTTP/1.1\r\n" |
| 1774 | "Host: www.foo.com\r\n" |
| 1775 | "Connection: keep-alive\r\n\r\n"; |
| 1776 | MockWrite data_writes[] = { |
| 1777 | MockWrite(ASYNC, 0, request_data), MockWrite(ASYNC, 2, request_data), |
| 1778 | MockWrite(ASYNC, 4, request_data), MockWrite(ASYNC, 6, request_data), |
| 1779 | MockWrite(ASYNC, 8, request_data), MockWrite(ASYNC, 10, request_data), |
| 1780 | MockWrite(ASYNC, 12, request_data), MockWrite(ASYNC, 14, request_data), |
| 1781 | MockWrite(ASYNC, 17, request_data), MockWrite(ASYNC, 20, request_data), |
| 1782 | }; |
| 1783 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1784 | // Note that because all these reads happen in the same |
| 1785 | // StaticSocketDataProvider, it shows that the same socket is being reused for |
| 1786 | // all transactions. |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1787 | MockRead data_reads[] = { |
| 1788 | MockRead(ASYNC, 1, "HTTP/1.1 204 No Content\r\n\r\n"), |
| 1789 | MockRead(ASYNC, 3, "HTTP/1.1 205 Reset Content\r\n\r\n"), |
| 1790 | MockRead(ASYNC, 5, "HTTP/1.1 304 Not Modified\r\n\r\n"), |
| 1791 | MockRead(ASYNC, 7, |
| 1792 | "HTTP/1.1 302 Found\r\n" |
| 1793 | "Content-Length: 0\r\n\r\n"), |
| 1794 | MockRead(ASYNC, 9, |
| 1795 | "HTTP/1.1 302 Found\r\n" |
| 1796 | "Content-Length: 5\r\n\r\n" |
| 1797 | "hello"), |
| 1798 | MockRead(ASYNC, 11, |
| 1799 | "HTTP/1.1 301 Moved Permanently\r\n" |
| 1800 | "Content-Length: 0\r\n\r\n"), |
| 1801 | MockRead(ASYNC, 13, |
| 1802 | "HTTP/1.1 301 Moved Permanently\r\n" |
| 1803 | "Content-Length: 5\r\n\r\n" |
| 1804 | "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1805 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1806 | // In the next two rounds, IsConnectedAndIdle returns false, due to |
| 1807 | // the set_busy_before_sync_reads(true) call, while the |
| 1808 | // HttpNetworkTransaction is being shut down, but the socket is still |
| 1809 | // reuseable. See http://crbug.com/544255. |
| 1810 | MockRead(ASYNC, 15, |
| 1811 | "HTTP/1.1 200 Hunky-Dory\r\n" |
| 1812 | "Content-Length: 5\r\n\r\n"), |
| 1813 | MockRead(SYNCHRONOUS, 16, "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1814 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1815 | MockRead(ASYNC, 18, |
| 1816 | "HTTP/1.1 200 Hunky-Dory\r\n" |
| 1817 | "Content-Length: 5\r\n\r\n" |
| 1818 | "he"), |
| 1819 | MockRead(SYNCHRONOUS, 19, "llo"), |
| 1820 | |
| 1821 | // The body of the final request is actually read. |
| 1822 | MockRead(ASYNC, 21, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1823 | MockRead(ASYNC, 22, "hello"), |
| 1824 | }; |
| 1825 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 1826 | arraysize(data_writes)); |
| 1827 | data.set_busy_before_sync_reads(true); |
| 1828 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 1829 | |
| 1830 | const int kNumUnreadBodies = arraysize(data_writes) - 1; |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1831 | std::string response_lines[kNumUnreadBodies]; |
| 1832 | |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 1833 | uint32_t first_socket_log_id = NetLog::Source::kInvalidId; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1834 | for (size_t i = 0; i < kNumUnreadBodies; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1835 | TestCompletionCallback callback; |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1836 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1837 | std::unique_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1838 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1839 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1840 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1841 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1842 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1843 | LoadTimingInfo load_timing_info; |
| 1844 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 1845 | if (i == 0) { |
| 1846 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1847 | first_socket_log_id = load_timing_info.socket_log_id; |
| 1848 | } else { |
| 1849 | TestLoadTimingReused(load_timing_info); |
| 1850 | EXPECT_EQ(first_socket_log_id, load_timing_info.socket_log_id); |
| 1851 | } |
| 1852 | |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1853 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1854 | ASSERT_TRUE(response); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1855 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1856 | ASSERT_TRUE(response->headers); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1857 | response_lines[i] = response->headers->GetStatusLine(); |
| 1858 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1859 | // Delete the transaction without reading the response bodies. Then spin |
| 1860 | // the message loop, so the response bodies are drained. |
| 1861 | trans.reset(); |
| 1862 | base::RunLoop().RunUntilIdle(); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1863 | } |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1864 | |
| 1865 | const char* const kStatusLines[] = { |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1866 | "HTTP/1.1 204 No Content", |
| 1867 | "HTTP/1.1 205 Reset Content", |
| 1868 | "HTTP/1.1 304 Not Modified", |
| 1869 | "HTTP/1.1 302 Found", |
| 1870 | "HTTP/1.1 302 Found", |
| 1871 | "HTTP/1.1 301 Moved Permanently", |
| 1872 | "HTTP/1.1 301 Moved Permanently", |
| 1873 | "HTTP/1.1 200 Hunky-Dory", |
| 1874 | "HTTP/1.1 200 Hunky-Dory", |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1875 | }; |
| 1876 | |
mostynb | 91e0da98 | 2015-01-20 19:17:27 | [diff] [blame] | 1877 | static_assert(kNumUnreadBodies == arraysize(kStatusLines), |
| 1878 | "forgot to update kStatusLines"); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1879 | |
| 1880 | for (int i = 0; i < kNumUnreadBodies; ++i) |
| 1881 | EXPECT_EQ(kStatusLines[i], response_lines[i]); |
| 1882 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1883 | TestCompletionCallback callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1884 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 1885 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1886 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1887 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1888 | ASSERT_TRUE(response); |
| 1889 | ASSERT_TRUE(response->headers); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1890 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1891 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1892 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1893 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1894 | EXPECT_EQ("hello", response_data); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1895 | } |
| 1896 | |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 1897 | // Sockets that receive extra data after a response is complete should not be |
| 1898 | // reused. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1899 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData1) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 1900 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1901 | MockWrite data_writes1[] = { |
| 1902 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 1903 | "Host: www.borked.com\r\n" |
| 1904 | "Connection: keep-alive\r\n\r\n"), |
| 1905 | }; |
| 1906 | |
| 1907 | MockRead data_reads1[] = { |
| 1908 | MockRead("HTTP/1.1 200 OK\r\n" |
| 1909 | "Connection: keep-alive\r\n" |
| 1910 | "Content-Length: 22\r\n\r\n" |
| 1911 | "This server is borked."), |
| 1912 | }; |
| 1913 | |
| 1914 | MockWrite data_writes2[] = { |
| 1915 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 1916 | "Host: www.borked.com\r\n" |
| 1917 | "Connection: keep-alive\r\n\r\n"), |
| 1918 | }; |
| 1919 | |
| 1920 | MockRead data_reads2[] = { |
| 1921 | MockRead("HTTP/1.1 200 OK\r\n" |
| 1922 | "Content-Length: 3\r\n\r\n" |
| 1923 | "foo"), |
| 1924 | }; |
| 1925 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 1926 | data_writes1, arraysize(data_writes1)); |
| 1927 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1928 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 1929 | data_writes2, arraysize(data_writes2)); |
| 1930 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1931 | |
| 1932 | TestCompletionCallback callback; |
| 1933 | HttpRequestInfo request1; |
| 1934 | request1.method = "HEAD"; |
| 1935 | request1.url = GURL("http://www.borked.com/"); |
| 1936 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1937 | std::unique_ptr<HttpNetworkTransaction> trans1( |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 1938 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 1939 | int rv = trans1->Start(&request1, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1940 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 1941 | |
| 1942 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 1943 | ASSERT_TRUE(response1); |
| 1944 | ASSERT_TRUE(response1->headers); |
| 1945 | EXPECT_EQ(200, response1->headers->response_code()); |
| 1946 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 1947 | |
| 1948 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1949 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 1950 | EXPECT_EQ("", response_data1); |
| 1951 | // Deleting the transaction attempts to release the socket back into the |
| 1952 | // socket pool. |
| 1953 | trans1.reset(); |
| 1954 | |
| 1955 | HttpRequestInfo request2; |
| 1956 | request2.method = "GET"; |
| 1957 | request2.url = GURL("http://www.borked.com/foo"); |
| 1958 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1959 | std::unique_ptr<HttpNetworkTransaction> trans2( |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 1960 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 1961 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1962 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 1963 | |
| 1964 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 1965 | ASSERT_TRUE(response2); |
| 1966 | ASSERT_TRUE(response2->headers); |
| 1967 | EXPECT_EQ(200, response2->headers->response_code()); |
| 1968 | |
| 1969 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1970 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 1971 | EXPECT_EQ("foo", response_data2); |
| 1972 | } |
| 1973 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1974 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData2) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 1975 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1976 | MockWrite data_writes1[] = { |
| 1977 | MockWrite("GET / HTTP/1.1\r\n" |
| 1978 | "Host: www.borked.com\r\n" |
| 1979 | "Connection: keep-alive\r\n\r\n"), |
| 1980 | }; |
| 1981 | |
| 1982 | MockRead data_reads1[] = { |
| 1983 | MockRead("HTTP/1.1 200 OK\r\n" |
| 1984 | "Connection: keep-alive\r\n" |
| 1985 | "Content-Length: 22\r\n\r\n" |
| 1986 | "This server is borked." |
| 1987 | "Bonus data!"), |
| 1988 | }; |
| 1989 | |
| 1990 | MockWrite data_writes2[] = { |
| 1991 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 1992 | "Host: www.borked.com\r\n" |
| 1993 | "Connection: keep-alive\r\n\r\n"), |
| 1994 | }; |
| 1995 | |
| 1996 | MockRead data_reads2[] = { |
| 1997 | MockRead("HTTP/1.1 200 OK\r\n" |
| 1998 | "Content-Length: 3\r\n\r\n" |
| 1999 | "foo"), |
| 2000 | }; |
| 2001 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2002 | data_writes1, arraysize(data_writes1)); |
| 2003 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2004 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2005 | data_writes2, arraysize(data_writes2)); |
| 2006 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2007 | |
| 2008 | TestCompletionCallback callback; |
| 2009 | HttpRequestInfo request1; |
| 2010 | request1.method = "GET"; |
| 2011 | request1.url = GURL("http://www.borked.com/"); |
| 2012 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2013 | std::unique_ptr<HttpNetworkTransaction> trans1( |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2014 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 2015 | int rv = trans1->Start(&request1, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2016 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2017 | |
| 2018 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2019 | ASSERT_TRUE(response1); |
| 2020 | ASSERT_TRUE(response1->headers); |
| 2021 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2022 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2023 | |
| 2024 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2025 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2026 | EXPECT_EQ("This server is borked.", response_data1); |
| 2027 | // Deleting the transaction attempts to release the socket back into the |
| 2028 | // socket pool. |
| 2029 | trans1.reset(); |
| 2030 | |
| 2031 | HttpRequestInfo request2; |
| 2032 | request2.method = "GET"; |
| 2033 | request2.url = GURL("http://www.borked.com/foo"); |
| 2034 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2035 | std::unique_ptr<HttpNetworkTransaction> trans2( |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2036 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 2037 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2038 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2039 | |
| 2040 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2041 | ASSERT_TRUE(response2); |
| 2042 | ASSERT_TRUE(response2->headers); |
| 2043 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2044 | |
| 2045 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2046 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2047 | EXPECT_EQ("foo", response_data2); |
| 2048 | } |
| 2049 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2050 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData3) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2051 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2052 | MockWrite data_writes1[] = { |
| 2053 | MockWrite("GET / HTTP/1.1\r\n" |
| 2054 | "Host: www.borked.com\r\n" |
| 2055 | "Connection: keep-alive\r\n\r\n"), |
| 2056 | }; |
| 2057 | |
| 2058 | MockRead data_reads1[] = { |
| 2059 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2060 | "Connection: keep-alive\r\n" |
| 2061 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 2062 | MockRead("16\r\nThis server is borked.\r\n"), |
| 2063 | MockRead("0\r\n\r\nBonus data!"), |
| 2064 | }; |
| 2065 | |
| 2066 | MockWrite data_writes2[] = { |
| 2067 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2068 | "Host: www.borked.com\r\n" |
| 2069 | "Connection: keep-alive\r\n\r\n"), |
| 2070 | }; |
| 2071 | |
| 2072 | MockRead data_reads2[] = { |
| 2073 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2074 | "Content-Length: 3\r\n\r\n" |
| 2075 | "foo"), |
| 2076 | }; |
| 2077 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2078 | data_writes1, arraysize(data_writes1)); |
| 2079 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2080 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2081 | data_writes2, arraysize(data_writes2)); |
| 2082 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2083 | |
| 2084 | TestCompletionCallback callback; |
| 2085 | HttpRequestInfo request1; |
| 2086 | request1.method = "GET"; |
| 2087 | request1.url = GURL("http://www.borked.com/"); |
| 2088 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2089 | std::unique_ptr<HttpNetworkTransaction> trans1( |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2090 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 2091 | int rv = trans1->Start(&request1, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2092 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2093 | |
| 2094 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2095 | ASSERT_TRUE(response1); |
| 2096 | ASSERT_TRUE(response1->headers); |
| 2097 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2098 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2099 | |
| 2100 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2101 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2102 | EXPECT_EQ("This server is borked.", response_data1); |
| 2103 | // Deleting the transaction attempts to release the socket back into the |
| 2104 | // socket pool. |
| 2105 | trans1.reset(); |
| 2106 | |
| 2107 | HttpRequestInfo request2; |
| 2108 | request2.method = "GET"; |
| 2109 | request2.url = GURL("http://www.borked.com/foo"); |
| 2110 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2111 | std::unique_ptr<HttpNetworkTransaction> trans2( |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2112 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 2113 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2114 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2115 | |
| 2116 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2117 | ASSERT_TRUE(response2); |
| 2118 | ASSERT_TRUE(response2->headers); |
| 2119 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2120 | |
| 2121 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2122 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2123 | EXPECT_EQ("foo", response_data2); |
| 2124 | } |
| 2125 | |
| 2126 | // This is a little different from the others - it tests the case that the |
| 2127 | // HttpStreamParser doesn't know if there's extra data on a socket or not when |
| 2128 | // the HttpNetworkTransaction is torn down, because the response body hasn't |
| 2129 | // been read from yet, but the request goes through the HttpResponseBodyDrainer. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2130 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData4) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2131 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2132 | MockWrite data_writes1[] = { |
| 2133 | MockWrite("GET / HTTP/1.1\r\n" |
| 2134 | "Host: www.borked.com\r\n" |
| 2135 | "Connection: keep-alive\r\n\r\n"), |
| 2136 | }; |
| 2137 | |
| 2138 | MockRead data_reads1[] = { |
| 2139 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2140 | "Connection: keep-alive\r\n" |
| 2141 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 2142 | MockRead("16\r\nThis server is borked.\r\n"), |
| 2143 | MockRead("0\r\n\r\nBonus data!"), |
| 2144 | }; |
| 2145 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2146 | data_writes1, arraysize(data_writes1)); |
| 2147 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2148 | |
| 2149 | TestCompletionCallback callback; |
| 2150 | HttpRequestInfo request1; |
| 2151 | request1.method = "GET"; |
| 2152 | request1.url = GURL("http://www.borked.com/"); |
| 2153 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2154 | std::unique_ptr<HttpNetworkTransaction> trans1( |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2155 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 2156 | int rv = trans1->Start(&request1, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2157 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2158 | |
| 2159 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2160 | ASSERT_TRUE(response1); |
| 2161 | ASSERT_TRUE(response1->headers); |
| 2162 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2163 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2164 | |
| 2165 | // Deleting the transaction creates an HttpResponseBodyDrainer to read the |
| 2166 | // response body. |
| 2167 | trans1.reset(); |
| 2168 | |
| 2169 | // Let the HttpResponseBodyDrainer drain the socket. It should determine the |
| 2170 | // socket can't be reused, rather than returning it to the socket pool. |
| 2171 | base::RunLoop().RunUntilIdle(); |
| 2172 | |
| 2173 | // There should be no idle sockets in the pool. |
| 2174 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 2175 | } |
| 2176 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2177 | // Test the request-challenge-retry sequence for basic auth. |
| 2178 | // (basic auth is the easiest to mock, because it has no randomness). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2179 | TEST_F(HttpNetworkTransactionTest, BasicAuth) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2180 | HttpRequestInfo request; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2181 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2182 | request.url = GURL("http://www.example.org/"); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2183 | request.load_flags = 0; |
| 2184 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2185 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2186 | session_deps_.net_log = &log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2187 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2188 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2189 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2190 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2191 | MockWrite( |
| 2192 | "GET / HTTP/1.1\r\n" |
| 2193 | "Host: www.example.org\r\n" |
| 2194 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2195 | }; |
| 2196 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2197 | MockRead data_reads1[] = { |
| 2198 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2199 | // Give a couple authenticate options (only the middle one is actually |
| 2200 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 2201 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2202 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2203 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2204 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2205 | // Large content-length -- won't matter, as connection will be reset. |
| 2206 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2207 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2208 | }; |
| 2209 | |
| 2210 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2211 | // be issuing -- the final header line contains the credentials. |
| 2212 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2213 | MockWrite( |
| 2214 | "GET / HTTP/1.1\r\n" |
| 2215 | "Host: www.example.org\r\n" |
| 2216 | "Connection: keep-alive\r\n" |
| 2217 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2218 | }; |
| 2219 | |
| 2220 | // Lastly, the server responds with the actual content. |
| 2221 | MockRead data_reads2[] = { |
| 2222 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2223 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2224 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2225 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2226 | }; |
| 2227 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2228 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2229 | data_writes1, arraysize(data_writes1)); |
| 2230 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2231 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2232 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2233 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2234 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2235 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2236 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2237 | int rv = trans.Start(&request, callback1.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2238 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2239 | |
| 2240 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2241 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2242 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2243 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2244 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2245 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2246 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2247 | int64_t writes_size1 = CountWriteBytes(data_writes1, arraysize(data_writes1)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2248 | EXPECT_EQ(writes_size1, trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2249 | int64_t reads_size1 = CountReadBytes(data_reads1, arraysize(data_reads1)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2250 | EXPECT_EQ(reads_size1, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2251 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2252 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2253 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2254 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2255 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2256 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2257 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2258 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2259 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2260 | |
| 2261 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2262 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2263 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2264 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2265 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2266 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2267 | // The load timing after restart should have a new socket ID, and times after |
| 2268 | // those of the first load timing. |
| 2269 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2270 | load_timing_info2.connect_timing.connect_start); |
| 2271 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2272 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2273 | int64_t writes_size2 = CountWriteBytes(data_writes2, arraysize(data_writes2)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2274 | EXPECT_EQ(writes_size1 + writes_size2, trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2275 | int64_t reads_size2 = CountReadBytes(data_reads2, arraysize(data_reads2)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2276 | EXPECT_EQ(reads_size1 + reads_size2, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2277 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2278 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2279 | ASSERT_TRUE(response); |
| 2280 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2281 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2282 | } |
| 2283 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2284 | // Test the request-challenge-retry sequence for basic auth. |
| 2285 | // (basic auth is the easiest to mock, because it has no randomness). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2286 | TEST_F(HttpNetworkTransactionTest, BasicAuthWithAddressChange) { |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2287 | HttpRequestInfo request; |
| 2288 | request.method = "GET"; |
| 2289 | request.url = GURL("http://www.example.org/"); |
| 2290 | request.load_flags = 0; |
| 2291 | |
| 2292 | TestNetLog log; |
| 2293 | MockHostResolver* resolver = new MockHostResolver(); |
| 2294 | session_deps_.net_log = &log; |
| 2295 | session_deps_.host_resolver.reset(resolver); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2296 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2297 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2298 | |
| 2299 | resolver->rules()->ClearRules(); |
| 2300 | resolver->rules()->AddRule("www.example.org", "127.0.0.1"); |
| 2301 | |
| 2302 | MockWrite data_writes1[] = { |
| 2303 | MockWrite("GET / HTTP/1.1\r\n" |
| 2304 | "Host: www.example.org\r\n" |
| 2305 | "Connection: keep-alive\r\n\r\n"), |
| 2306 | }; |
| 2307 | |
| 2308 | MockRead data_reads1[] = { |
| 2309 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2310 | // Give a couple authenticate options (only the middle one is actually |
| 2311 | // supported). |
| 2312 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 2313 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2314 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2315 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2316 | // Large content-length -- won't matter, as connection will be reset. |
| 2317 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 2318 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 2319 | }; |
| 2320 | |
| 2321 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2322 | // be issuing -- the final header line contains the credentials. |
| 2323 | MockWrite data_writes2[] = { |
| 2324 | MockWrite("GET / HTTP/1.1\r\n" |
| 2325 | "Host: www.example.org\r\n" |
| 2326 | "Connection: keep-alive\r\n" |
| 2327 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2328 | }; |
| 2329 | |
| 2330 | // Lastly, the server responds with the actual content. |
| 2331 | MockRead data_reads2[] = { |
| 2332 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2333 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2334 | MockRead("Content-Length: 100\r\n\r\n"), MockRead(SYNCHRONOUS, OK), |
| 2335 | }; |
| 2336 | |
| 2337 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2338 | data_writes1, arraysize(data_writes1)); |
| 2339 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2340 | data_writes2, arraysize(data_writes2)); |
| 2341 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2342 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2343 | |
| 2344 | TestCompletionCallback callback1; |
| 2345 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2346 | EXPECT_EQ(OK, callback1.GetResult(trans.Start(&request, callback1.callback(), |
| 2347 | BoundNetLog()))); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2348 | |
| 2349 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2350 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2351 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2352 | |
| 2353 | int64_t writes_size1 = CountWriteBytes(data_writes1, arraysize(data_writes1)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2354 | EXPECT_EQ(writes_size1, trans.GetTotalSentBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2355 | int64_t reads_size1 = CountReadBytes(data_reads1, arraysize(data_reads1)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2356 | EXPECT_EQ(reads_size1, trans.GetTotalReceivedBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2357 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2358 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2359 | ASSERT_TRUE(response); |
| 2360 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 2361 | |
| 2362 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2363 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2364 | ASSERT_FALSE(endpoint.address().empty()); |
| 2365 | EXPECT_EQ("127.0.0.1:80", endpoint.ToString()); |
| 2366 | |
| 2367 | resolver->rules()->ClearRules(); |
| 2368 | resolver->rules()->AddRule("www.example.org", "127.0.0.2"); |
| 2369 | |
| 2370 | TestCompletionCallback callback2; |
| 2371 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2372 | EXPECT_EQ(OK, callback2.GetResult(trans.RestartWithAuth( |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2373 | AuthCredentials(kFoo, kBar), callback2.callback()))); |
| 2374 | |
| 2375 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2376 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2377 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2378 | // The load timing after restart should have a new socket ID, and times after |
| 2379 | // those of the first load timing. |
| 2380 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2381 | load_timing_info2.connect_timing.connect_start); |
| 2382 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2383 | |
| 2384 | int64_t writes_size2 = CountWriteBytes(data_writes2, arraysize(data_writes2)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2385 | EXPECT_EQ(writes_size1 + writes_size2, trans.GetTotalSentBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2386 | int64_t reads_size2 = CountReadBytes(data_reads2, arraysize(data_reads2)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2387 | EXPECT_EQ(reads_size1 + reads_size2, trans.GetTotalReceivedBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2388 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2389 | response = trans.GetResponseInfo(); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2390 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2391 | EXPECT_FALSE(response->auth_challenge); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2392 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 2393 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2394 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2395 | ASSERT_FALSE(endpoint.address().empty()); |
| 2396 | EXPECT_EQ("127.0.0.2:80", endpoint.ToString()); |
| 2397 | } |
| 2398 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2399 | TEST_F(HttpNetworkTransactionTest, DoNotSendAuth) { |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2400 | HttpRequestInfo request; |
| 2401 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2402 | request.url = GURL("http://www.example.org/"); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2403 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2404 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2405 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2406 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2407 | |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2408 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2409 | MockWrite( |
| 2410 | "GET / HTTP/1.1\r\n" |
| 2411 | "Host: www.example.org\r\n" |
| 2412 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2413 | }; |
| 2414 | |
| 2415 | MockRead data_reads[] = { |
| 2416 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2417 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2418 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2419 | // Large content-length -- won't matter, as connection will be reset. |
| 2420 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2421 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2422 | }; |
| 2423 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2424 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 2425 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2426 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2427 | TestCompletionCallback callback; |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2428 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2429 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2430 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2431 | |
| 2432 | rv = callback.WaitForResult(); |
| 2433 | EXPECT_EQ(0, rv); |
| 2434 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2435 | int64_t writes_size = CountWriteBytes(data_writes, arraysize(data_writes)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2436 | EXPECT_EQ(writes_size, trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2437 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2438 | EXPECT_EQ(reads_size, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2439 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2440 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2441 | ASSERT_TRUE(response); |
| 2442 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2443 | } |
| 2444 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2445 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2446 | // connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2447 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAlive) { |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2448 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 2449 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 2450 | // reused. See http://crbug.com/544255. |
| 2451 | for (int i = 0; i < 2; ++i) { |
| 2452 | HttpRequestInfo request; |
| 2453 | request.method = "GET"; |
| 2454 | request.url = GURL("http://www.example.org/"); |
| 2455 | request.load_flags = 0; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2456 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2457 | TestNetLog log; |
| 2458 | session_deps_.net_log = &log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2459 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2460 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2461 | MockWrite data_writes[] = { |
| 2462 | MockWrite(ASYNC, 0, |
| 2463 | "GET / HTTP/1.1\r\n" |
| 2464 | "Host: www.example.org\r\n" |
| 2465 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2466 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2467 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2468 | // be issuing -- the final header line contains the credentials. |
| 2469 | MockWrite(ASYNC, 6, |
| 2470 | "GET / HTTP/1.1\r\n" |
| 2471 | "Host: www.example.org\r\n" |
| 2472 | "Connection: keep-alive\r\n" |
| 2473 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2474 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2475 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2476 | MockRead data_reads[] = { |
| 2477 | MockRead(ASYNC, 1, "HTTP/1.1 401 Unauthorized\r\n"), |
| 2478 | MockRead(ASYNC, 2, "WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2479 | MockRead(ASYNC, 3, "Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2480 | MockRead(ASYNC, 4, "Content-Length: 14\r\n\r\n"), |
| 2481 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 5, "Unauthorized\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2482 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2483 | // Lastly, the server responds with the actual content. |
| 2484 | MockRead(ASYNC, 7, "HTTP/1.1 200 OK\r\n"), |
| 2485 | MockRead(ASYNC, 8, "Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2486 | MockRead(ASYNC, 9, "Content-Length: 5\r\n\r\n"), |
| 2487 | MockRead(ASYNC, 10, "Hello"), |
| 2488 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2489 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2490 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 2491 | arraysize(data_writes)); |
| 2492 | data.set_busy_before_sync_reads(true); |
| 2493 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2494 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2495 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2496 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2497 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 2498 | int rv = trans.Start(&request, callback1.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2499 | ASSERT_THAT(callback1.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2500 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2501 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2502 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2503 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2504 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2505 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2506 | ASSERT_TRUE(response); |
| 2507 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2508 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2509 | TestCompletionCallback callback2; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2510 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2511 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 2512 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2513 | ASSERT_THAT(callback2.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2514 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2515 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2516 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2517 | TestLoadTimingReused(load_timing_info2); |
| 2518 | // The load timing after restart should have the same socket ID, and times |
| 2519 | // those of the first load timing. |
| 2520 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2521 | load_timing_info2.send_start); |
| 2522 | 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] | 2523 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2524 | response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2525 | ASSERT_TRUE(response); |
| 2526 | EXPECT_FALSE(response->auth_challenge); |
| 2527 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2528 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2529 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2530 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2531 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2532 | int64_t writes_size = CountWriteBytes(data_writes, arraysize(data_writes)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2533 | EXPECT_EQ(writes_size, trans.GetTotalSentBytes()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2534 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2535 | EXPECT_EQ(reads_size, trans.GetTotalReceivedBytes()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2536 | } |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2537 | } |
| 2538 | |
| 2539 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2540 | // connection and with no response body to drain. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2541 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2542 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2543 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2544 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2545 | request.load_flags = 0; |
| 2546 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2547 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2548 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2549 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2550 | MockWrite("GET / HTTP/1.1\r\n" |
| 2551 | "Host: www.example.org\r\n" |
| 2552 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2553 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2554 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2555 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2556 | MockWrite("GET / HTTP/1.1\r\n" |
| 2557 | "Host: www.example.org\r\n" |
| 2558 | "Connection: keep-alive\r\n" |
| 2559 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2560 | }; |
| 2561 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2562 | MockRead data_reads1[] = { |
| 2563 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2564 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2565 | MockRead("Content-Length: 0\r\n\r\n"), // No response body. |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2566 | |
| 2567 | // Lastly, the server responds with the actual content. |
| 2568 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2569 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2570 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2571 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2572 | }; |
| 2573 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2574 | // An incorrect reconnect would cause this to be read. |
| 2575 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2576 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2577 | }; |
| 2578 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2579 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2580 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2581 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2582 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2583 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2584 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2585 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2586 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2587 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2588 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 2589 | int rv = trans.Start(&request, callback1.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2590 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2591 | |
| 2592 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2593 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2594 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2595 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2596 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2597 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2598 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2599 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2600 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2601 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2602 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2603 | |
| 2604 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2605 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2606 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2607 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2608 | ASSERT_TRUE(response); |
| 2609 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2610 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2611 | } |
| 2612 | |
| 2613 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2614 | // connection and with a large response body to drain. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2615 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveLargeBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2616 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2617 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2618 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2619 | request.load_flags = 0; |
| 2620 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2621 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2622 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2623 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2624 | MockWrite("GET / HTTP/1.1\r\n" |
| 2625 | "Host: www.example.org\r\n" |
| 2626 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2627 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2628 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2629 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2630 | MockWrite("GET / HTTP/1.1\r\n" |
| 2631 | "Host: www.example.org\r\n" |
| 2632 | "Connection: keep-alive\r\n" |
| 2633 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2634 | }; |
| 2635 | |
| 2636 | // Respond with 5 kb of response body. |
| 2637 | std::string large_body_string("Unauthorized"); |
| 2638 | large_body_string.append(5 * 1024, ' '); |
| 2639 | large_body_string.append("\r\n"); |
| 2640 | |
| 2641 | MockRead data_reads1[] = { |
| 2642 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2643 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2644 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2645 | // 5134 = 12 + 5 * 1024 + 2 |
| 2646 | MockRead("Content-Length: 5134\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2647 | MockRead(ASYNC, large_body_string.data(), large_body_string.size()), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2648 | |
| 2649 | // Lastly, the server responds with the actual content. |
| 2650 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2651 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2652 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2653 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2654 | }; |
| 2655 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2656 | // An incorrect reconnect would cause this to be read. |
| 2657 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2658 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2659 | }; |
| 2660 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2661 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2662 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2663 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2664 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2665 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2666 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2667 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2668 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2669 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2670 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 2671 | int rv = trans.Start(&request, callback1.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2672 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2673 | |
| 2674 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2675 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2676 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2677 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2678 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2679 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2680 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2681 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2682 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2683 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2684 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2685 | |
| 2686 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2687 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2688 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2689 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2690 | ASSERT_TRUE(response); |
| 2691 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2692 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2693 | } |
| 2694 | |
| 2695 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2696 | // connection, but the server gets impatient and closes the connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2697 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveImpatientServer) { |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2698 | HttpRequestInfo request; |
| 2699 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2700 | request.url = GURL("http://www.example.org/"); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2701 | request.load_flags = 0; |
| 2702 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2703 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2704 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2705 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2706 | MockWrite( |
| 2707 | "GET / HTTP/1.1\r\n" |
| 2708 | "Host: www.example.org\r\n" |
| 2709 | "Connection: keep-alive\r\n\r\n"), |
| 2710 | // This simulates the seemingly successful write to a closed connection |
| 2711 | // if the bug is not fixed. |
| 2712 | MockWrite( |
| 2713 | "GET / HTTP/1.1\r\n" |
| 2714 | "Host: www.example.org\r\n" |
| 2715 | "Connection: keep-alive\r\n" |
| 2716 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2717 | }; |
| 2718 | |
| 2719 | MockRead data_reads1[] = { |
| 2720 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2721 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2722 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2723 | MockRead("Content-Length: 14\r\n\r\n"), |
| 2724 | // Tell MockTCPClientSocket to simulate the server closing the connection. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2725 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2726 | MockRead("Unauthorized\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2727 | MockRead(SYNCHRONOUS, OK), // The server closes the connection. |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2728 | }; |
| 2729 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2730 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2731 | // be issuing -- the final header line contains the credentials. |
| 2732 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2733 | MockWrite( |
| 2734 | "GET / HTTP/1.1\r\n" |
| 2735 | "Host: www.example.org\r\n" |
| 2736 | "Connection: keep-alive\r\n" |
| 2737 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2738 | }; |
| 2739 | |
| 2740 | // Lastly, the server responds with the actual content. |
| 2741 | MockRead data_reads2[] = { |
| 2742 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2743 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2744 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2745 | MockRead("hello"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2746 | }; |
| 2747 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2748 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2749 | data_writes1, arraysize(data_writes1)); |
| 2750 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2751 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2752 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2753 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2754 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2755 | TestCompletionCallback callback1; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2756 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2757 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 2758 | int rv = trans.Start(&request, callback1.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2759 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2760 | |
| 2761 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2762 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2763 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2764 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2765 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2766 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2767 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2768 | TestCompletionCallback callback2; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2769 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2770 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2771 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2772 | |
| 2773 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2774 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2775 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2776 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2777 | ASSERT_TRUE(response); |
| 2778 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2779 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2780 | } |
| 2781 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2782 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 2783 | // that requires a restart when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2784 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp10) { |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2785 | HttpRequestInfo request; |
| 2786 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2787 | request.url = GURL("https://www.example.org/"); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2788 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2789 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2790 | |
| 2791 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 2792 | session_deps_.proxy_service = |
| 2793 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2794 | BoundTestNetLog log; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2795 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2796 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2797 | |
| 2798 | // Since we have proxy, should try to establish tunnel. |
| 2799 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2800 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 2801 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2802 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2803 | }; |
| 2804 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2805 | // The proxy responds to the connect with a 407, using a non-persistent |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2806 | // connection. |
| 2807 | MockRead data_reads1[] = { |
| 2808 | // No credentials. |
| 2809 | MockRead("HTTP/1.0 407 Proxy Authentication Required\r\n"), |
| 2810 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n\r\n"), |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2811 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2812 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2813 | // Since the first connection couldn't be reused, need to establish another |
| 2814 | // once given credentials. |
| 2815 | MockWrite data_writes2[] = { |
| 2816 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2817 | // be issuing -- the final header line contains the credentials. |
| 2818 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 2819 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2820 | "Proxy-Connection: keep-alive\r\n" |
| 2821 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2822 | |
| 2823 | MockWrite("GET / HTTP/1.1\r\n" |
| 2824 | "Host: www.example.org\r\n" |
| 2825 | "Connection: keep-alive\r\n\r\n"), |
| 2826 | }; |
| 2827 | |
| 2828 | MockRead data_reads2[] = { |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2829 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 2830 | |
| 2831 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2832 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2833 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2834 | MockRead(SYNCHRONOUS, "hello"), |
| 2835 | }; |
| 2836 | |
| 2837 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2838 | data_writes1, arraysize(data_writes1)); |
| 2839 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2840 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2841 | data_writes2, arraysize(data_writes2)); |
| 2842 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2843 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 2844 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 2845 | |
| 2846 | TestCompletionCallback callback1; |
| 2847 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2848 | std::unique_ptr<HttpNetworkTransaction> trans( |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2849 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 2850 | |
| 2851 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2852 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2853 | |
| 2854 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2855 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 2856 | TestNetLogEntry::List entries; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2857 | log.GetEntries(&entries); |
| 2858 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 2859 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 2860 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2861 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 2862 | entries, pos, |
| 2863 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 2864 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2865 | |
| 2866 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2867 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2868 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2869 | ASSERT_TRUE(response->headers); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2870 | EXPECT_EQ(407, response->headers->response_code()); |
| 2871 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 2872 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 2873 | |
| 2874 | LoadTimingInfo load_timing_info; |
| 2875 | // CONNECT requests and responses are handled at the connect job level, so |
| 2876 | // the transaction does not yet have a connection. |
| 2877 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2878 | |
| 2879 | TestCompletionCallback callback2; |
| 2880 | |
| 2881 | rv = |
| 2882 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2883 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2884 | |
| 2885 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2886 | EXPECT_THAT(rv, IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2887 | |
| 2888 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2889 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2890 | |
| 2891 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2892 | EXPECT_EQ(200, response->headers->response_code()); |
| 2893 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 2894 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 2895 | |
| 2896 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2897 | EXPECT_FALSE(response->auth_challenge); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2898 | |
| 2899 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2900 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 2901 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 2902 | |
| 2903 | trans.reset(); |
| 2904 | session->CloseAllConnections(); |
| 2905 | } |
| 2906 | |
| 2907 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 2908 | // that requires a restart when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2909 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp11) { |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2910 | HttpRequestInfo request; |
| 2911 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2912 | request.url = GURL("https://www.example.org/"); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2913 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2914 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2915 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2916 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 2917 | session_deps_.proxy_service = |
| 2918 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2919 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2920 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2921 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2922 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2923 | // Since we have proxy, should try to establish tunnel. |
| 2924 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2925 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 2926 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2927 | "Proxy-Connection: keep-alive\r\n\r\n"), |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 2928 | }; |
| 2929 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2930 | // The proxy responds to the connect with a 407, using a non-persistent |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 2931 | // connection. |
| 2932 | MockRead data_reads1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2933 | // No credentials. |
| 2934 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 2935 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2936 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 2937 | }; |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 2938 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2939 | MockWrite data_writes2[] = { |
| 2940 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2941 | // be issuing -- the final header line contains the credentials. |
| 2942 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 2943 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2944 | "Proxy-Connection: keep-alive\r\n" |
| 2945 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 2946 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2947 | MockWrite("GET / HTTP/1.1\r\n" |
| 2948 | "Host: www.example.org\r\n" |
| 2949 | "Connection: keep-alive\r\n\r\n"), |
| 2950 | }; |
| 2951 | |
| 2952 | MockRead data_reads2[] = { |
| 2953 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 2954 | |
| 2955 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2956 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2957 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2958 | MockRead(SYNCHRONOUS, "hello"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2959 | }; |
| 2960 | |
| 2961 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2962 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2963 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2964 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2965 | data_writes2, arraysize(data_writes2)); |
| 2966 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2967 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2968 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2969 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2970 | TestCompletionCallback callback1; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2971 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2972 | std::unique_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2973 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2974 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2975 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2976 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2977 | |
| 2978 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2979 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 2980 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2981 | log.GetEntries(&entries); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2982 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 2983 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 2984 | NetLogEventPhase::NONE); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2985 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2986 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 2987 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 2988 | NetLogEventPhase::NONE); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2989 | |
| 2990 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2991 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2992 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2993 | ASSERT_TRUE(response->headers); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2994 | EXPECT_EQ(407, response->headers->response_code()); |
| 2995 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2996 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2997 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2998 | LoadTimingInfo load_timing_info; |
| 2999 | // CONNECT requests and responses are handled at the connect job level, so |
| 3000 | // the transaction does not yet have a connection. |
| 3001 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3002 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3003 | TestCompletionCallback callback2; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3004 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3005 | rv = trans->RestartWithAuth( |
| 3006 | AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3007 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3008 | |
| 3009 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3010 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3011 | |
| 3012 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3013 | ASSERT_TRUE(response); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3014 | |
| 3015 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3016 | EXPECT_EQ(200, response->headers->response_code()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3017 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3018 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3019 | |
| 3020 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3021 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3022 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3023 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3024 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3025 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3026 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3027 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3028 | session->CloseAllConnections(); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3029 | } |
| 3030 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3031 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3032 | // proxy connection with HTTP/1.0 responses, when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3033 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp10) { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3034 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 3035 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 3036 | // reused. See http://crbug.com/544255. |
| 3037 | for (int i = 0; i < 2; ++i) { |
| 3038 | HttpRequestInfo request; |
| 3039 | request.method = "GET"; |
| 3040 | request.url = GURL("https://www.example.org/"); |
| 3041 | // Ensure that proxy authentication is attempted even |
| 3042 | // when the no authentication data flag is set. |
| 3043 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3044 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3045 | // Configure against proxy server "myproxy:70". |
| 3046 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
| 3047 | BoundTestNetLog log; |
| 3048 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3049 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3050 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3051 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3052 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3053 | // Since we have proxy, should try to establish tunnel. |
| 3054 | MockWrite data_writes1[] = { |
| 3055 | MockWrite(ASYNC, 0, |
| 3056 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3057 | "Host: www.example.org:443\r\n" |
| 3058 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3059 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3060 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3061 | // be issuing -- the final header line contains the credentials. |
| 3062 | MockWrite(ASYNC, 3, |
| 3063 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3064 | "Host: www.example.org:443\r\n" |
| 3065 | "Proxy-Connection: keep-alive\r\n" |
| 3066 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 3067 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3068 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3069 | // The proxy responds to the connect with a 407, using a persistent |
| 3070 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 3071 | MockRead data_reads1[] = { |
| 3072 | // No credentials. |
| 3073 | MockRead(ASYNC, 1, |
| 3074 | "HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 3075 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3076 | "Proxy-Connection: keep-alive\r\n" |
| 3077 | "Content-Length: 10\r\n\r\n"), |
| 3078 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 2, "0123456789"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3079 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3080 | // Wrong credentials (wrong password). |
| 3081 | MockRead(ASYNC, 4, |
| 3082 | "HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 3083 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3084 | "Proxy-Connection: keep-alive\r\n" |
| 3085 | "Content-Length: 10\r\n\r\n"), |
| 3086 | // No response body because the test stops reading here. |
| 3087 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 5), |
| 3088 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3089 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3090 | SequencedSocketData data1(data_reads1, arraysize(data_reads1), data_writes1, |
| 3091 | arraysize(data_writes1)); |
| 3092 | data1.set_busy_before_sync_reads(true); |
| 3093 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3094 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3095 | TestCompletionCallback callback1; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3096 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3097 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3098 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3099 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3100 | TestNetLogEntry::List entries; |
| 3101 | log.GetEntries(&entries); |
| 3102 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3103 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3104 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3105 | ExpectLogContainsSomewhere( |
| 3106 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3107 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3108 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3109 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3110 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3111 | ASSERT_TRUE(response); |
| 3112 | ASSERT_TRUE(response->headers); |
| 3113 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3114 | EXPECT_EQ(407, response->headers->response_code()); |
| 3115 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3116 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 3117 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3118 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3119 | TestCompletionCallback callback2; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3120 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3121 | // Wrong password (should be "bar"). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3122 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBaz), |
| 3123 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3124 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3125 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3126 | response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3127 | ASSERT_TRUE(response); |
| 3128 | ASSERT_TRUE(response->headers); |
| 3129 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3130 | EXPECT_EQ(407, response->headers->response_code()); |
| 3131 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3132 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 3133 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3134 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3135 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 3136 | // out of scope. |
| 3137 | session->CloseAllConnections(); |
| 3138 | } |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3139 | } |
| 3140 | |
| 3141 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3142 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3143 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp11) { |
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; |
| 3154 | |
| 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_)); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3160 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3161 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3162 | |
| 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"), |
| 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 | }; |
| 3178 | |
| 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.1 407 Proxy Authentication Required\r\n" |
| 3185 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3186 | "Content-Length: 10\r\n\r\n"), |
| 3187 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 2, "0123456789"), |
| 3188 | |
| 3189 | // Wrong credentials (wrong password). |
| 3190 | MockRead(ASYNC, 4, |
| 3191 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3192 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3193 | "Content-Length: 10\r\n\r\n"), |
| 3194 | // No response body because the test stops reading here. |
| 3195 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 5), |
| 3196 | }; |
| 3197 | |
| 3198 | SequencedSocketData data1(data_reads1, arraysize(data_reads1), data_writes1, |
| 3199 | arraysize(data_writes1)); |
| 3200 | data1.set_busy_before_sync_reads(true); |
| 3201 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3202 | |
| 3203 | TestCompletionCallback callback1; |
| 3204 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3205 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3206 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3207 | |
| 3208 | TestNetLogEntry::List entries; |
| 3209 | log.GetEntries(&entries); |
| 3210 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3211 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3212 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3213 | ExpectLogContainsSomewhere( |
| 3214 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3215 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3216 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3217 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3218 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3219 | ASSERT_TRUE(response); |
| 3220 | ASSERT_TRUE(response->headers); |
| 3221 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3222 | EXPECT_EQ(407, response->headers->response_code()); |
| 3223 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3224 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3225 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3226 | |
| 3227 | TestCompletionCallback callback2; |
| 3228 | |
| 3229 | // Wrong password (should be "bar"). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3230 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBaz), |
| 3231 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3232 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3233 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3234 | response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3235 | ASSERT_TRUE(response); |
| 3236 | ASSERT_TRUE(response->headers); |
| 3237 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3238 | EXPECT_EQ(407, response->headers->response_code()); |
| 3239 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3240 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3241 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3242 | |
| 3243 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 3244 | // out of scope. |
| 3245 | session->CloseAllConnections(); |
| 3246 | } |
| 3247 | } |
| 3248 | |
| 3249 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3250 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel, in |
| 3251 | // the case the server sends extra data on the original socket, so it can't be |
| 3252 | // reused. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3253 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveExtraData) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3254 | HttpRequestInfo request; |
| 3255 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3256 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3257 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3258 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3259 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3260 | // Configure against proxy server "myproxy:70". |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3261 | session_deps_.proxy_service = |
| 3262 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3263 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3264 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3265 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3266 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3267 | // Since we have proxy, should try to establish tunnel. |
| 3268 | MockWrite data_writes1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3269 | MockWrite(ASYNC, 0, |
| 3270 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3271 | "Host: www.example.org:443\r\n" |
| 3272 | "Proxy-Connection: keep-alive\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3273 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3274 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3275 | // The proxy responds to the connect with a 407, using a persistent, but sends |
| 3276 | // extra data, so the socket cannot be reused. |
| 3277 | MockRead data_reads1[] = { |
| 3278 | // No credentials. |
| 3279 | MockRead(ASYNC, 1, |
| 3280 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3281 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3282 | "Content-Length: 10\r\n\r\n"), |
| 3283 | MockRead(SYNCHRONOUS, 2, "0123456789"), |
| 3284 | MockRead(SYNCHRONOUS, 3, "I'm broken!"), |
| 3285 | }; |
| 3286 | |
| 3287 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3288 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3289 | // be issuing -- the final header line contains the credentials. |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3290 | MockWrite(ASYNC, 0, |
| 3291 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3292 | "Host: www.example.org:443\r\n" |
| 3293 | "Proxy-Connection: keep-alive\r\n" |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3294 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3295 | |
| 3296 | MockWrite(ASYNC, 2, |
| 3297 | "GET / HTTP/1.1\r\n" |
| 3298 | "Host: www.example.org\r\n" |
| 3299 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3300 | }; |
| 3301 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3302 | MockRead data_reads2[] = { |
| 3303 | MockRead(ASYNC, 1, "HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3304 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3305 | MockRead(ASYNC, 3, |
| 3306 | "HTTP/1.1 200 OK\r\n" |
| 3307 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 3308 | "Content-Length: 5\r\n\r\n"), |
| 3309 | // No response body because the test stops reading here. |
| 3310 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 4), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3311 | }; |
| 3312 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3313 | SequencedSocketData data1(data_reads1, arraysize(data_reads1), data_writes1, |
| 3314 | arraysize(data_writes1)); |
| 3315 | data1.set_busy_before_sync_reads(true); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3316 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3317 | SequencedSocketData data2(data_reads2, arraysize(data_reads2), data_writes2, |
| 3318 | arraysize(data_writes2)); |
| 3319 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3320 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3321 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3322 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3323 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3324 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3325 | std::unique_ptr<HttpNetworkTransaction> trans( |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3326 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3327 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3328 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3329 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3330 | |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3331 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3332 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 3333 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3334 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3335 | NetLogEventPhase::NONE); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 3336 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3337 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3338 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3339 | NetLogEventPhase::NONE); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3340 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3341 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3342 | ASSERT_TRUE(response); |
| 3343 | ASSERT_TRUE(response->headers); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3344 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3345 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3346 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3347 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3348 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3349 | LoadTimingInfo load_timing_info; |
| 3350 | // CONNECT requests and responses are handled at the connect job level, so |
| 3351 | // the transaction does not yet have a connection. |
| 3352 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3353 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3354 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3355 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3356 | rv = |
| 3357 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3358 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3359 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3360 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3361 | EXPECT_EQ(200, response->headers->response_code()); |
| 3362 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3363 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 3364 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3365 | // The password prompt info should not be set. |
| 3366 | EXPECT_FALSE(response->auth_challenge); |
| 3367 | |
| 3368 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3369 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3370 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3371 | |
| 3372 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3373 | session->CloseAllConnections(); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3374 | } |
| 3375 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3376 | // Test the case a proxy closes a socket while the challenge body is being |
| 3377 | // drained. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3378 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHangupDuringBody) { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3379 | HttpRequestInfo request; |
| 3380 | request.method = "GET"; |
| 3381 | request.url = GURL("https://www.example.org/"); |
| 3382 | // Ensure that proxy authentication is attempted even |
| 3383 | // when the no authentication data flag is set. |
| 3384 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
| 3385 | |
| 3386 | // Configure against proxy server "myproxy:70". |
| 3387 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3388 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3389 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3390 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3391 | |
| 3392 | // Since we have proxy, should try to establish tunnel. |
| 3393 | MockWrite data_writes1[] = { |
| 3394 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3395 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3396 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3397 | }; |
| 3398 | |
| 3399 | // The proxy responds to the connect with a 407, using a persistent |
| 3400 | // connection. |
| 3401 | MockRead data_reads1[] = { |
| 3402 | // No credentials. |
| 3403 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3404 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3405 | MockRead("Content-Length: 10\r\n\r\n"), MockRead("spam!"), |
| 3406 | // Server hands up in the middle of the body. |
| 3407 | MockRead(ASYNC, ERR_CONNECTION_CLOSED), |
| 3408 | }; |
| 3409 | |
| 3410 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3411 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3412 | // be issuing -- the final header line contains the credentials. |
| 3413 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3414 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3415 | "Proxy-Connection: keep-alive\r\n" |
| 3416 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3417 | |
| 3418 | MockWrite("GET / HTTP/1.1\r\n" |
| 3419 | "Host: www.example.org\r\n" |
| 3420 | "Connection: keep-alive\r\n\r\n"), |
| 3421 | }; |
| 3422 | |
| 3423 | MockRead data_reads2[] = { |
| 3424 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3425 | |
| 3426 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3427 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3428 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3429 | MockRead(SYNCHRONOUS, "hello"), |
| 3430 | }; |
| 3431 | |
| 3432 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3433 | data_writes1, arraysize(data_writes1)); |
| 3434 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3435 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3436 | data_writes2, arraysize(data_writes2)); |
| 3437 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3438 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3439 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3440 | |
| 3441 | TestCompletionCallback callback; |
| 3442 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3443 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3444 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3445 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3446 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3447 | ASSERT_TRUE(response); |
| 3448 | ASSERT_TRUE(response->headers); |
| 3449 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3450 | EXPECT_EQ(407, response->headers->response_code()); |
| 3451 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3452 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3453 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3454 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3455 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3456 | response = trans.GetResponseInfo(); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3457 | ASSERT_TRUE(response); |
| 3458 | ASSERT_TRUE(response->headers); |
| 3459 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3460 | EXPECT_EQ(200, response->headers->response_code()); |
| 3461 | std::string body; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3462 | EXPECT_THAT(ReadTransaction(&trans, &body), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3463 | EXPECT_EQ("hello", body); |
| 3464 | } |
| 3465 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3466 | // Test that we don't read the response body when we fail to establish a tunnel, |
| 3467 | // even if the user cancels the proxy's auth attempt. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3468 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyCancelTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3469 | HttpRequestInfo request; |
| 3470 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3471 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3472 | request.load_flags = 0; |
| 3473 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3474 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3475 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3476 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3477 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3478 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3479 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3480 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3481 | // Since we have proxy, should try to establish tunnel. |
| 3482 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3483 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3484 | "Host: www.example.org:443\r\n" |
| 3485 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3486 | }; |
| 3487 | |
| 3488 | // The proxy responds to the connect with a 407. |
| 3489 | MockRead data_reads[] = { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3490 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3491 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3492 | MockRead("Content-Length: 10\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3493 | MockRead("0123456789"), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3494 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3495 | }; |
| 3496 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 3497 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 3498 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3499 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3500 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3501 | TestCompletionCallback callback; |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3502 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3503 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3504 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3505 | |
| 3506 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3507 | EXPECT_THAT(rv, IsOk()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3508 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3509 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3510 | ASSERT_TRUE(response); |
| 3511 | ASSERT_TRUE(response->headers); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3512 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3513 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3514 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3515 | |
| 3516 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3517 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3518 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 3519 | |
| 3520 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3521 | session->CloseAllConnections(); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3522 | } |
| 3523 | |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3524 | // Test that we don't pass extraneous headers from the proxy's response to the |
| 3525 | // caller when the proxy responds to CONNECT with 407. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3526 | TEST_F(HttpNetworkTransactionTest, SanitizeProxyAuthHeaders) { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3527 | HttpRequestInfo request; |
| 3528 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3529 | request.url = GURL("https://www.example.org/"); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3530 | request.load_flags = 0; |
| 3531 | |
| 3532 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3533 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3534 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3535 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3536 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3537 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3538 | |
| 3539 | // Since we have proxy, should try to establish tunnel. |
| 3540 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3541 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3542 | "Host: www.example.org:443\r\n" |
| 3543 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3544 | }; |
| 3545 | |
| 3546 | // The proxy responds to the connect with a 407. |
| 3547 | MockRead data_reads[] = { |
| 3548 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3549 | MockRead("X-Foo: bar\r\n"), |
| 3550 | MockRead("Set-Cookie: foo=bar\r\n"), |
| 3551 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3552 | MockRead("Content-Length: 10\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3553 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3554 | }; |
| 3555 | |
| 3556 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 3557 | arraysize(data_writes)); |
| 3558 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 3559 | |
| 3560 | TestCompletionCallback callback; |
| 3561 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3562 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3563 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3564 | |
| 3565 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3566 | EXPECT_THAT(rv, IsOk()); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3567 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3568 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3569 | ASSERT_TRUE(response); |
| 3570 | ASSERT_TRUE(response->headers); |
| 3571 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3572 | EXPECT_EQ(407, response->headers->response_code()); |
| 3573 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3574 | EXPECT_FALSE(response->headers->HasHeader("X-Foo")); |
| 3575 | EXPECT_FALSE(response->headers->HasHeader("Set-Cookie")); |
| 3576 | |
| 3577 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3578 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3579 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3580 | |
| 3581 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
| 3582 | session->CloseAllConnections(); |
| 3583 | } |
| 3584 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3585 | // Test when a server (non-proxy) returns a 407 (proxy-authenticate). |
| 3586 | // The request should fail with ERR_UNEXPECTED_PROXY_AUTH. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3587 | TEST_F(HttpNetworkTransactionTest, UnexpectedProxyAuth) { |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3588 | HttpRequestInfo request; |
| 3589 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3590 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3591 | request.load_flags = 0; |
| 3592 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3593 | // We are using a DIRECT connection (i.e. no proxy) for this session. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3594 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3595 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3596 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3597 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3598 | MockWrite( |
| 3599 | "GET / HTTP/1.1\r\n" |
| 3600 | "Host: www.example.org\r\n" |
| 3601 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3602 | }; |
| 3603 | |
| 3604 | MockRead data_reads1[] = { |
| 3605 | MockRead("HTTP/1.0 407 Proxy Auth required\r\n"), |
| 3606 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3607 | // Large content-length -- won't matter, as connection will be reset. |
| 3608 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3609 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3610 | }; |
| 3611 | |
| 3612 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3613 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3614 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3615 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3616 | TestCompletionCallback callback; |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3617 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3618 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3619 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3620 | |
| 3621 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3622 | EXPECT_THAT(rv, IsError(ERR_UNEXPECTED_PROXY_AUTH)); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3623 | } |
| 3624 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3625 | // Tests when an HTTPS server (non-proxy) returns a 407 (proxy-authentication) |
| 3626 | // through a non-authenticating proxy. The request should fail with |
| 3627 | // ERR_UNEXPECTED_PROXY_AUTH. |
| 3628 | // Note that it is impossible to detect if an HTTP server returns a 407 through |
| 3629 | // a non-authenticating proxy - there is nothing to indicate whether the |
| 3630 | // response came from the proxy or the server, so it is treated as if the proxy |
| 3631 | // issued the challenge. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3632 | TEST_F(HttpNetworkTransactionTest, HttpsServerRequestsProxyAuthThroughProxy) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3633 | HttpRequestInfo request; |
| 3634 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3635 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3636 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3637 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3638 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3639 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3640 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3641 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3642 | // Since we have proxy, should try to establish tunnel. |
| 3643 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3644 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3645 | "Host: www.example.org:443\r\n" |
| 3646 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3647 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3648 | MockWrite("GET / HTTP/1.1\r\n" |
| 3649 | "Host: www.example.org\r\n" |
| 3650 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3651 | }; |
| 3652 | |
| 3653 | MockRead data_reads1[] = { |
| 3654 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3655 | |
| 3656 | MockRead("HTTP/1.1 407 Unauthorized\r\n"), |
| 3657 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3658 | MockRead("\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3659 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3660 | }; |
| 3661 | |
| 3662 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3663 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3664 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3665 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3666 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3667 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3668 | TestCompletionCallback callback1; |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3669 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3670 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3671 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3672 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3673 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3674 | |
| 3675 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3676 | EXPECT_THAT(rv, IsError(ERR_UNEXPECTED_PROXY_AUTH)); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3677 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3678 | log.GetEntries(&entries); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3679 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3680 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3681 | NetLogEventPhase::NONE); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3682 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3683 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3684 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3685 | NetLogEventPhase::NONE); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3686 | } |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3687 | |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3688 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 3689 | // that uses non-persistent connections. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3690 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3691 | AuthAllowsDefaultCredentialsTunnelConnectionClose) { |
| 3692 | HttpRequestInfo request; |
| 3693 | request.method = "GET"; |
| 3694 | request.url = GURL("https://www.example.org/"); |
| 3695 | |
| 3696 | // Configure against proxy server "myproxy:70". |
| 3697 | session_deps_.proxy_service = |
| 3698 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 3699 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3700 | std::unique_ptr<HttpAuthHandlerMock::Factory> auth_handler_factory( |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3701 | new HttpAuthHandlerMock::Factory()); |
| 3702 | auth_handler_factory->set_do_init_from_challenge(true); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3703 | std::unique_ptr<HttpAuthHandlerMock> mock_handler(new HttpAuthHandlerMock()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3704 | mock_handler->set_allows_default_credentials(true); |
| 3705 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 3706 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 3707 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3708 | |
| 3709 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 3710 | NetLog net_log; |
| 3711 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3712 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3713 | |
| 3714 | // Since we have proxy, should try to establish tunnel. |
| 3715 | MockWrite data_writes1[] = { |
| 3716 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3717 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3718 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3719 | }; |
| 3720 | |
| 3721 | // The proxy responds to the connect with a 407, using a non-persistent |
| 3722 | // connection. |
| 3723 | MockRead data_reads1[] = { |
| 3724 | // No credentials. |
| 3725 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3726 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 3727 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 3728 | }; |
| 3729 | |
| 3730 | // Since the first connection couldn't be reused, need to establish another |
| 3731 | // once given credentials. |
| 3732 | MockWrite data_writes2[] = { |
| 3733 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3734 | // be issuing -- the final header line contains the credentials. |
| 3735 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3736 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3737 | "Proxy-Connection: keep-alive\r\n" |
| 3738 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 3739 | |
| 3740 | MockWrite("GET / HTTP/1.1\r\n" |
| 3741 | "Host: www.example.org\r\n" |
| 3742 | "Connection: keep-alive\r\n\r\n"), |
| 3743 | }; |
| 3744 | |
| 3745 | MockRead data_reads2[] = { |
| 3746 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 3747 | |
| 3748 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3749 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3750 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3751 | MockRead(SYNCHRONOUS, "hello"), |
| 3752 | }; |
| 3753 | |
| 3754 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3755 | data_writes1, arraysize(data_writes1)); |
| 3756 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3757 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3758 | data_writes2, arraysize(data_writes2)); |
| 3759 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3760 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3761 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3762 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3763 | std::unique_ptr<HttpNetworkTransaction> trans( |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3764 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 3765 | |
| 3766 | TestCompletionCallback callback; |
| 3767 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3768 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3769 | |
| 3770 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3771 | ASSERT_TRUE(response); |
| 3772 | ASSERT_TRUE(response->headers); |
| 3773 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
| 3774 | EXPECT_EQ(407, response->headers->response_code()); |
| 3775 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3776 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3777 | EXPECT_FALSE(response->auth_challenge); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3778 | |
| 3779 | LoadTimingInfo load_timing_info; |
| 3780 | // CONNECT requests and responses are handled at the connect job level, so |
| 3781 | // the transaction does not yet have a connection. |
| 3782 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3783 | |
| 3784 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3785 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3786 | response = trans->GetResponseInfo(); |
| 3787 | ASSERT_TRUE(response); |
| 3788 | ASSERT_TRUE(response->headers); |
| 3789 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3790 | EXPECT_EQ(200, response->headers->response_code()); |
| 3791 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 3792 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3793 | |
| 3794 | // The password prompt info should not be set. |
| 3795 | EXPECT_FALSE(response->auth_challenge); |
| 3796 | |
| 3797 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3798 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3799 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3800 | |
| 3801 | trans.reset(); |
| 3802 | session->CloseAllConnections(); |
| 3803 | } |
| 3804 | |
| 3805 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 3806 | // that hangs up when credentials are initially sent. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3807 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3808 | AuthAllowsDefaultCredentialsTunnelServerClosesConnection) { |
| 3809 | HttpRequestInfo request; |
| 3810 | request.method = "GET"; |
| 3811 | request.url = GURL("https://www.example.org/"); |
| 3812 | |
| 3813 | // Configure against proxy server "myproxy:70". |
| 3814 | session_deps_.proxy_service = |
| 3815 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 3816 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3817 | std::unique_ptr<HttpAuthHandlerMock::Factory> auth_handler_factory( |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3818 | new HttpAuthHandlerMock::Factory()); |
| 3819 | auth_handler_factory->set_do_init_from_challenge(true); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3820 | std::unique_ptr<HttpAuthHandlerMock> mock_handler(new HttpAuthHandlerMock()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3821 | mock_handler->set_allows_default_credentials(true); |
| 3822 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 3823 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 3824 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3825 | |
| 3826 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 3827 | NetLog net_log; |
| 3828 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3829 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3830 | |
| 3831 | // Should try to establish tunnel. |
| 3832 | MockWrite data_writes1[] = { |
| 3833 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3834 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3835 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3836 | |
| 3837 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3838 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3839 | "Proxy-Connection: keep-alive\r\n" |
| 3840 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 3841 | }; |
| 3842 | |
| 3843 | // The proxy responds to the connect with a 407, using a non-persistent |
| 3844 | // connection. |
| 3845 | MockRead data_reads1[] = { |
| 3846 | // No credentials. |
| 3847 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3848 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 3849 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 3850 | }; |
| 3851 | |
| 3852 | // Since the first connection was closed, need to establish another once given |
| 3853 | // credentials. |
| 3854 | MockWrite data_writes2[] = { |
| 3855 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3856 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3857 | "Proxy-Connection: keep-alive\r\n" |
| 3858 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 3859 | |
| 3860 | MockWrite("GET / HTTP/1.1\r\n" |
| 3861 | "Host: www.example.org\r\n" |
| 3862 | "Connection: keep-alive\r\n\r\n"), |
| 3863 | }; |
| 3864 | |
| 3865 | MockRead data_reads2[] = { |
| 3866 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 3867 | |
| 3868 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3869 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3870 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3871 | MockRead(SYNCHRONOUS, "hello"), |
| 3872 | }; |
| 3873 | |
| 3874 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3875 | data_writes1, arraysize(data_writes1)); |
| 3876 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3877 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3878 | data_writes2, arraysize(data_writes2)); |
| 3879 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3880 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3881 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3882 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3883 | std::unique_ptr<HttpNetworkTransaction> trans( |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3884 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 3885 | |
| 3886 | TestCompletionCallback callback; |
| 3887 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3888 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3889 | |
| 3890 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3891 | ASSERT_TRUE(response); |
| 3892 | ASSERT_TRUE(response->headers); |
| 3893 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3894 | EXPECT_EQ(407, response->headers->response_code()); |
| 3895 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3896 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 3897 | EXPECT_FALSE(response->auth_challenge); |
| 3898 | |
| 3899 | LoadTimingInfo load_timing_info; |
| 3900 | // CONNECT requests and responses are handled at the connect job level, so |
| 3901 | // the transaction does not yet have a connection. |
| 3902 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3903 | |
| 3904 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3905 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3906 | |
| 3907 | response = trans->GetResponseInfo(); |
| 3908 | ASSERT_TRUE(response); |
| 3909 | ASSERT_TRUE(response->headers); |
| 3910 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3911 | EXPECT_EQ(200, response->headers->response_code()); |
| 3912 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 3913 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3914 | |
| 3915 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3916 | EXPECT_FALSE(response->auth_challenge); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3917 | |
| 3918 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3919 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3920 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3921 | |
| 3922 | trans.reset(); |
| 3923 | session->CloseAllConnections(); |
| 3924 | } |
| 3925 | |
| 3926 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 3927 | // that hangs up when credentials are initially sent, and hangs up again when |
| 3928 | // they are retried. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3929 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3930 | AuthAllowsDefaultCredentialsTunnelServerClosesConnectionTwice) { |
| 3931 | HttpRequestInfo request; |
| 3932 | request.method = "GET"; |
| 3933 | request.url = GURL("https://www.example.org/"); |
| 3934 | |
| 3935 | // Configure against proxy server "myproxy:70". |
| 3936 | session_deps_.proxy_service = |
| 3937 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 3938 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3939 | std::unique_ptr<HttpAuthHandlerMock::Factory> auth_handler_factory( |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3940 | new HttpAuthHandlerMock::Factory()); |
| 3941 | auth_handler_factory->set_do_init_from_challenge(true); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3942 | std::unique_ptr<HttpAuthHandlerMock> mock_handler(new HttpAuthHandlerMock()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3943 | mock_handler->set_allows_default_credentials(true); |
| 3944 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 3945 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 3946 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3947 | |
| 3948 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 3949 | NetLog net_log; |
| 3950 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3951 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3952 | |
| 3953 | // Should try to establish tunnel. |
| 3954 | MockWrite data_writes1[] = { |
| 3955 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3956 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3957 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3958 | |
| 3959 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3960 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3961 | "Proxy-Connection: keep-alive\r\n" |
| 3962 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 3963 | }; |
| 3964 | |
| 3965 | // The proxy responds to the connect with a 407, and then hangs up after the |
| 3966 | // second request is sent. |
| 3967 | MockRead data_reads1[] = { |
| 3968 | // No credentials. |
| 3969 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3970 | MockRead("Content-Length: 0\r\n"), |
| 3971 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 3972 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 3973 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 3974 | }; |
| 3975 | |
| 3976 | // HttpNetworkTransaction sees a reused connection that was closed with |
| 3977 | // ERR_CONNECTION_CLOSED, realized it might have been a race, so retries the |
| 3978 | // request. |
| 3979 | MockWrite data_writes2[] = { |
| 3980 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3981 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3982 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3983 | }; |
| 3984 | |
| 3985 | // The proxy, having had more than enough of us, just hangs up. |
| 3986 | MockRead data_reads2[] = { |
| 3987 | // No credentials. |
| 3988 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 3989 | }; |
| 3990 | |
| 3991 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3992 | data_writes1, arraysize(data_writes1)); |
| 3993 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3994 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3995 | data_writes2, arraysize(data_writes2)); |
| 3996 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3997 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3998 | std::unique_ptr<HttpNetworkTransaction> trans( |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3999 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 4000 | |
| 4001 | TestCompletionCallback callback; |
| 4002 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4003 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4004 | |
| 4005 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4006 | ASSERT_TRUE(response); |
| 4007 | ASSERT_TRUE(response->headers); |
| 4008 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4009 | EXPECT_EQ(407, response->headers->response_code()); |
| 4010 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4011 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4012 | EXPECT_FALSE(response->auth_challenge); |
| 4013 | |
| 4014 | LoadTimingInfo load_timing_info; |
| 4015 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4016 | |
| 4017 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4018 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_EMPTY_RESPONSE)); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4019 | |
| 4020 | trans.reset(); |
| 4021 | session->CloseAllConnections(); |
| 4022 | } |
| 4023 | |
| 4024 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4025 | // that hangs up when credentials are initially sent, and sends a challenge |
| 4026 | // again they are retried. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4027 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4028 | AuthAllowsDefaultCredentialsTunnelServerChallengesTwice) { |
| 4029 | HttpRequestInfo request; |
| 4030 | request.method = "GET"; |
| 4031 | request.url = GURL("https://www.example.org/"); |
| 4032 | |
| 4033 | // Configure against proxy server "myproxy:70". |
| 4034 | session_deps_.proxy_service = |
| 4035 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 4036 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4037 | std::unique_ptr<HttpAuthHandlerMock::Factory> auth_handler_factory( |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4038 | new HttpAuthHandlerMock::Factory()); |
| 4039 | auth_handler_factory->set_do_init_from_challenge(true); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4040 | std::unique_ptr<HttpAuthHandlerMock> mock_handler(new HttpAuthHandlerMock()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4041 | mock_handler->set_allows_default_credentials(true); |
| 4042 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4043 | HttpAuth::AUTH_PROXY); |
| 4044 | // Add another handler for the second challenge. It supports default |
| 4045 | // credentials, but they shouldn't be used, since they were already tried. |
| 4046 | mock_handler.reset(new HttpAuthHandlerMock()); |
| 4047 | mock_handler->set_allows_default_credentials(true); |
| 4048 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4049 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4050 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4051 | |
| 4052 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4053 | NetLog net_log; |
| 4054 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4055 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4056 | |
| 4057 | // Should try to establish tunnel. |
| 4058 | MockWrite data_writes1[] = { |
| 4059 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4060 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4061 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4062 | }; |
| 4063 | |
| 4064 | // The proxy responds to the connect with a 407, using a non-persistent |
| 4065 | // connection. |
| 4066 | MockRead data_reads1[] = { |
| 4067 | // No credentials. |
| 4068 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4069 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4070 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4071 | }; |
| 4072 | |
| 4073 | // Since the first connection was closed, need to establish another once given |
| 4074 | // credentials. |
| 4075 | MockWrite data_writes2[] = { |
| 4076 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4077 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4078 | "Proxy-Connection: keep-alive\r\n" |
| 4079 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4080 | }; |
| 4081 | |
| 4082 | MockRead data_reads2[] = { |
| 4083 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4084 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4085 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4086 | }; |
| 4087 | |
| 4088 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4089 | data_writes1, arraysize(data_writes1)); |
| 4090 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4091 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4092 | data_writes2, arraysize(data_writes2)); |
| 4093 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4094 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4095 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4096 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4097 | std::unique_ptr<HttpNetworkTransaction> trans( |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4098 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 4099 | |
| 4100 | TestCompletionCallback callback; |
| 4101 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4102 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4103 | |
| 4104 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4105 | ASSERT_TRUE(response); |
| 4106 | ASSERT_TRUE(response->headers); |
| 4107 | EXPECT_EQ(407, response->headers->response_code()); |
| 4108 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4109 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4110 | EXPECT_FALSE(response->auth_challenge); |
| 4111 | |
| 4112 | LoadTimingInfo load_timing_info; |
| 4113 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4114 | |
| 4115 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4116 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4117 | response = trans->GetResponseInfo(); |
| 4118 | ASSERT_TRUE(response); |
| 4119 | ASSERT_TRUE(response->headers); |
| 4120 | EXPECT_EQ(407, response->headers->response_code()); |
| 4121 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 4122 | EXPECT_TRUE(response->auth_challenge); |
| 4123 | |
| 4124 | trans.reset(); |
| 4125 | session->CloseAllConnections(); |
| 4126 | } |
| 4127 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4128 | // Test the load timing for HTTPS requests with an HTTP proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4129 | TEST_F(HttpNetworkTransactionTest, HttpProxyLoadTimingNoPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4130 | HttpRequestInfo request1; |
| 4131 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4132 | request1.url = GURL("https://www.example.org/1"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4133 | |
| 4134 | HttpRequestInfo request2; |
| 4135 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4136 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4137 | |
| 4138 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4139 | session_deps_.proxy_service = ProxyService::CreateFixed("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4140 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4141 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4142 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4143 | |
| 4144 | // Since we have proxy, should try to establish tunnel. |
| 4145 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4146 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4147 | "Host: www.example.org:443\r\n" |
| 4148 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4149 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4150 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 4151 | "Host: www.example.org\r\n" |
| 4152 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4153 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4154 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 4155 | "Host: www.example.org\r\n" |
| 4156 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4157 | }; |
| 4158 | |
| 4159 | // The proxy responds to the connect with a 407, using a persistent |
| 4160 | // connection. |
| 4161 | MockRead data_reads1[] = { |
| 4162 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 4163 | |
| 4164 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4165 | MockRead("Content-Length: 1\r\n\r\n"), |
| 4166 | MockRead(SYNCHRONOUS, "1"), |
| 4167 | |
| 4168 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4169 | MockRead("Content-Length: 2\r\n\r\n"), |
| 4170 | MockRead(SYNCHRONOUS, "22"), |
| 4171 | }; |
| 4172 | |
| 4173 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4174 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4175 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4176 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4177 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4178 | |
| 4179 | TestCompletionCallback callback1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4180 | std::unique_ptr<HttpNetworkTransaction> trans1( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4181 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4182 | |
| 4183 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4184 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4185 | |
| 4186 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4187 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4188 | |
| 4189 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4190 | ASSERT_TRUE(response1); |
| 4191 | ASSERT_TRUE(response1->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4192 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 4193 | |
| 4194 | LoadTimingInfo load_timing_info1; |
| 4195 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 4196 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4197 | |
| 4198 | trans1.reset(); |
| 4199 | |
| 4200 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4201 | std::unique_ptr<HttpNetworkTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4202 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4203 | |
| 4204 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4205 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4206 | |
| 4207 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4208 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4209 | |
| 4210 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4211 | ASSERT_TRUE(response2); |
| 4212 | ASSERT_TRUE(response2->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4213 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 4214 | |
| 4215 | LoadTimingInfo load_timing_info2; |
| 4216 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4217 | TestLoadTimingReused(load_timing_info2); |
| 4218 | |
| 4219 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 4220 | |
| 4221 | trans2.reset(); |
| 4222 | session->CloseAllConnections(); |
| 4223 | } |
| 4224 | |
| 4225 | // 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] | 4226 | TEST_F(HttpNetworkTransactionTest, HttpProxyLoadTimingWithPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4227 | HttpRequestInfo request1; |
| 4228 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4229 | request1.url = GURL("https://www.example.org/1"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4230 | |
| 4231 | HttpRequestInfo request2; |
| 4232 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4233 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4234 | |
| 4235 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4236 | session_deps_.proxy_service = |
| 4237 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4238 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4239 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4240 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4241 | |
| 4242 | // Since we have proxy, should try to establish tunnel. |
| 4243 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4244 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4245 | "Host: www.example.org:443\r\n" |
| 4246 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4247 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4248 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 4249 | "Host: www.example.org\r\n" |
| 4250 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4251 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4252 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 4253 | "Host: www.example.org\r\n" |
| 4254 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4255 | }; |
| 4256 | |
| 4257 | // The proxy responds to the connect with a 407, using a persistent |
| 4258 | // connection. |
| 4259 | MockRead data_reads1[] = { |
| 4260 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 4261 | |
| 4262 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4263 | MockRead("Content-Length: 1\r\n\r\n"), |
| 4264 | MockRead(SYNCHRONOUS, "1"), |
| 4265 | |
| 4266 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4267 | MockRead("Content-Length: 2\r\n\r\n"), |
| 4268 | MockRead(SYNCHRONOUS, "22"), |
| 4269 | }; |
| 4270 | |
| 4271 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4272 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4273 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4274 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4275 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4276 | |
| 4277 | TestCompletionCallback callback1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4278 | std::unique_ptr<HttpNetworkTransaction> trans1( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4279 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4280 | |
| 4281 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4282 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4283 | |
| 4284 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4285 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4286 | |
| 4287 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4288 | ASSERT_TRUE(response1); |
| 4289 | ASSERT_TRUE(response1->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4290 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 4291 | |
| 4292 | LoadTimingInfo load_timing_info1; |
| 4293 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 4294 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 4295 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4296 | |
| 4297 | trans1.reset(); |
| 4298 | |
| 4299 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4300 | std::unique_ptr<HttpNetworkTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4301 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4302 | |
| 4303 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4304 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4305 | |
| 4306 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4307 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4308 | |
| 4309 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4310 | ASSERT_TRUE(response2); |
| 4311 | ASSERT_TRUE(response2->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4312 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 4313 | |
| 4314 | LoadTimingInfo load_timing_info2; |
| 4315 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4316 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 4317 | |
| 4318 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 4319 | |
| 4320 | trans2.reset(); |
| 4321 | session->CloseAllConnections(); |
| 4322 | } |
| 4323 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4324 | // Test a simple get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4325 | TEST_F(HttpNetworkTransactionTest, HttpsProxyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4326 | HttpRequestInfo request; |
| 4327 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4328 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4329 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4330 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4331 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4332 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4333 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4334 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4335 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4336 | // Since we have proxy, should use full url |
| 4337 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4338 | MockWrite( |
| 4339 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 4340 | "Host: www.example.org\r\n" |
| 4341 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4342 | }; |
| 4343 | |
| 4344 | MockRead data_reads1[] = { |
| 4345 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4346 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4347 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4348 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4349 | }; |
| 4350 | |
| 4351 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4352 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4353 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4354 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4355 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4356 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4357 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4358 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4359 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4360 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4361 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4362 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4363 | |
| 4364 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4365 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4366 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4367 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4368 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4369 | TestLoadTimingNotReused(load_timing_info, |
| 4370 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 4371 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4372 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4373 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4374 | |
| 4375 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4376 | EXPECT_EQ(200, response->headers->response_code()); |
| 4377 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 4378 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4379 | |
| 4380 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4381 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4382 | } |
| 4383 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4384 | // Test a SPDY get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4385 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4386 | HttpRequestInfo request; |
| 4387 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4388 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4389 | request.load_flags = 0; |
| 4390 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4391 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4392 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4393 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4394 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4395 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4396 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4397 | // fetch http://www.example.org/ via SPDY |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4398 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 4399 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4400 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4401 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4402 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4403 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4404 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4405 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4406 | }; |
| 4407 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4408 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4409 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4410 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4411 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4412 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 4413 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4414 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4415 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4416 | TestCompletionCallback callback1; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4417 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4418 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4419 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4420 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4421 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4422 | |
| 4423 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4424 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4425 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4426 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4427 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4428 | TestLoadTimingNotReused(load_timing_info, |
| 4429 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 4430 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4431 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4432 | ASSERT_TRUE(response); |
| 4433 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 4434 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4435 | |
| 4436 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4437 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 4438 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4439 | } |
| 4440 | |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4441 | // Verifies that a session which races and wins against the owning transaction |
| 4442 | // (completing prior to host resolution), doesn't fail the transaction. |
| 4443 | // Regression test for crbug.com/334413. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4444 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGetWithSessionRace) { |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4445 | HttpRequestInfo request; |
| 4446 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4447 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4448 | request.load_flags = 0; |
| 4449 | |
| 4450 | // Configure SPDY proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4451 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4452 | BoundTestNetLog log; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4453 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4454 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4455 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4456 | // Fetch http://www.example.org/ through the SPDY proxy. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4457 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 4458 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4459 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4460 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4461 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4462 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4463 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4464 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4465 | }; |
| 4466 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4467 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4468 | arraysize(spdy_writes)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4469 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 4470 | |
| 4471 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 4472 | ssl.next_proto = kProtoHTTP2; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4473 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4474 | |
| 4475 | TestCompletionCallback callback1; |
| 4476 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4477 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4478 | |
| 4479 | // Stall the hostname resolution begun by the transaction. |
| 4480 | session_deps_.host_resolver->set_synchronous_mode(false); |
| 4481 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 4482 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4483 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4484 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4485 | |
| 4486 | // Race a session to the proxy, which completes first. |
| 4487 | session_deps_.host_resolver->set_ondemand_mode(false); |
| 4488 | SpdySessionKey key( |
| 4489 | HostPortPair("proxy", 70), ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
| 4490 | base::WeakPtr<SpdySession> spdy_session = |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4491 | CreateSecureSpdySession(session.get(), key, log.bound()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4492 | |
| 4493 | // Unstall the resolution begun by the transaction. |
| 4494 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 4495 | session_deps_.host_resolver->ResolveAllPending(); |
| 4496 | |
| 4497 | EXPECT_FALSE(callback1.have_result()); |
| 4498 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4499 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4500 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4501 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4502 | ASSERT_TRUE(response); |
| 4503 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 4504 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4505 | |
| 4506 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4507 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4508 | EXPECT_EQ(kUploadData, response_data); |
| 4509 | } |
| 4510 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4511 | // Test a SPDY get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4512 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGetWithProxyAuth) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4513 | HttpRequestInfo request; |
| 4514 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4515 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4516 | request.load_flags = 0; |
| 4517 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4518 | // Configure against https proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4519 | session_deps_.proxy_service = ProxyService::CreateFixed("https://myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4520 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4521 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4522 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4523 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4524 | // The first request will be a bare GET, the second request will be a |
| 4525 | // GET with a Proxy-Authorization header. |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 4526 | spdy_util_.set_default_url(request.url); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4527 | SpdySerializedFrame req_get( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4528 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, false)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4529 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4530 | const char* const kExtraAuthorizationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4531 | "proxy-authorization", "Basic Zm9vOmJhcg==" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4532 | }; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4533 | SpdySerializedFrame req_get_authorization(spdy_util_.ConstructSpdyGet( |
| 4534 | kExtraAuthorizationHeaders, arraysize(kExtraAuthorizationHeaders) / 2, 3, |
| 4535 | LOWEST, false)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4536 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4537 | CreateMockWrite(req_get, 0), CreateMockWrite(req_get_authorization, 3), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4538 | }; |
| 4539 | |
| 4540 | // The first response is a 407 proxy authentication challenge, and the second |
| 4541 | // response will be a 200 response since the second request includes a valid |
| 4542 | // Authorization header. |
| 4543 | const char* const kExtraAuthenticationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4544 | "proxy-authenticate", "Basic realm=\"MyRealm1\"" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4545 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4546 | SpdySerializedFrame resp_authentication(spdy_util_.ConstructSpdyReplyError( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4547 | "407 Proxy Authentication Required", kExtraAuthenticationHeaders, |
| 4548 | arraysize(kExtraAuthenticationHeaders) / 2, 1)); |
| 4549 | SpdySerializedFrame body_authentication( |
| 4550 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4551 | SpdySerializedFrame resp_data(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4552 | SpdySerializedFrame body_data(spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4553 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4554 | CreateMockRead(resp_authentication, 1), |
| 4555 | CreateMockRead(body_authentication, 2), |
| 4556 | CreateMockRead(resp_data, 4), |
| 4557 | CreateMockRead(body_data, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4558 | MockRead(ASYNC, 0, 6), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4559 | }; |
| 4560 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4561 | SequencedSocketData data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4562 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4563 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4564 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4565 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 4566 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4567 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4568 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4569 | TestCompletionCallback callback1; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4570 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4571 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4572 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4573 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4574 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4575 | |
| 4576 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4577 | EXPECT_THAT(rv, IsOk()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4578 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4579 | const HttpResponseInfo* const response = trans.GetResponseInfo(); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4580 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4581 | ASSERT_TRUE(response); |
| 4582 | ASSERT_TRUE(response->headers); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4583 | EXPECT_EQ(407, response->headers->response_code()); |
| 4584 | EXPECT_TRUE(response->was_fetched_via_spdy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 4585 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4586 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4587 | TestCompletionCallback callback2; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4588 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4589 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4590 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4591 | |
| 4592 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4593 | EXPECT_THAT(rv, IsOk()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4594 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4595 | const HttpResponseInfo* const response_restart = trans.GetResponseInfo(); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4596 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4597 | ASSERT_TRUE(response_restart); |
| 4598 | ASSERT_TRUE(response_restart->headers); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4599 | EXPECT_EQ(200, response_restart->headers->response_code()); |
| 4600 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4601 | EXPECT_FALSE(response_restart->auth_challenge); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4602 | } |
| 4603 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4604 | // Test a SPDY CONNECT through an HTTPS Proxy to an HTTPS (non-SPDY) Server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4605 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectHttps) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4606 | HttpRequestInfo request; |
| 4607 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4608 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4609 | request.load_flags = 0; |
| 4610 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4611 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4612 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4613 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4614 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4615 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4616 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4617 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4618 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4619 | // CONNECT to www.example.org:443 via SPDY |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4620 | SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4621 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 4622 | // fetch https://www.example.org/ via HTTP |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4623 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4624 | const char get[] = |
| 4625 | "GET / HTTP/1.1\r\n" |
| 4626 | "Host: www.example.org\r\n" |
| 4627 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4628 | SpdySerializedFrame wrapped_get( |
| 4629 | spdy_util_.ConstructSpdyDataFrame(1, get, strlen(get), false)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4630 | SpdySerializedFrame conn_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4631 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 4632 | "Content-Length: 10\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4633 | SpdySerializedFrame wrapped_get_resp( |
| 4634 | spdy_util_.ConstructSpdyDataFrame(1, resp, strlen(resp), false)); |
| 4635 | SpdySerializedFrame wrapped_body( |
| 4636 | spdy_util_.ConstructSpdyDataFrame(1, "1234567890", 10, false)); |
| 4637 | SpdySerializedFrame window_update( |
| 4638 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 4639 | |
| 4640 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4641 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_get, 2), |
| 4642 | CreateMockWrite(window_update, 6), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 4643 | }; |
| 4644 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4645 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4646 | CreateMockRead(conn_resp, 1, ASYNC), |
| 4647 | CreateMockRead(wrapped_get_resp, 3, ASYNC), |
| 4648 | CreateMockRead(wrapped_body, 4, ASYNC), |
| 4649 | CreateMockRead(wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4650 | MockRead(ASYNC, 0, 7), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4651 | }; |
| 4652 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4653 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4654 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4655 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4656 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4657 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 4658 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4659 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4660 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4661 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4662 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4663 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4664 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4665 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4666 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4667 | |
| 4668 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4669 | ASSERT_THAT(rv, IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4670 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4671 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4672 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4673 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4674 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4675 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4676 | ASSERT_TRUE(response); |
| 4677 | ASSERT_TRUE(response->headers); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4678 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4679 | |
| 4680 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4681 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4682 | EXPECT_EQ("1234567890", response_data); |
| 4683 | } |
| 4684 | |
| 4685 | // Test a SPDY CONNECT through an HTTPS Proxy to a SPDY server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4686 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectSpdy) { |
| 4687 | SpdyTestUtil spdy_util_wrapped; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4688 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4689 | HttpRequestInfo request; |
| 4690 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4691 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4692 | request.load_flags = 0; |
| 4693 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4694 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4695 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4696 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4697 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4698 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4699 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4700 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4701 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4702 | // CONNECT to www.example.org:443 via SPDY |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4703 | SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4704 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 4705 | // fetch https://www.example.org/ via SPDY |
| 4706 | const char kMyUrl[] = "https://www.example.org/"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4707 | SpdySerializedFrame get( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4708 | spdy_util_wrapped.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4709 | SpdySerializedFrame wrapped_get(spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4710 | SpdySerializedFrame conn_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4711 | SpdySerializedFrame get_resp( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4712 | spdy_util_wrapped.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4713 | SpdySerializedFrame wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4714 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4715 | SpdySerializedFrame body(spdy_util_wrapped.ConstructSpdyDataFrame(1, true)); |
| 4716 | SpdySerializedFrame wrapped_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4717 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4718 | SpdySerializedFrame window_update_get_resp( |
| 4719 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
| 4720 | SpdySerializedFrame window_update_body( |
| 4721 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body.size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 4722 | |
| 4723 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4724 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_get, 2), |
| 4725 | CreateMockWrite(window_update_get_resp, 6), |
| 4726 | CreateMockWrite(window_update_body, 7), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 4727 | }; |
| 4728 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4729 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4730 | CreateMockRead(conn_resp, 1, ASYNC), |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4731 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4732 | CreateMockRead(wrapped_get_resp, 4, ASYNC), |
| 4733 | CreateMockRead(wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4734 | MockRead(ASYNC, 0, 8), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4735 | }; |
| 4736 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4737 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4738 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4739 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4740 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4741 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 4742 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4743 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4744 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 4745 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4746 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4747 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4748 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4749 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4750 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4751 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4752 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4753 | // Allow the SpdyProxyClientSocket's write callback to complete. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 4754 | base::RunLoop().RunUntilIdle(); |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4755 | // Now allow the read of the response to complete. |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 4756 | spdy_data.Resume(); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4757 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4758 | EXPECT_THAT(rv, IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4759 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4760 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4761 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4762 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4763 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4764 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4765 | ASSERT_TRUE(response); |
| 4766 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 4767 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4768 | |
| 4769 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4770 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 4771 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4772 | } |
| 4773 | |
| 4774 | // Test a SPDY CONNECT failure through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4775 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectFailure) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4776 | HttpRequestInfo request; |
| 4777 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4778 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4779 | request.load_flags = 0; |
| 4780 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4781 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4782 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4783 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4784 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4785 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4786 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4787 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4788 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4789 | // CONNECT to www.example.org:443 via SPDY |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4790 | SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4791 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4792 | SpdySerializedFrame get( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 4793 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4794 | |
| 4795 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4796 | CreateMockWrite(connect, 0), CreateMockWrite(get, 2), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4797 | }; |
| 4798 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4799 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError(1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4800 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4801 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4802 | CreateMockRead(resp, 1, ASYNC), MockRead(ASYNC, 0, 3), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4803 | }; |
| 4804 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4805 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4806 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4807 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4808 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4809 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 4810 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4811 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4812 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 4813 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4814 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4815 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4816 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4817 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4818 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4819 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4820 | |
| 4821 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4822 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4823 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 4824 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4825 | } |
| 4826 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4827 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 4828 | // HTTPS Proxy to different servers. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4829 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4830 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsTwoServers) { |
| 4831 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4832 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4833 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4834 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4835 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4836 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4837 | |
| 4838 | HttpRequestInfo request1; |
| 4839 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4840 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4841 | request1.load_flags = 0; |
| 4842 | |
| 4843 | HttpRequestInfo request2; |
| 4844 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4845 | request2.url = GURL("https://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4846 | request2.load_flags = 0; |
| 4847 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4848 | // CONNECT to www.example.org:443 via SPDY. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4849 | SpdySerializedFrame connect1(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4850 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4851 | SpdySerializedFrame conn_resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4852 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4853 | // Fetch https://www.example.org/ via HTTP. |
| 4854 | const char get1[] = |
| 4855 | "GET / HTTP/1.1\r\n" |
| 4856 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4857 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4858 | SpdySerializedFrame wrapped_get1( |
| 4859 | spdy_util_.ConstructSpdyDataFrame(1, get1, strlen(get1), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4860 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 4861 | "Content-Length: 1\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4862 | SpdySerializedFrame wrapped_get_resp1( |
| 4863 | spdy_util_.ConstructSpdyDataFrame(1, resp1, strlen(resp1), false)); |
| 4864 | SpdySerializedFrame wrapped_body1( |
| 4865 | spdy_util_.ConstructSpdyDataFrame(1, "1", 1, false)); |
| 4866 | SpdySerializedFrame window_update( |
| 4867 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1.size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4868 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4869 | // CONNECT to mail.example.org:443 via SPDY. |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 4870 | SpdyHeaderBlock connect2_block; |
| 4871 | connect2_block[spdy_util_.GetMethodKey()] = "CONNECT"; |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 4872 | connect2_block[spdy_util_.GetHostKey()] = "mail.example.org:443"; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4873 | SpdySerializedFrame connect2(spdy_util_.ConstructSpdyHeaders( |
| 4874 | 3, std::move(connect2_block), LOWEST, false)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 4875 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4876 | SpdySerializedFrame conn_resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4877 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4878 | // Fetch https://mail.example.org/ via HTTP. |
| 4879 | const char get2[] = |
| 4880 | "GET / HTTP/1.1\r\n" |
| 4881 | "Host: mail.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4882 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4883 | SpdySerializedFrame wrapped_get2( |
| 4884 | spdy_util_.ConstructSpdyDataFrame(3, get2, strlen(get2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4885 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 4886 | "Content-Length: 2\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4887 | SpdySerializedFrame wrapped_get_resp2( |
| 4888 | spdy_util_.ConstructSpdyDataFrame(3, resp2, strlen(resp2), false)); |
| 4889 | SpdySerializedFrame wrapped_body2( |
| 4890 | spdy_util_.ConstructSpdyDataFrame(3, "22", 2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4891 | |
| 4892 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4893 | CreateMockWrite(connect1, 0), CreateMockWrite(wrapped_get1, 2), |
| 4894 | CreateMockWrite(connect2, 5), CreateMockWrite(wrapped_get2, 7), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4895 | }; |
| 4896 | |
| 4897 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4898 | CreateMockRead(conn_resp1, 1, ASYNC), |
| 4899 | CreateMockRead(wrapped_get_resp1, 3, ASYNC), |
| 4900 | CreateMockRead(wrapped_body1, 4, ASYNC), |
| 4901 | CreateMockRead(conn_resp2, 6, ASYNC), |
| 4902 | CreateMockRead(wrapped_get_resp2, 8, ASYNC), |
| 4903 | CreateMockRead(wrapped_body2, 9, ASYNC), |
| 4904 | MockRead(ASYNC, 0, 10), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4905 | }; |
| 4906 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4907 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4908 | arraysize(spdy_writes)); |
| 4909 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4910 | |
| 4911 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 4912 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4913 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4914 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4915 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4916 | SSLSocketDataProvider ssl3(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4917 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4918 | |
| 4919 | TestCompletionCallback callback; |
| 4920 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4921 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 4922 | int rv = trans.Start(&request1, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4923 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4924 | |
| 4925 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4926 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4927 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4928 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4929 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4930 | ASSERT_TRUE(response); |
| 4931 | ASSERT_TRUE(response->headers); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4932 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4933 | |
| 4934 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 4935 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4936 | rv = trans.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4937 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4938 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4939 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 4940 | rv = trans2.Start(&request2, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4941 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4942 | |
| 4943 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4944 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4945 | // Even though the SPDY connection is reused, a new tunnelled connection has |
| 4946 | // to be created, so the socket's load timing looks like a fresh connection. |
| 4947 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4948 | |
| 4949 | // The requests should have different IDs, since they each are using their own |
| 4950 | // separate stream. |
| 4951 | EXPECT_NE(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 4952 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4953 | rv = trans2.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4954 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4955 | } |
| 4956 | |
| 4957 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 4958 | // HTTPS Proxy to the same server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4959 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4960 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsSameServer) { |
| 4961 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4962 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4963 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4964 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4965 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4966 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4967 | |
| 4968 | HttpRequestInfo request1; |
| 4969 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4970 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4971 | request1.load_flags = 0; |
| 4972 | |
| 4973 | HttpRequestInfo request2; |
| 4974 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4975 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4976 | request2.load_flags = 0; |
| 4977 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4978 | // CONNECT to www.example.org:443 via SPDY. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4979 | SpdySerializedFrame connect1(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4980 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4981 | SpdySerializedFrame conn_resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4982 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4983 | // Fetch https://www.example.org/ via HTTP. |
| 4984 | const char get1[] = |
| 4985 | "GET / HTTP/1.1\r\n" |
| 4986 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4987 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4988 | SpdySerializedFrame wrapped_get1( |
| 4989 | spdy_util_.ConstructSpdyDataFrame(1, get1, strlen(get1), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4990 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 4991 | "Content-Length: 1\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4992 | SpdySerializedFrame wrapped_get_resp1( |
| 4993 | spdy_util_.ConstructSpdyDataFrame(1, resp1, strlen(resp1), false)); |
| 4994 | SpdySerializedFrame wrapped_body1( |
| 4995 | spdy_util_.ConstructSpdyDataFrame(1, "1", 1, false)); |
| 4996 | SpdySerializedFrame window_update( |
| 4997 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1.size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4998 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4999 | // Fetch https://www.example.org/2 via HTTP. |
| 5000 | const char get2[] = |
| 5001 | "GET /2 HTTP/1.1\r\n" |
| 5002 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5003 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5004 | SpdySerializedFrame wrapped_get2( |
| 5005 | spdy_util_.ConstructSpdyDataFrame(1, get2, strlen(get2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5006 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 5007 | "Content-Length: 2\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5008 | SpdySerializedFrame wrapped_get_resp2( |
| 5009 | spdy_util_.ConstructSpdyDataFrame(1, resp2, strlen(resp2), false)); |
| 5010 | SpdySerializedFrame wrapped_body2( |
| 5011 | spdy_util_.ConstructSpdyDataFrame(1, "22", 2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5012 | |
| 5013 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5014 | CreateMockWrite(connect1, 0), CreateMockWrite(wrapped_get1, 2), |
| 5015 | CreateMockWrite(wrapped_get2, 5), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5016 | }; |
| 5017 | |
| 5018 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5019 | CreateMockRead(conn_resp1, 1, ASYNC), |
| 5020 | CreateMockRead(wrapped_get_resp1, 3, ASYNC), |
| 5021 | CreateMockRead(wrapped_body1, 4, ASYNC), |
| 5022 | CreateMockRead(wrapped_get_resp2, 6, ASYNC), |
| 5023 | CreateMockRead(wrapped_body2, 7, ASYNC), |
| 5024 | MockRead(ASYNC, 0, 8), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5025 | }; |
| 5026 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5027 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5028 | arraysize(spdy_writes)); |
| 5029 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5030 | |
| 5031 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5032 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5033 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5034 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5035 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5036 | |
| 5037 | TestCompletionCallback callback; |
| 5038 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5039 | std::unique_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5040 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5041 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5042 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5043 | |
| 5044 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5045 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5046 | |
| 5047 | LoadTimingInfo load_timing_info; |
| 5048 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 5049 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5050 | |
| 5051 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5052 | ASSERT_TRUE(response); |
| 5053 | ASSERT_TRUE(response->headers); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5054 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5055 | |
| 5056 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5057 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5058 | EXPECT_EQ(1, trans->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5059 | trans.reset(); |
| 5060 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5061 | std::unique_ptr<HttpNetworkTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5062 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5063 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5064 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5065 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5066 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5067 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5068 | |
| 5069 | LoadTimingInfo load_timing_info2; |
| 5070 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 5071 | TestLoadTimingReused(load_timing_info2); |
| 5072 | |
| 5073 | // The requests should have the same ID. |
| 5074 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 5075 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5076 | EXPECT_EQ(2, trans2->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5077 | } |
| 5078 | |
| 5079 | // Test load timing in the case of of two HTTP requests through a SPDY HTTPS |
| 5080 | // Proxy to different servers. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5081 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyLoadTimingTwoHttpRequests) { |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5082 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5083 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5084 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5085 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5086 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5087 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5088 | |
| 5089 | HttpRequestInfo request1; |
| 5090 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5091 | request1.url = GURL("http://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5092 | request1.load_flags = 0; |
| 5093 | |
| 5094 | HttpRequestInfo request2; |
| 5095 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5096 | request2.url = GURL("http://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5097 | request2.load_flags = 0; |
| 5098 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5099 | // http://www.example.org/ |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 5100 | SpdyHeaderBlock headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5101 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5102 | SpdySerializedFrame get1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5103 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
| 5104 | SpdySerializedFrame get_resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5105 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, "1", 1, true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5106 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5107 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5108 | // http://mail.example.org/ |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 5109 | SpdyHeaderBlock headers2( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5110 | spdy_util_.ConstructGetHeaderBlockForProxy("http://mail.example.org/")); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5111 | SpdySerializedFrame get2( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5112 | spdy_util_.ConstructSpdyHeaders(3, std::move(headers2), LOWEST, true)); |
| 5113 | SpdySerializedFrame get_resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5114 | SpdySerializedFrame body2( |
| 5115 | spdy_util_.ConstructSpdyDataFrame(3, "22", 2, true)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5116 | |
| 5117 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5118 | CreateMockWrite(get1, 0), CreateMockWrite(get2, 3), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5119 | }; |
| 5120 | |
| 5121 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5122 | CreateMockRead(get_resp1, 1, ASYNC), |
| 5123 | CreateMockRead(body1, 2, ASYNC), |
| 5124 | CreateMockRead(get_resp2, 4, ASYNC), |
| 5125 | CreateMockRead(body2, 5, ASYNC), |
| 5126 | MockRead(ASYNC, 0, 6), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5127 | }; |
| 5128 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5129 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5130 | arraysize(spdy_writes)); |
| 5131 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5132 | |
| 5133 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5134 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5135 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5136 | |
| 5137 | TestCompletionCallback callback; |
| 5138 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5139 | std::unique_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5140 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5141 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5142 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5143 | |
| 5144 | LoadTimingInfo load_timing_info; |
| 5145 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 5146 | TestLoadTimingNotReused(load_timing_info, |
| 5147 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5148 | |
| 5149 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5150 | ASSERT_TRUE(response); |
| 5151 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5152 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5153 | |
| 5154 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5155 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5156 | rv = trans->Read(buf.get(), 256, callback.callback()); |
| 5157 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5158 | // Delete the first request, so the second one can reuse the socket. |
| 5159 | trans.reset(); |
| 5160 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5161 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 5162 | rv = trans2.Start(&request2, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5163 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5164 | |
| 5165 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5166 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5167 | TestLoadTimingReused(load_timing_info2); |
| 5168 | |
| 5169 | // The requests should have the same ID. |
| 5170 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 5171 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5172 | rv = trans2.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5173 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5174 | } |
| 5175 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5176 | // Test the challenge-response-retry sequence through an HTTPS Proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5177 | TEST_F(HttpNetworkTransactionTest, HttpsProxyAuthRetry) { |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5178 | HttpRequestInfo request; |
| 5179 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5180 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5181 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5182 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5183 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5184 | // Configure against https proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5185 | session_deps_.proxy_service = ProxyService::CreateFixed("https://myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5186 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5187 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5188 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5189 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5190 | // Since we have proxy, should use full url |
| 5191 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5192 | MockWrite("GET http://www.example.org/ HTTP/1.1\r\n" |
| 5193 | "Host: www.example.org\r\n" |
| 5194 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5195 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5196 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5197 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5198 | MockWrite("GET http://www.example.org/ HTTP/1.1\r\n" |
| 5199 | "Host: www.example.org\r\n" |
| 5200 | "Proxy-Connection: keep-alive\r\n" |
| 5201 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5202 | }; |
| 5203 | |
| 5204 | // The proxy responds to the GET with a 407, using a persistent |
| 5205 | // connection. |
| 5206 | MockRead data_reads1[] = { |
| 5207 | // No credentials. |
| 5208 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 5209 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5210 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 5211 | MockRead("Content-Length: 0\r\n\r\n"), |
| 5212 | |
| 5213 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5214 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5215 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5216 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5217 | }; |
| 5218 | |
| 5219 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5220 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5221 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5222 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5223 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5224 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5225 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5226 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5227 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5228 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5229 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5230 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5231 | |
| 5232 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5233 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5234 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5235 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5236 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5237 | TestLoadTimingNotReused(load_timing_info, |
| 5238 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5239 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5240 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5241 | ASSERT_TRUE(response); |
| 5242 | ASSERT_TRUE(response->headers); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5243 | EXPECT_EQ(407, response->headers->response_code()); |
| 5244 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 5245 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5246 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5247 | TestCompletionCallback callback2; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5248 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5249 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5250 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5251 | |
| 5252 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5253 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5254 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5255 | load_timing_info = LoadTimingInfo(); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5256 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5257 | // Retrying with HTTP AUTH is considered to be reusing a socket. |
| 5258 | TestLoadTimingReused(load_timing_info); |
| 5259 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5260 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5261 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5262 | |
| 5263 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 5264 | EXPECT_EQ(200, response->headers->response_code()); |
| 5265 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5266 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 5267 | |
| 5268 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5269 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5270 | } |
| 5271 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5272 | void HttpNetworkTransactionTest::ConnectStatusHelperWithExpectedStatus( |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5273 | const MockRead& status, int expected_status) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5274 | HttpRequestInfo request; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5275 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5276 | request.url = GURL("https://www.example.org/"); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5277 | request.load_flags = 0; |
| 5278 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5279 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5280 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5281 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5282 | |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5283 | // Since we have proxy, should try to establish tunnel. |
| 5284 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5285 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5286 | "Host: www.example.org:443\r\n" |
| 5287 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5288 | }; |
| 5289 | |
| 5290 | MockRead data_reads[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 5291 | status, MockRead("Content-Length: 10\r\n\r\n"), |
| 5292 | // No response body because the test stops reading here. |
| 5293 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5294 | }; |
| 5295 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5296 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 5297 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5298 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5299 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5300 | TestCompletionCallback callback; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5301 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5302 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5303 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5304 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5305 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5306 | |
| 5307 | rv = callback.WaitForResult(); |
| 5308 | EXPECT_EQ(expected_status, rv); |
| 5309 | } |
| 5310 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5311 | void HttpNetworkTransactionTest::ConnectStatusHelper( |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5312 | const MockRead& status) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5313 | ConnectStatusHelperWithExpectedStatus( |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5314 | status, ERR_TUNNEL_CONNECTION_FAILED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5315 | } |
| 5316 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5317 | TEST_F(HttpNetworkTransactionTest, ConnectStatus100) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5318 | ConnectStatusHelper(MockRead("HTTP/1.1 100 Continue\r\n")); |
| 5319 | } |
| 5320 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5321 | TEST_F(HttpNetworkTransactionTest, ConnectStatus101) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5322 | ConnectStatusHelper(MockRead("HTTP/1.1 101 Switching Protocols\r\n")); |
| 5323 | } |
| 5324 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5325 | TEST_F(HttpNetworkTransactionTest, ConnectStatus201) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5326 | ConnectStatusHelper(MockRead("HTTP/1.1 201 Created\r\n")); |
| 5327 | } |
| 5328 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5329 | TEST_F(HttpNetworkTransactionTest, ConnectStatus202) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5330 | ConnectStatusHelper(MockRead("HTTP/1.1 202 Accepted\r\n")); |
| 5331 | } |
| 5332 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5333 | TEST_F(HttpNetworkTransactionTest, ConnectStatus203) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5334 | ConnectStatusHelper( |
| 5335 | MockRead("HTTP/1.1 203 Non-Authoritative Information\r\n")); |
| 5336 | } |
| 5337 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5338 | TEST_F(HttpNetworkTransactionTest, ConnectStatus204) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5339 | ConnectStatusHelper(MockRead("HTTP/1.1 204 No Content\r\n")); |
| 5340 | } |
| 5341 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5342 | TEST_F(HttpNetworkTransactionTest, ConnectStatus205) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5343 | ConnectStatusHelper(MockRead("HTTP/1.1 205 Reset Content\r\n")); |
| 5344 | } |
| 5345 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5346 | TEST_F(HttpNetworkTransactionTest, ConnectStatus206) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5347 | ConnectStatusHelper(MockRead("HTTP/1.1 206 Partial Content\r\n")); |
| 5348 | } |
| 5349 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5350 | TEST_F(HttpNetworkTransactionTest, ConnectStatus300) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5351 | ConnectStatusHelper(MockRead("HTTP/1.1 300 Multiple Choices\r\n")); |
| 5352 | } |
| 5353 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5354 | TEST_F(HttpNetworkTransactionTest, ConnectStatus301) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5355 | ConnectStatusHelper(MockRead("HTTP/1.1 301 Moved Permanently\r\n")); |
| 5356 | } |
| 5357 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5358 | TEST_F(HttpNetworkTransactionTest, ConnectStatus302) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5359 | ConnectStatusHelper(MockRead("HTTP/1.1 302 Found\r\n")); |
| 5360 | } |
| 5361 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5362 | TEST_F(HttpNetworkTransactionTest, ConnectStatus303) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5363 | ConnectStatusHelper(MockRead("HTTP/1.1 303 See Other\r\n")); |
| 5364 | } |
| 5365 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5366 | TEST_F(HttpNetworkTransactionTest, ConnectStatus304) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5367 | ConnectStatusHelper(MockRead("HTTP/1.1 304 Not Modified\r\n")); |
| 5368 | } |
| 5369 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5370 | TEST_F(HttpNetworkTransactionTest, ConnectStatus305) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5371 | ConnectStatusHelper(MockRead("HTTP/1.1 305 Use Proxy\r\n")); |
| 5372 | } |
| 5373 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5374 | TEST_F(HttpNetworkTransactionTest, ConnectStatus306) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5375 | ConnectStatusHelper(MockRead("HTTP/1.1 306\r\n")); |
| 5376 | } |
| 5377 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5378 | TEST_F(HttpNetworkTransactionTest, ConnectStatus307) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5379 | ConnectStatusHelper(MockRead("HTTP/1.1 307 Temporary Redirect\r\n")); |
| 5380 | } |
| 5381 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5382 | TEST_F(HttpNetworkTransactionTest, ConnectStatus308) { |
[email protected] | 0a17aab3 | 2014-04-24 03:32:37 | [diff] [blame] | 5383 | ConnectStatusHelper(MockRead("HTTP/1.1 308 Permanent Redirect\r\n")); |
| 5384 | } |
| 5385 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5386 | TEST_F(HttpNetworkTransactionTest, ConnectStatus400) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5387 | ConnectStatusHelper(MockRead("HTTP/1.1 400 Bad Request\r\n")); |
| 5388 | } |
| 5389 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5390 | TEST_F(HttpNetworkTransactionTest, ConnectStatus401) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5391 | ConnectStatusHelper(MockRead("HTTP/1.1 401 Unauthorized\r\n")); |
| 5392 | } |
| 5393 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5394 | TEST_F(HttpNetworkTransactionTest, ConnectStatus402) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5395 | ConnectStatusHelper(MockRead("HTTP/1.1 402 Payment Required\r\n")); |
| 5396 | } |
| 5397 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5398 | TEST_F(HttpNetworkTransactionTest, ConnectStatus403) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5399 | ConnectStatusHelper(MockRead("HTTP/1.1 403 Forbidden\r\n")); |
| 5400 | } |
| 5401 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5402 | TEST_F(HttpNetworkTransactionTest, ConnectStatus404) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5403 | ConnectStatusHelper(MockRead("HTTP/1.1 404 Not Found\r\n")); |
| 5404 | } |
| 5405 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5406 | TEST_F(HttpNetworkTransactionTest, ConnectStatus405) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5407 | ConnectStatusHelper(MockRead("HTTP/1.1 405 Method Not Allowed\r\n")); |
| 5408 | } |
| 5409 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5410 | TEST_F(HttpNetworkTransactionTest, ConnectStatus406) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5411 | ConnectStatusHelper(MockRead("HTTP/1.1 406 Not Acceptable\r\n")); |
| 5412 | } |
| 5413 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5414 | TEST_F(HttpNetworkTransactionTest, ConnectStatus407) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5415 | ConnectStatusHelperWithExpectedStatus( |
| 5416 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
[email protected] | a7ea883 | 2010-07-12 17:54:54 | [diff] [blame] | 5417 | ERR_PROXY_AUTH_UNSUPPORTED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5418 | } |
| 5419 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5420 | TEST_F(HttpNetworkTransactionTest, ConnectStatus408) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5421 | ConnectStatusHelper(MockRead("HTTP/1.1 408 Request Timeout\r\n")); |
| 5422 | } |
| 5423 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5424 | TEST_F(HttpNetworkTransactionTest, ConnectStatus409) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5425 | ConnectStatusHelper(MockRead("HTTP/1.1 409 Conflict\r\n")); |
| 5426 | } |
| 5427 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5428 | TEST_F(HttpNetworkTransactionTest, ConnectStatus410) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5429 | ConnectStatusHelper(MockRead("HTTP/1.1 410 Gone\r\n")); |
| 5430 | } |
| 5431 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5432 | TEST_F(HttpNetworkTransactionTest, ConnectStatus411) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5433 | ConnectStatusHelper(MockRead("HTTP/1.1 411 Length Required\r\n")); |
| 5434 | } |
| 5435 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5436 | TEST_F(HttpNetworkTransactionTest, ConnectStatus412) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5437 | ConnectStatusHelper(MockRead("HTTP/1.1 412 Precondition Failed\r\n")); |
| 5438 | } |
| 5439 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5440 | TEST_F(HttpNetworkTransactionTest, ConnectStatus413) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5441 | ConnectStatusHelper(MockRead("HTTP/1.1 413 Request Entity Too Large\r\n")); |
| 5442 | } |
| 5443 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5444 | TEST_F(HttpNetworkTransactionTest, ConnectStatus414) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5445 | ConnectStatusHelper(MockRead("HTTP/1.1 414 Request-URI Too Long\r\n")); |
| 5446 | } |
| 5447 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5448 | TEST_F(HttpNetworkTransactionTest, ConnectStatus415) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5449 | ConnectStatusHelper(MockRead("HTTP/1.1 415 Unsupported Media Type\r\n")); |
| 5450 | } |
| 5451 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5452 | TEST_F(HttpNetworkTransactionTest, ConnectStatus416) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5453 | ConnectStatusHelper( |
| 5454 | MockRead("HTTP/1.1 416 Requested Range Not Satisfiable\r\n")); |
| 5455 | } |
| 5456 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5457 | TEST_F(HttpNetworkTransactionTest, ConnectStatus417) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5458 | ConnectStatusHelper(MockRead("HTTP/1.1 417 Expectation Failed\r\n")); |
| 5459 | } |
| 5460 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5461 | TEST_F(HttpNetworkTransactionTest, ConnectStatus500) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5462 | ConnectStatusHelper(MockRead("HTTP/1.1 500 Internal Server Error\r\n")); |
| 5463 | } |
| 5464 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5465 | TEST_F(HttpNetworkTransactionTest, ConnectStatus501) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5466 | ConnectStatusHelper(MockRead("HTTP/1.1 501 Not Implemented\r\n")); |
| 5467 | } |
| 5468 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5469 | TEST_F(HttpNetworkTransactionTest, ConnectStatus502) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5470 | ConnectStatusHelper(MockRead("HTTP/1.1 502 Bad Gateway\r\n")); |
| 5471 | } |
| 5472 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5473 | TEST_F(HttpNetworkTransactionTest, ConnectStatus503) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5474 | ConnectStatusHelper(MockRead("HTTP/1.1 503 Service Unavailable\r\n")); |
| 5475 | } |
| 5476 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5477 | TEST_F(HttpNetworkTransactionTest, ConnectStatus504) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5478 | ConnectStatusHelper(MockRead("HTTP/1.1 504 Gateway Timeout\r\n")); |
| 5479 | } |
| 5480 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5481 | TEST_F(HttpNetworkTransactionTest, ConnectStatus505) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5482 | ConnectStatusHelper(MockRead("HTTP/1.1 505 HTTP Version Not Supported\r\n")); |
| 5483 | } |
| 5484 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5485 | // Test the flow when both the proxy server AND origin server require |
| 5486 | // authentication. Again, this uses basic auth for both since that is |
| 5487 | // the simplest to mock. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5488 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyThenServer) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5489 | HttpRequestInfo request; |
| 5490 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5491 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5492 | request.load_flags = 0; |
| 5493 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5494 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5495 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5496 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 5497 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5498 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5499 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5500 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5501 | MockWrite( |
| 5502 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5503 | "Host: www.example.org\r\n" |
| 5504 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5505 | }; |
| 5506 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5507 | MockRead data_reads1[] = { |
| 5508 | MockRead("HTTP/1.0 407 Unauthorized\r\n"), |
| 5509 | // Give a couple authenticate options (only the middle one is actually |
| 5510 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 5511 | MockRead("Proxy-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5512 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5513 | MockRead("Proxy-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 5514 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5515 | // Large content-length -- won't matter, as connection will be reset. |
| 5516 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5517 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5518 | }; |
| 5519 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5520 | // After calling trans.RestartWithAuth() the first time, this is the |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5521 | // request we should be issuing -- the final header line contains the |
| 5522 | // proxy's credentials. |
| 5523 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5524 | MockWrite( |
| 5525 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5526 | "Host: www.example.org\r\n" |
| 5527 | "Proxy-Connection: keep-alive\r\n" |
| 5528 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5529 | }; |
| 5530 | |
| 5531 | // Now the proxy server lets the request pass through to origin server. |
| 5532 | // The origin server responds with a 401. |
| 5533 | MockRead data_reads2[] = { |
| 5534 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5535 | // Note: We are using the same realm-name as the proxy server. This is |
| 5536 | // completely valid, as realms are unique across hosts. |
| 5537 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5538 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5539 | MockRead("Content-Length: 2000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5540 | MockRead(SYNCHRONOUS, ERR_FAILED), // Won't be reached. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5541 | }; |
| 5542 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5543 | // After calling trans.RestartWithAuth() the second time, we should send |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5544 | // the credentials for both the proxy and origin server. |
| 5545 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5546 | MockWrite( |
| 5547 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5548 | "Host: www.example.org\r\n" |
| 5549 | "Proxy-Connection: keep-alive\r\n" |
| 5550 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n" |
| 5551 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5552 | }; |
| 5553 | |
| 5554 | // Lastly we get the desired content. |
| 5555 | MockRead data_reads3[] = { |
| 5556 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5557 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5558 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5559 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5560 | }; |
| 5561 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5562 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5563 | data_writes1, arraysize(data_writes1)); |
| 5564 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5565 | data_writes2, arraysize(data_writes2)); |
| 5566 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 5567 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5568 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5569 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 5570 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5571 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5572 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5573 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5574 | int rv = trans.Start(&request, callback1.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5575 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5576 | |
| 5577 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5578 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5579 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5580 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5581 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5582 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5583 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5584 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5585 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5586 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5587 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5588 | |
| 5589 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5590 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5591 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5592 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5593 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5594 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5595 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5596 | TestCompletionCallback callback3; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5597 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5598 | rv = trans.RestartWithAuth(AuthCredentials(kFoo2, kBar2), |
| 5599 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5600 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5601 | |
| 5602 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5603 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5604 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5605 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5606 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5607 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5608 | } |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5609 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 5610 | // For the NTLM implementation using SSPI, we skip the NTLM tests since we |
| 5611 | // can't hook into its internals to cause it to generate predictable NTLM |
| 5612 | // authorization headers. |
| 5613 | #if defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5614 | // The NTLM authentication unit tests were generated by capturing the HTTP |
| 5615 | // requests and responses using Fiddler 2 and inspecting the generated random |
| 5616 | // bytes in the debugger. |
| 5617 | |
| 5618 | // Enter the correct password and authenticate successfully. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5619 | TEST_F(HttpNetworkTransactionTest, NTLMAuth1) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5620 | HttpRequestInfo request; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5621 | request.method = "GET"; |
| 5622 | request.url = GURL("http://172.22.68.17/kids/login.aspx"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 5623 | |
| 5624 | // Ensure load is not disrupted by flags which suppress behaviour specific |
| 5625 | // to other auth schemes. |
| 5626 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5627 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5628 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom1, |
| 5629 | MockGetHostName); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5630 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5631 | |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5632 | MockWrite data_writes1[] = { |
| 5633 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5634 | "Host: 172.22.68.17\r\n" |
| 5635 | "Connection: keep-alive\r\n\r\n"), |
| 5636 | }; |
| 5637 | |
| 5638 | MockRead data_reads1[] = { |
| 5639 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 5640 | // Negotiate and NTLM are often requested together. However, we only want |
| 5641 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 5642 | // the header that requests Negotiate for this test. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5643 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 5644 | MockRead("Connection: close\r\n"), |
| 5645 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 5646 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5647 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5648 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5649 | }; |
| 5650 | |
| 5651 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5652 | // After restarting with a null identity, this is the |
| 5653 | // request we should be issuing -- the final header line contains a Type |
| 5654 | // 1 message. |
| 5655 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5656 | "Host: 172.22.68.17\r\n" |
| 5657 | "Connection: keep-alive\r\n" |
| 5658 | "Authorization: NTLM " |
| 5659 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5660 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5661 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 5662 | // (the credentials for the origin server). The second request continues |
| 5663 | // on the same connection. |
| 5664 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5665 | "Host: 172.22.68.17\r\n" |
| 5666 | "Connection: keep-alive\r\n" |
| 5667 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 5668 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 5669 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwBVKW" |
| 5670 | "Yma5xzVAAAAAAAAAAAAAAAAAAAAACH+gWcm+YsP9Tqb9zCR3WAeZZX" |
| 5671 | "ahlhx5I=\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5672 | }; |
| 5673 | |
| 5674 | MockRead data_reads2[] = { |
| 5675 | // The origin server responds with a Type 2 message. |
| 5676 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 5677 | MockRead("WWW-Authenticate: NTLM " |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5678 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCjGpMpPGlYKkAAAAAAAAAALo" |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5679 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 5680 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 5681 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 5682 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 5683 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 5684 | "BtAAAAAAA=\r\n"), |
| 5685 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 5686 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5687 | MockRead("You are not authorized to view this page\r\n"), |
| 5688 | |
| 5689 | // Lastly we get the desired content. |
| 5690 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5691 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 5692 | MockRead("Content-Length: 13\r\n\r\n"), |
| 5693 | MockRead("Please Login\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5694 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5695 | }; |
| 5696 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5697 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5698 | data_writes1, arraysize(data_writes1)); |
| 5699 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5700 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5701 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5702 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5703 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5704 | TestCompletionCallback callback1; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5705 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5706 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5707 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5708 | int rv = trans.Start(&request, callback1.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5709 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5710 | |
| 5711 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5712 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5713 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5714 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5715 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5716 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5717 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5718 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5719 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5720 | TestCompletionCallback callback2; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5721 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5722 | rv = trans.RestartWithAuth(AuthCredentials(kTestingNTLM, kTestingNTLM), |
| 5723 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5724 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5725 | |
| 5726 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5727 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5728 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5729 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5730 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5731 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5732 | ASSERT_TRUE(response); |
| 5733 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5734 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5735 | TestCompletionCallback callback3; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5736 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5737 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5738 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5739 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5740 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5741 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5742 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5743 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5744 | ASSERT_TRUE(response); |
| 5745 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5746 | EXPECT_EQ(13, response->headers->GetContentLength()); |
| 5747 | } |
| 5748 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5749 | // Enter a wrong password, and then the correct one. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5750 | TEST_F(HttpNetworkTransactionTest, NTLMAuth2) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5751 | HttpRequestInfo request; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5752 | request.method = "GET"; |
| 5753 | request.url = GURL("http://172.22.68.17/kids/login.aspx"); |
| 5754 | request.load_flags = 0; |
| 5755 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5756 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom2, |
| 5757 | MockGetHostName); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5758 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5759 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5760 | MockWrite data_writes1[] = { |
| 5761 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5762 | "Host: 172.22.68.17\r\n" |
| 5763 | "Connection: keep-alive\r\n\r\n"), |
| 5764 | }; |
| 5765 | |
| 5766 | MockRead data_reads1[] = { |
| 5767 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 5768 | // Negotiate and NTLM are often requested together. However, we only want |
| 5769 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 5770 | // the header that requests Negotiate for this test. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5771 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 5772 | MockRead("Connection: close\r\n"), |
| 5773 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 5774 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5775 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5776 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5777 | }; |
| 5778 | |
| 5779 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5780 | // After restarting with a null identity, this is the |
| 5781 | // request we should be issuing -- the final header line contains a Type |
| 5782 | // 1 message. |
| 5783 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5784 | "Host: 172.22.68.17\r\n" |
| 5785 | "Connection: keep-alive\r\n" |
| 5786 | "Authorization: NTLM " |
| 5787 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5788 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5789 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 5790 | // (the credentials for the origin server). The second request continues |
| 5791 | // on the same connection. |
| 5792 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5793 | "Host: 172.22.68.17\r\n" |
| 5794 | "Connection: keep-alive\r\n" |
| 5795 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 5796 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 5797 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwCWeY" |
| 5798 | "XnSZNwoQAAAAAAAAAAAAAAAAAAAADLa34/phTTKzNTWdub+uyFleOj" |
| 5799 | "4Ww7b7E=\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5800 | }; |
| 5801 | |
| 5802 | MockRead data_reads2[] = { |
| 5803 | // The origin server responds with a Type 2 message. |
| 5804 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 5805 | MockRead("WWW-Authenticate: NTLM " |
| 5806 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCbVWUZezVGpAAAAAAAAAAALo" |
| 5807 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 5808 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 5809 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 5810 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 5811 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 5812 | "BtAAAAAAA=\r\n"), |
| 5813 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 5814 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5815 | MockRead("You are not authorized to view this page\r\n"), |
| 5816 | |
| 5817 | // Wrong password. |
| 5818 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5819 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 5820 | MockRead("Connection: close\r\n"), |
| 5821 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 5822 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5823 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5824 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5825 | }; |
| 5826 | |
| 5827 | MockWrite data_writes3[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5828 | // After restarting with a null identity, this is the |
| 5829 | // request we should be issuing -- the final header line contains a Type |
| 5830 | // 1 message. |
| 5831 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5832 | "Host: 172.22.68.17\r\n" |
| 5833 | "Connection: keep-alive\r\n" |
| 5834 | "Authorization: NTLM " |
| 5835 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5836 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5837 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 5838 | // (the credentials for the origin server). The second request continues |
| 5839 | // on the same connection. |
| 5840 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5841 | "Host: 172.22.68.17\r\n" |
| 5842 | "Connection: keep-alive\r\n" |
| 5843 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 5844 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 5845 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwBO54" |
| 5846 | "dFMVvTHwAAAAAAAAAAAAAAAAAAAACS7sT6Uzw7L0L//WUqlIaVWpbI" |
| 5847 | "+4MUm7c=\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5848 | }; |
| 5849 | |
| 5850 | MockRead data_reads3[] = { |
| 5851 | // The origin server responds with a Type 2 message. |
| 5852 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 5853 | MockRead("WWW-Authenticate: NTLM " |
| 5854 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCL24VN8dgOR8AAAAAAAAAALo" |
| 5855 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 5856 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 5857 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 5858 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 5859 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 5860 | "BtAAAAAAA=\r\n"), |
| 5861 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 5862 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5863 | MockRead("You are not authorized to view this page\r\n"), |
| 5864 | |
| 5865 | // Lastly we get the desired content. |
| 5866 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5867 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 5868 | MockRead("Content-Length: 13\r\n\r\n"), |
| 5869 | MockRead("Please Login\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5870 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5871 | }; |
| 5872 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5873 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5874 | data_writes1, arraysize(data_writes1)); |
| 5875 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5876 | data_writes2, arraysize(data_writes2)); |
| 5877 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 5878 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5879 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5880 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 5881 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5882 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5883 | TestCompletionCallback callback1; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5884 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5885 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5886 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5887 | int rv = trans.Start(&request, callback1.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5888 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5889 | |
| 5890 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5891 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5892 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5893 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5894 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5895 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5896 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5897 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5898 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5899 | TestCompletionCallback callback2; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5900 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5901 | // Enter the wrong password. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5902 | rv = trans.RestartWithAuth(AuthCredentials(kTestingNTLM, kWrongPassword), |
| 5903 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5904 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5905 | |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5906 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5907 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5908 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5909 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5910 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5911 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5912 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5913 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5914 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5915 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5916 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5917 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5918 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5919 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5920 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5921 | TestCompletionCallback callback4; |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5922 | |
| 5923 | // Now enter the right password. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5924 | rv = trans.RestartWithAuth(AuthCredentials(kTestingNTLM, kTestingNTLM), |
| 5925 | callback4.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5926 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5927 | |
| 5928 | rv = callback4.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5929 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5930 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5931 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5932 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5933 | TestCompletionCallback callback5; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5934 | |
| 5935 | // One more roundtrip |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5936 | rv = trans.RestartWithAuth(AuthCredentials(), callback5.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5937 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5938 | |
| 5939 | rv = callback5.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5940 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5941 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5942 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5943 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5944 | EXPECT_EQ(13, response->headers->GetContentLength()); |
| 5945 | } |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 5946 | #endif // NTLM_PORTABLE |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5947 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5948 | // Test reading a server response which has only headers, and no body. |
| 5949 | // After some maximum number of bytes is consumed, the transaction should |
| 5950 | // fail with ERR_RESPONSE_HEADERS_TOO_BIG. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5951 | TEST_F(HttpNetworkTransactionTest, LargeHeadersNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5952 | HttpRequestInfo request; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5953 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5954 | request.url = GURL("http://www.example.org/"); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5955 | request.load_flags = 0; |
| 5956 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5957 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5958 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5959 | |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 5960 | // Respond with 300 kb of headers (we should fail after 256 kb). |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 5961 | std::string large_headers_string; |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 5962 | FillLargeHeadersString(&large_headers_string, 300 * 1024); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5963 | |
| 5964 | MockRead data_reads[] = { |
| 5965 | MockRead("HTTP/1.0 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5966 | MockRead(ASYNC, large_headers_string.data(), large_headers_string.size()), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5967 | MockRead("\r\nBODY"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5968 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5969 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5970 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5971 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5972 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5973 | TestCompletionCallback callback; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5974 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5975 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5976 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5977 | |
| 5978 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5979 | EXPECT_THAT(rv, IsError(ERR_RESPONSE_HEADERS_TOO_BIG)); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5980 | } |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5981 | |
| 5982 | // Make sure that we don't try to reuse a TCPClientSocket when failing to |
| 5983 | // establish tunnel. |
| 5984 | // http://code.google.com/p/chromium/issues/detail?id=3772 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5985 | TEST_F(HttpNetworkTransactionTest, DontRecycleTransportSocketForSSLTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5986 | HttpRequestInfo request; |
| 5987 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5988 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5989 | request.load_flags = 0; |
| 5990 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5991 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5992 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | db8f44c | 2008-12-13 04:52:01 | [diff] [blame] | 5993 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5994 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5995 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5996 | std::unique_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5997 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5998 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5999 | // Since we have proxy, should try to establish tunnel. |
| 6000 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 6001 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 6002 | "Host: www.example.org:443\r\n" |
| 6003 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6004 | }; |
| 6005 | |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 6006 | // The proxy responds to the connect with a 404, using a persistent |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6007 | // connection. Usually a proxy would return 501 (not implemented), |
| 6008 | // or 200 (tunnel established). |
| 6009 | MockRead data_reads1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 6010 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 6011 | MockRead("Content-Length: 10\r\n\r\n"), |
| 6012 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6013 | }; |
| 6014 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6015 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6016 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6017 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6018 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6019 | TestCompletionCallback callback1; |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6020 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6021 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6022 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6023 | |
| 6024 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6025 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6026 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6027 | // Empty the current queue. This is necessary because idle sockets are |
| 6028 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6029 | base::RunLoop().RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6030 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6031 | // We now check to make sure the TCPClientSocket was not added back to |
| 6032 | // the pool. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6033 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6034 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6035 | base::RunLoop().RunUntilIdle(); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6036 | // Make sure that the socket didn't get recycled after calling the destructor. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6037 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6038 | } |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6039 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6040 | // Make sure that we recycle a socket after reading all of the response body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6041 | TEST_F(HttpNetworkTransactionTest, RecycleSocket) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6042 | HttpRequestInfo request; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6043 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6044 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6045 | request.load_flags = 0; |
| 6046 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6047 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6048 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6049 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6050 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6051 | MockRead data_reads[] = { |
| 6052 | // A part of the response body is received with the response headers. |
| 6053 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 6054 | // The rest of the response body is received in two parts. |
| 6055 | MockRead("lo"), |
| 6056 | MockRead(" world"), |
| 6057 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6058 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6059 | }; |
| 6060 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6061 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6062 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6063 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6064 | TestCompletionCallback callback; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6065 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6066 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6067 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6068 | |
| 6069 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6070 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6071 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6072 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6073 | ASSERT_TRUE(response); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6074 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6075 | EXPECT_TRUE(response->headers); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6076 | std::string status_line = response->headers->GetStatusLine(); |
| 6077 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 6078 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6079 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6080 | |
| 6081 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6082 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6083 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6084 | EXPECT_EQ("hello world", response_data); |
| 6085 | |
| 6086 | // Empty the current queue. This is necessary because idle sockets are |
| 6087 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6088 | base::RunLoop().RunUntilIdle(); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6089 | |
| 6090 | // 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] | 6091 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6092 | } |
| 6093 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6094 | // Make sure that we recycle a SSL socket after reading all of the response |
| 6095 | // body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6096 | TEST_F(HttpNetworkTransactionTest, RecycleSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6097 | HttpRequestInfo request; |
| 6098 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6099 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6100 | request.load_flags = 0; |
| 6101 | |
| 6102 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6103 | MockWrite( |
| 6104 | "GET / HTTP/1.1\r\n" |
| 6105 | "Host: www.example.org\r\n" |
| 6106 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6107 | }; |
| 6108 | |
| 6109 | MockRead data_reads[] = { |
| 6110 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6111 | MockRead("Content-Length: 11\r\n\r\n"), |
| 6112 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6113 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6114 | }; |
| 6115 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6116 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6117 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6118 | |
| 6119 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6120 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6121 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6122 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6123 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6124 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6125 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6126 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6127 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6128 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6129 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6130 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6131 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6132 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6133 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6134 | ASSERT_TRUE(response); |
| 6135 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6136 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6137 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6138 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6139 | |
| 6140 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6141 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6142 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6143 | EXPECT_EQ("hello world", response_data); |
| 6144 | |
| 6145 | // Empty the current queue. This is necessary because idle sockets are |
| 6146 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6147 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6148 | |
| 6149 | // 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] | 6150 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6151 | } |
| 6152 | |
| 6153 | // Grab a SSL socket, use it, and put it back into the pool. Then, reuse it |
| 6154 | // from the pool and make sure that we recover okay. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6155 | TEST_F(HttpNetworkTransactionTest, RecycleDeadSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6156 | HttpRequestInfo request; |
| 6157 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6158 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6159 | request.load_flags = 0; |
| 6160 | |
| 6161 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6162 | MockWrite( |
| 6163 | "GET / HTTP/1.1\r\n" |
| 6164 | "Host: www.example.org\r\n" |
| 6165 | "Connection: keep-alive\r\n\r\n"), |
| 6166 | MockWrite( |
| 6167 | "GET / HTTP/1.1\r\n" |
| 6168 | "Host: www.example.org\r\n" |
| 6169 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6170 | }; |
| 6171 | |
| 6172 | MockRead data_reads[] = { |
mmenke | 911ee022 | 2015-12-04 03:58:42 | [diff] [blame] | 6173 | MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
| 6174 | MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6175 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6176 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 6177 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6178 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 6179 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6180 | |
| 6181 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6182 | data_writes, arraysize(data_writes)); |
| 6183 | StaticSocketDataProvider data2(data_reads, arraysize(data_reads), |
| 6184 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6185 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6186 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6187 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6188 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [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 | std::unique_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6192 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6193 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6194 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6195 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6196 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6197 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6198 | |
| 6199 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6200 | ASSERT_TRUE(response); |
| 6201 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6202 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6203 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6204 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6205 | |
| 6206 | std::string response_data; |
| 6207 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6208 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6209 | EXPECT_EQ("hello world", response_data); |
| 6210 | |
| 6211 | // Empty the current queue. This is necessary because idle sockets are |
| 6212 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6213 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6214 | |
| 6215 | // 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] | 6216 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6217 | |
| 6218 | // Now start the second transaction, which should reuse the previous socket. |
| 6219 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6220 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6221 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6222 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6223 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6224 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6225 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6226 | |
| 6227 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6228 | ASSERT_TRUE(response); |
| 6229 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6230 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6231 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6232 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6233 | |
| 6234 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6235 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6236 | EXPECT_EQ("hello world", response_data); |
| 6237 | |
| 6238 | // Empty the current queue. This is necessary because idle sockets are |
| 6239 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6240 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6241 | |
| 6242 | // 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] | 6243 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6244 | } |
| 6245 | |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6246 | // Grab a socket, use it, and put it back into the pool. Then, make |
| 6247 | // low memory notification and ensure the socket pool is flushed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6248 | TEST_F(HttpNetworkTransactionTest, FlushSocketPoolOnLowMemoryNotifications) { |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6249 | HttpRequestInfo request; |
| 6250 | request.method = "GET"; |
| 6251 | request.url = GURL("http://www.example.org/"); |
| 6252 | request.load_flags = 0; |
| 6253 | |
| 6254 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 6255 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6256 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6257 | |
| 6258 | MockRead data_reads[] = { |
| 6259 | // A part of the response body is received with the response headers. |
| 6260 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 6261 | // The rest of the response body is received in two parts. |
| 6262 | MockRead("lo"), MockRead(" world"), |
| 6263 | MockRead("junk"), // Should not be read!! |
| 6264 | MockRead(SYNCHRONOUS, OK), |
| 6265 | }; |
| 6266 | |
| 6267 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 6268 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6269 | |
| 6270 | TestCompletionCallback callback; |
| 6271 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6272 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6273 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6274 | |
| 6275 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 6276 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6277 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6278 | ASSERT_TRUE(response); |
| 6279 | EXPECT_TRUE(response->headers); |
| 6280 | std::string status_line = response->headers->GetStatusLine(); |
| 6281 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 6282 | |
| 6283 | // Make memory critical notification and ensure the transaction still has been |
| 6284 | // operating right. |
| 6285 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 6286 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 6287 | base::RunLoop().RunUntilIdle(); |
| 6288 | |
| 6289 | // Socket should not be flushed as long as it is not idle. |
| 6290 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 6291 | |
| 6292 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6293 | rv = ReadTransaction(&trans, &response_data); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6294 | EXPECT_THAT(rv, IsOk()); |
| 6295 | EXPECT_EQ("hello world", response_data); |
| 6296 | |
| 6297 | // Empty the current queue. This is necessary because idle sockets are |
| 6298 | // added to the connection pool asynchronously with a PostTask. |
| 6299 | base::RunLoop().RunUntilIdle(); |
| 6300 | |
| 6301 | // We now check to make sure the socket was added back to the pool. |
| 6302 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 6303 | |
| 6304 | // Idle sockets should be flushed now. |
| 6305 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 6306 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 6307 | base::RunLoop().RunUntilIdle(); |
| 6308 | |
| 6309 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 6310 | } |
| 6311 | |
| 6312 | // Grab an SSL socket, use it, and put it back into the pool. Then, make |
| 6313 | // low memory notification and ensure the socket pool is flushed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6314 | TEST_F(HttpNetworkTransactionTest, FlushSSLSocketPoolOnLowMemoryNotifications) { |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6315 | HttpRequestInfo request; |
| 6316 | request.method = "GET"; |
| 6317 | request.url = GURL("https://www.example.org/"); |
| 6318 | request.load_flags = 0; |
| 6319 | |
| 6320 | MockWrite data_writes[] = { |
| 6321 | MockWrite("GET / HTTP/1.1\r\n" |
| 6322 | "Host: www.example.org\r\n" |
| 6323 | "Connection: keep-alive\r\n\r\n"), |
| 6324 | }; |
| 6325 | |
| 6326 | MockRead data_reads[] = { |
| 6327 | MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
| 6328 | MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; |
| 6329 | |
| 6330 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 6331 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 6332 | |
| 6333 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 6334 | arraysize(data_writes)); |
| 6335 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6336 | |
| 6337 | TestCompletionCallback callback; |
| 6338 | |
| 6339 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6340 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6341 | |
| 6342 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6343 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6344 | |
| 6345 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 6346 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6347 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6348 | ASSERT_TRUE(response); |
| 6349 | ASSERT_TRUE(response->headers); |
| 6350 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6351 | |
| 6352 | // Make memory critical notification and ensure the transaction still has been |
| 6353 | // operating right. |
| 6354 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 6355 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 6356 | base::RunLoop().RunUntilIdle(); |
| 6357 | |
| 6358 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 6359 | |
| 6360 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6361 | rv = ReadTransaction(&trans, &response_data); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6362 | EXPECT_THAT(rv, IsOk()); |
| 6363 | EXPECT_EQ("hello world", response_data); |
| 6364 | |
| 6365 | // Empty the current queue. This is necessary because idle sockets are |
| 6366 | // added to the connection pool asynchronously with a PostTask. |
| 6367 | base::RunLoop().RunUntilIdle(); |
| 6368 | |
| 6369 | // We now check to make sure the socket was added back to the pool. |
| 6370 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 6371 | |
| 6372 | // Make memory notification once again and ensure idle socket is closed. |
| 6373 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 6374 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 6375 | base::RunLoop().RunUntilIdle(); |
| 6376 | |
| 6377 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 6378 | } |
| 6379 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6380 | // Make sure that we recycle a socket after a zero-length response. |
| 6381 | // http://crbug.com/9880 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6382 | TEST_F(HttpNetworkTransactionTest, RecycleSocketAfterZeroContentLength) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6383 | HttpRequestInfo request; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6384 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6385 | request.url = GURL( |
| 6386 | "http://www.example.org/csi?v=3&s=web&action=&" |
| 6387 | "tran=undefined&ei=mAXcSeegAo-SMurloeUN&" |
| 6388 | "e=17259,18167,19592,19773,19981,20133,20173,20233&" |
| 6389 | "rt=prt.2642,ol.2649,xjs.2951"); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6390 | request.load_flags = 0; |
| 6391 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6392 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6393 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6394 | MockRead data_reads[] = { |
| 6395 | MockRead("HTTP/1.1 204 No Content\r\n" |
| 6396 | "Content-Length: 0\r\n" |
| 6397 | "Content-Type: text/html\r\n\r\n"), |
| 6398 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6399 | MockRead(SYNCHRONOUS, OK), |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6400 | }; |
| 6401 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6402 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6403 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6404 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 6405 | // Transaction must be created after the MockReads, so it's destroyed before |
| 6406 | // them. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6407 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 6408 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6409 | TestCompletionCallback callback; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6410 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6411 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6412 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6413 | |
| 6414 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6415 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6416 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6417 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6418 | ASSERT_TRUE(response); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6419 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6420 | EXPECT_TRUE(response->headers); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6421 | std::string status_line = response->headers->GetStatusLine(); |
| 6422 | EXPECT_EQ("HTTP/1.1 204 No Content", status_line); |
| 6423 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6424 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6425 | |
| 6426 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6427 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6428 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6429 | EXPECT_EQ("", response_data); |
| 6430 | |
| 6431 | // Empty the current queue. This is necessary because idle sockets are |
| 6432 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6433 | base::RunLoop().RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6434 | |
| 6435 | // 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] | 6436 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6437 | } |
| 6438 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6439 | TEST_F(HttpNetworkTransactionTest, ResendRequestOnWriteBodyError) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6440 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 6441 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 6442 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 6443 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 6444 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6445 | HttpRequestInfo request[2]; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6446 | // Transaction 1: a GET request that succeeds. The socket is recycled |
| 6447 | // after use. |
| 6448 | request[0].method = "GET"; |
| 6449 | request[0].url = GURL("http://www.google.com/"); |
| 6450 | request[0].load_flags = 0; |
| 6451 | // Transaction 2: a POST request. Reuses the socket kept alive from |
| 6452 | // transaction 1. The first attempts fails when writing the POST data. |
| 6453 | // This causes the transaction to retry with a new socket. The second |
| 6454 | // attempt succeeds. |
| 6455 | request[1].method = "POST"; |
| 6456 | request[1].url = GURL("http://www.google.com/login.cgi"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 6457 | request[1].upload_data_stream = &upload_data_stream; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6458 | request[1].load_flags = 0; |
| 6459 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6460 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6461 | |
| 6462 | // The first socket is used for transaction 1 and the first attempt of |
| 6463 | // transaction 2. |
| 6464 | |
| 6465 | // The response of transaction 1. |
| 6466 | MockRead data_reads1[] = { |
| 6467 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\n"), |
| 6468 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6469 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6470 | }; |
| 6471 | // The mock write results of transaction 1 and the first attempt of |
| 6472 | // transaction 2. |
| 6473 | MockWrite data_writes1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6474 | MockWrite(SYNCHRONOUS, 64), // GET |
| 6475 | MockWrite(SYNCHRONOUS, 93), // POST |
| 6476 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_ABORTED), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6477 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6478 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6479 | data_writes1, arraysize(data_writes1)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6480 | |
| 6481 | // The second socket is used for the second attempt of transaction 2. |
| 6482 | |
| 6483 | // The response of transaction 2. |
| 6484 | MockRead data_reads2[] = { |
| 6485 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 7\r\n\r\n"), |
| 6486 | MockRead("welcome"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6487 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6488 | }; |
| 6489 | // The mock write results of the second attempt of transaction 2. |
| 6490 | MockWrite data_writes2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6491 | MockWrite(SYNCHRONOUS, 93), // POST |
| 6492 | MockWrite(SYNCHRONOUS, 3), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6493 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6494 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6495 | data_writes2, arraysize(data_writes2)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6496 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6497 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6498 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6499 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 6500 | const char* const kExpectedResponseData[] = { |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6501 | "hello world", "welcome" |
| 6502 | }; |
| 6503 | |
| 6504 | for (int i = 0; i < 2; ++i) { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6505 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6506 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6507 | TestCompletionCallback callback; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6508 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6509 | int rv = trans.Start(&request[i], callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6510 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6511 | |
| 6512 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6513 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6514 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6515 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6516 | ASSERT_TRUE(response); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6517 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6518 | EXPECT_TRUE(response->headers); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6519 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6520 | |
| 6521 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6522 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6523 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6524 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
| 6525 | } |
| 6526 | } |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6527 | |
| 6528 | // Test the request-challenge-retry sequence for basic auth when there is |
| 6529 | // 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] | 6530 | // it fails the identity from the URL is used to answer the challenge. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6531 | TEST_F(HttpNetworkTransactionTest, AuthIdentityInURL) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6532 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6533 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6534 | request.url = GURL("http://foo:b@[email protected]/"); |
[email protected] | 7b08ba6 | 2012-02-10 20:19:41 | [diff] [blame] | 6535 | request.load_flags = LOAD_NORMAL; |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 6536 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6537 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6538 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6539 | |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 6540 | // The password contains an escaped character -- for this test to pass it |
| 6541 | // will need to be unescaped by HttpNetworkTransaction. |
| 6542 | EXPECT_EQ("b%40r", request.url.password()); |
| 6543 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6544 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6545 | MockWrite( |
| 6546 | "GET / HTTP/1.1\r\n" |
| 6547 | "Host: www.example.org\r\n" |
| 6548 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6549 | }; |
| 6550 | |
| 6551 | MockRead data_reads1[] = { |
| 6552 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6553 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6554 | MockRead("Content-Length: 10\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6555 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6556 | }; |
| 6557 | |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6558 | // After the challenge above, the transaction will be restarted using the |
| 6559 | // identity from the url (foo, b@r) to answer the challenge. |
| 6560 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6561 | MockWrite( |
| 6562 | "GET / HTTP/1.1\r\n" |
| 6563 | "Host: www.example.org\r\n" |
| 6564 | "Connection: keep-alive\r\n" |
| 6565 | "Authorization: Basic Zm9vOmJAcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6566 | }; |
| 6567 | |
| 6568 | MockRead data_reads2[] = { |
| 6569 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6570 | MockRead("Content-Length: 100\r\n\r\n"), |
| 6571 | MockRead(SYNCHRONOUS, OK), |
| 6572 | }; |
| 6573 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6574 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6575 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6576 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6577 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6578 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6579 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6580 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6581 | TestCompletionCallback callback1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6582 | int rv = trans.Start(&request, callback1.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6583 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6584 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6585 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6586 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6587 | |
| 6588 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6589 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6590 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6591 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6592 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6593 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6594 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6595 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6596 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6597 | |
| 6598 | // There is no challenge info, since the identity in URL worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6599 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6600 | |
| 6601 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6602 | |
| 6603 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6604 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6605 | } |
| 6606 | |
| 6607 | // Test the request-challenge-retry sequence for basic auth when there is an |
| 6608 | // incorrect identity in the URL. The identity from the URL should be used only |
| 6609 | // once. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6610 | TEST_F(HttpNetworkTransactionTest, WrongAuthIdentityInURL) { |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6611 | HttpRequestInfo request; |
| 6612 | request.method = "GET"; |
| 6613 | // Note: the URL has a username:password in it. The password "baz" is |
| 6614 | // wrong (should be "bar"). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6615 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6616 | |
| 6617 | request.load_flags = LOAD_NORMAL; |
| 6618 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6619 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6620 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6621 | |
| 6622 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6623 | MockWrite( |
| 6624 | "GET / HTTP/1.1\r\n" |
| 6625 | "Host: www.example.org\r\n" |
| 6626 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6627 | }; |
| 6628 | |
| 6629 | MockRead data_reads1[] = { |
| 6630 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6631 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6632 | MockRead("Content-Length: 10\r\n\r\n"), |
| 6633 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 6634 | }; |
| 6635 | |
| 6636 | // After the challenge above, the transaction will be restarted using the |
| 6637 | // identity from the url (foo, baz) to answer the challenge. |
| 6638 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6639 | MockWrite( |
| 6640 | "GET / HTTP/1.1\r\n" |
| 6641 | "Host: www.example.org\r\n" |
| 6642 | "Connection: keep-alive\r\n" |
| 6643 | "Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6644 | }; |
| 6645 | |
| 6646 | MockRead data_reads2[] = { |
| 6647 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6648 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6649 | MockRead("Content-Length: 10\r\n\r\n"), |
| 6650 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 6651 | }; |
| 6652 | |
| 6653 | // After the challenge above, the transaction will be restarted using the |
| 6654 | // identity supplied by the user (foo, bar) to answer the challenge. |
| 6655 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6656 | MockWrite( |
| 6657 | "GET / HTTP/1.1\r\n" |
| 6658 | "Host: www.example.org\r\n" |
| 6659 | "Connection: keep-alive\r\n" |
| 6660 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6661 | }; |
| 6662 | |
| 6663 | MockRead data_reads3[] = { |
| 6664 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6665 | MockRead("Content-Length: 100\r\n\r\n"), |
| 6666 | MockRead(SYNCHRONOUS, OK), |
| 6667 | }; |
| 6668 | |
| 6669 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6670 | data_writes1, arraysize(data_writes1)); |
| 6671 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6672 | data_writes2, arraysize(data_writes2)); |
| 6673 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 6674 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6675 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6676 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 6677 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6678 | |
| 6679 | TestCompletionCallback callback1; |
| 6680 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6681 | int rv = trans.Start(&request, callback1.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6682 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6683 | |
| 6684 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6685 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6686 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6687 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6688 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6689 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6690 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6691 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6692 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6693 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6694 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6695 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6696 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6697 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 6698 | |
| 6699 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6700 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6701 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6702 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6703 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6704 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6705 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6706 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6707 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6708 | |
| 6709 | // There is no challenge info, since the identity worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6710 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6711 | |
| 6712 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6713 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 6714 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6715 | base::RunLoop().RunUntilIdle(); |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 6716 | } |
| 6717 | |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6718 | |
| 6719 | // Test the request-challenge-retry sequence for basic auth when there is a |
| 6720 | // correct identity in the URL, but its use is being suppressed. The identity |
| 6721 | // from the URL should never be used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6722 | TEST_F(HttpNetworkTransactionTest, AuthIdentityInURLSuppressed) { |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6723 | HttpRequestInfo request; |
| 6724 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6725 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6726 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
| 6727 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6728 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6729 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6730 | |
| 6731 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6732 | MockWrite( |
| 6733 | "GET / HTTP/1.1\r\n" |
| 6734 | "Host: www.example.org\r\n" |
| 6735 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6736 | }; |
| 6737 | |
| 6738 | MockRead data_reads1[] = { |
| 6739 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6740 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6741 | MockRead("Content-Length: 10\r\n\r\n"), |
| 6742 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 6743 | }; |
| 6744 | |
| 6745 | // After the challenge above, the transaction will be restarted using the |
| 6746 | // identity supplied by the user, not the one in the URL, to answer the |
| 6747 | // challenge. |
| 6748 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6749 | MockWrite( |
| 6750 | "GET / HTTP/1.1\r\n" |
| 6751 | "Host: www.example.org\r\n" |
| 6752 | "Connection: keep-alive\r\n" |
| 6753 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6754 | }; |
| 6755 | |
| 6756 | MockRead data_reads3[] = { |
| 6757 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6758 | MockRead("Content-Length: 100\r\n\r\n"), |
| 6759 | MockRead(SYNCHRONOUS, OK), |
| 6760 | }; |
| 6761 | |
| 6762 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6763 | data_writes1, arraysize(data_writes1)); |
| 6764 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 6765 | data_writes3, arraysize(data_writes3)); |
| 6766 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6767 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 6768 | |
| 6769 | TestCompletionCallback callback1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6770 | int rv = trans.Start(&request, callback1.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6771 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6772 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6773 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6774 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6775 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6776 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6777 | ASSERT_TRUE(response); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6778 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 6779 | |
| 6780 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6781 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6782 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6783 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6784 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6785 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6786 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6787 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6788 | ASSERT_TRUE(response); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6789 | |
| 6790 | // There is no challenge info, since the identity worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6791 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6792 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6793 | |
| 6794 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6795 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6796 | } |
| 6797 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6798 | // Test that previously tried username/passwords for a realm get re-used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6799 | TEST_F(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6800 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6801 | |
| 6802 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 6803 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6804 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6805 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6806 | request.url = GURL("http://www.example.org/x/y/z"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6807 | request.load_flags = 0; |
| 6808 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6809 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6810 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6811 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6812 | MockWrite( |
| 6813 | "GET /x/y/z HTTP/1.1\r\n" |
| 6814 | "Host: www.example.org\r\n" |
| 6815 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6816 | }; |
| 6817 | |
| 6818 | MockRead data_reads1[] = { |
| 6819 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6820 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6821 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6822 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6823 | }; |
| 6824 | |
| 6825 | // Resend with authorization (username=foo, password=bar) |
| 6826 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6827 | MockWrite( |
| 6828 | "GET /x/y/z HTTP/1.1\r\n" |
| 6829 | "Host: www.example.org\r\n" |
| 6830 | "Connection: keep-alive\r\n" |
| 6831 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6832 | }; |
| 6833 | |
| 6834 | // Sever accepts the authorization. |
| 6835 | MockRead data_reads2[] = { |
| 6836 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6837 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6838 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6839 | }; |
| 6840 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6841 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6842 | data_writes1, arraysize(data_writes1)); |
| 6843 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6844 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6845 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6846 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6847 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6848 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6849 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6850 | int rv = trans.Start(&request, callback1.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6851 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6852 | |
| 6853 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6854 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6855 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6856 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6857 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6858 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6859 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6860 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6861 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6862 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 6863 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6864 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6865 | |
| 6866 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6867 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6868 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6869 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6870 | ASSERT_TRUE(response); |
| 6871 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6872 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6873 | } |
| 6874 | |
| 6875 | // ------------------------------------------------------------------------ |
| 6876 | |
| 6877 | // Transaction 2: authenticate (foo2, bar2) on MyRealm2 |
| 6878 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6879 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6880 | request.method = "GET"; |
| 6881 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 6882 | // protection space as MyRealm1. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6883 | request.url = GURL("http://www.example.org/x/y/a/b"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6884 | request.load_flags = 0; |
| 6885 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6886 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6887 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6888 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6889 | MockWrite( |
| 6890 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 6891 | "Host: www.example.org\r\n" |
| 6892 | "Connection: keep-alive\r\n" |
| 6893 | // Send preemptive authorization for MyRealm1 |
| 6894 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6895 | }; |
| 6896 | |
| 6897 | // The server didn't like the preemptive authorization, and |
| 6898 | // challenges us for a different realm (MyRealm2). |
| 6899 | MockRead data_reads1[] = { |
| 6900 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6901 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm2\"\r\n"), |
| 6902 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6903 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6904 | }; |
| 6905 | |
| 6906 | // Resend with authorization for MyRealm2 (username=foo2, password=bar2) |
| 6907 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6908 | MockWrite( |
| 6909 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 6910 | "Host: www.example.org\r\n" |
| 6911 | "Connection: keep-alive\r\n" |
| 6912 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6913 | }; |
| 6914 | |
| 6915 | // Sever accepts the authorization. |
| 6916 | MockRead data_reads2[] = { |
| 6917 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6918 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6919 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6920 | }; |
| 6921 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6922 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6923 | data_writes1, arraysize(data_writes1)); |
| 6924 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6925 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6926 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6927 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6928 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6929 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6930 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6931 | int rv = trans.Start(&request, callback1.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6932 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6933 | |
| 6934 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6935 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6936 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6937 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6938 | ASSERT_TRUE(response); |
| 6939 | ASSERT_TRUE(response->auth_challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6940 | EXPECT_FALSE(response->auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 6941 | EXPECT_EQ("http://www.example.org", |
| 6942 | response->auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6943 | EXPECT_EQ("MyRealm2", response->auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 6944 | EXPECT_EQ(kBasicAuthScheme, response->auth_challenge->scheme); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6945 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6946 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6947 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6948 | rv = trans.RestartWithAuth(AuthCredentials(kFoo2, kBar2), |
| 6949 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6950 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6951 | |
| 6952 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6953 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6954 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6955 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6956 | ASSERT_TRUE(response); |
| 6957 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6958 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6959 | } |
| 6960 | |
| 6961 | // ------------------------------------------------------------------------ |
| 6962 | |
| 6963 | // Transaction 3: Resend a request in MyRealm's protection space -- |
| 6964 | // succeed with preemptive authorization. |
| 6965 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6966 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6967 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6968 | request.url = GURL("http://www.example.org/x/y/z2"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6969 | request.load_flags = 0; |
| 6970 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6971 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6972 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6973 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6974 | MockWrite( |
| 6975 | "GET /x/y/z2 HTTP/1.1\r\n" |
| 6976 | "Host: www.example.org\r\n" |
| 6977 | "Connection: keep-alive\r\n" |
| 6978 | // The authorization for MyRealm1 gets sent preemptively |
| 6979 | // (since the url is in the same protection space) |
| 6980 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6981 | }; |
| 6982 | |
| 6983 | // Sever accepts the preemptive authorization |
| 6984 | MockRead data_reads1[] = { |
| 6985 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6986 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6987 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6988 | }; |
| 6989 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6990 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6991 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6992 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6993 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6994 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6995 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6996 | int rv = trans.Start(&request, callback1.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6997 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6998 | |
| 6999 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7000 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7001 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7002 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7003 | ASSERT_TRUE(response); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7004 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7005 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7006 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7007 | } |
| 7008 | |
| 7009 | // ------------------------------------------------------------------------ |
| 7010 | |
| 7011 | // Transaction 4: request another URL in MyRealm (however the |
| 7012 | // url is not known to belong to the protection space, so no pre-auth). |
| 7013 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7014 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7015 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7016 | request.url = GURL("http://www.example.org/x/1"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7017 | request.load_flags = 0; |
| 7018 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7019 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7020 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7021 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7022 | MockWrite( |
| 7023 | "GET /x/1 HTTP/1.1\r\n" |
| 7024 | "Host: www.example.org\r\n" |
| 7025 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7026 | }; |
| 7027 | |
| 7028 | MockRead data_reads1[] = { |
| 7029 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7030 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7031 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7032 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7033 | }; |
| 7034 | |
| 7035 | // Resend with authorization from MyRealm's cache. |
| 7036 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7037 | MockWrite( |
| 7038 | "GET /x/1 HTTP/1.1\r\n" |
| 7039 | "Host: www.example.org\r\n" |
| 7040 | "Connection: keep-alive\r\n" |
| 7041 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7042 | }; |
| 7043 | |
| 7044 | // Sever accepts the authorization. |
| 7045 | MockRead data_reads2[] = { |
| 7046 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7047 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7048 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7049 | }; |
| 7050 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7051 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7052 | data_writes1, arraysize(data_writes1)); |
| 7053 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7054 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7055 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7056 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7057 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7058 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7059 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7060 | int rv = trans.Start(&request, callback1.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7061 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7062 | |
| 7063 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7064 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7065 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7066 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7067 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7068 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7069 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7070 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7071 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7072 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7073 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7074 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7075 | ASSERT_TRUE(response); |
| 7076 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7077 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7078 | } |
| 7079 | |
| 7080 | // ------------------------------------------------------------------------ |
| 7081 | |
| 7082 | // Transaction 5: request a URL in MyRealm, but the server rejects the |
| 7083 | // cached identity. Should invalidate and re-prompt. |
| 7084 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7085 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7086 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7087 | request.url = GURL("http://www.example.org/p/q/t"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7088 | request.load_flags = 0; |
| 7089 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7090 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7091 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7092 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7093 | MockWrite( |
| 7094 | "GET /p/q/t HTTP/1.1\r\n" |
| 7095 | "Host: www.example.org\r\n" |
| 7096 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7097 | }; |
| 7098 | |
| 7099 | MockRead data_reads1[] = { |
| 7100 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7101 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7102 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7103 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7104 | }; |
| 7105 | |
| 7106 | // Resend with authorization from cache for MyRealm. |
| 7107 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7108 | MockWrite( |
| 7109 | "GET /p/q/t HTTP/1.1\r\n" |
| 7110 | "Host: www.example.org\r\n" |
| 7111 | "Connection: keep-alive\r\n" |
| 7112 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7113 | }; |
| 7114 | |
| 7115 | // Sever rejects the authorization. |
| 7116 | MockRead data_reads2[] = { |
| 7117 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7118 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7119 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7120 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7121 | }; |
| 7122 | |
| 7123 | // At this point we should prompt for new credentials for MyRealm. |
| 7124 | // Restart with username=foo3, password=foo4. |
| 7125 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7126 | MockWrite( |
| 7127 | "GET /p/q/t HTTP/1.1\r\n" |
| 7128 | "Host: www.example.org\r\n" |
| 7129 | "Connection: keep-alive\r\n" |
| 7130 | "Authorization: Basic Zm9vMzpiYXIz\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7131 | }; |
| 7132 | |
| 7133 | // Sever accepts the authorization. |
| 7134 | MockRead data_reads3[] = { |
| 7135 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7136 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7137 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7138 | }; |
| 7139 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7140 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7141 | data_writes1, arraysize(data_writes1)); |
| 7142 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7143 | data_writes2, arraysize(data_writes2)); |
| 7144 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 7145 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7146 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7147 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 7148 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7149 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7150 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7151 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7152 | int rv = trans.Start(&request, callback1.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7153 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7154 | |
| 7155 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7156 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7157 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7158 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7159 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7160 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7161 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7162 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7163 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7164 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7165 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7166 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7167 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7168 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7169 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7170 | TestCompletionCallback callback3; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7171 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7172 | rv = trans.RestartWithAuth(AuthCredentials(kFoo3, kBar3), |
| 7173 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7174 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7175 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7176 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7177 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7178 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7179 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7180 | ASSERT_TRUE(response); |
| 7181 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7182 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7183 | } |
| 7184 | } |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7185 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7186 | // Tests that nonce count increments when multiple auth attempts |
| 7187 | // are started with the same nonce. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7188 | TEST_F(HttpNetworkTransactionTest, DigestPreAuthNonceCount) { |
[email protected] | 54fea256 | 2010-11-17 14:40:44 | [diff] [blame] | 7189 | HttpAuthHandlerDigest::Factory* digest_factory = |
| 7190 | new HttpAuthHandlerDigest::Factory(); |
| 7191 | HttpAuthHandlerDigest::FixedNonceGenerator* nonce_generator = |
| 7192 | new HttpAuthHandlerDigest::FixedNonceGenerator("0123456789abcdef"); |
| 7193 | digest_factory->set_nonce_generator(nonce_generator); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7194 | session_deps_.http_auth_handler_factory.reset(digest_factory); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7195 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7196 | |
| 7197 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 7198 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7199 | HttpRequestInfo request; |
| 7200 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7201 | request.url = GURL("http://www.example.org/x/y/z"); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7202 | request.load_flags = 0; |
| 7203 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7204 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7205 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7206 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7207 | MockWrite( |
| 7208 | "GET /x/y/z HTTP/1.1\r\n" |
| 7209 | "Host: www.example.org\r\n" |
| 7210 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7211 | }; |
| 7212 | |
| 7213 | MockRead data_reads1[] = { |
| 7214 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7215 | MockRead("WWW-Authenticate: Digest realm=\"digestive\", nonce=\"OU812\", " |
| 7216 | "algorithm=MD5, qop=\"auth\"\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7217 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7218 | }; |
| 7219 | |
| 7220 | // Resend with authorization (username=foo, password=bar) |
| 7221 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7222 | MockWrite( |
| 7223 | "GET /x/y/z HTTP/1.1\r\n" |
| 7224 | "Host: www.example.org\r\n" |
| 7225 | "Connection: keep-alive\r\n" |
| 7226 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 7227 | "nonce=\"OU812\", uri=\"/x/y/z\", algorithm=MD5, " |
| 7228 | "response=\"03ffbcd30add722589c1de345d7a927f\", qop=auth, " |
| 7229 | "nc=00000001, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7230 | }; |
| 7231 | |
| 7232 | // Sever accepts the authorization. |
| 7233 | MockRead data_reads2[] = { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 7234 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7235 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7236 | }; |
| 7237 | |
| 7238 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7239 | data_writes1, arraysize(data_writes1)); |
| 7240 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7241 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7242 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7243 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7244 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7245 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7246 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7247 | int rv = trans.Start(&request, callback1.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7248 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7249 | |
| 7250 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7251 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7252 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7253 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7254 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7255 | EXPECT_TRUE(CheckDigestServerAuth(response->auth_challenge.get())); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7256 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7257 | TestCompletionCallback callback2; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7258 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7259 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 7260 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7261 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7262 | |
| 7263 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7264 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7265 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7266 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7267 | ASSERT_TRUE(response); |
| 7268 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7269 | } |
| 7270 | |
| 7271 | // ------------------------------------------------------------------------ |
| 7272 | |
| 7273 | // Transaction 2: Request another resource in digestive's protection space. |
| 7274 | // This will preemptively add an Authorization header which should have an |
| 7275 | // "nc" value of 2 (as compared to 1 in the first use. |
| 7276 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7277 | HttpRequestInfo request; |
| 7278 | request.method = "GET"; |
| 7279 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 7280 | // protection space as digest. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7281 | request.url = GURL("http://www.example.org/x/y/a/b"); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7282 | request.load_flags = 0; |
| 7283 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7284 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7285 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7286 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7287 | MockWrite( |
| 7288 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 7289 | "Host: www.example.org\r\n" |
| 7290 | "Connection: keep-alive\r\n" |
| 7291 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 7292 | "nonce=\"OU812\", uri=\"/x/y/a/b\", algorithm=MD5, " |
| 7293 | "response=\"d6f9a2c07d1c5df7b89379dca1269b35\", qop=auth, " |
| 7294 | "nc=00000002, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7295 | }; |
| 7296 | |
| 7297 | // Sever accepts the authorization. |
| 7298 | MockRead data_reads1[] = { |
| 7299 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7300 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7301 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7302 | }; |
| 7303 | |
| 7304 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7305 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7306 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7307 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7308 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7309 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7310 | int rv = trans.Start(&request, callback1.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7311 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7312 | |
| 7313 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7314 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7315 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7316 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7317 | ASSERT_TRUE(response); |
| 7318 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7319 | } |
| 7320 | } |
| 7321 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7322 | // Test the ResetStateForRestart() private method. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7323 | TEST_F(HttpNetworkTransactionTest, ResetStateForRestart) { |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7324 | // Create a transaction (the dependencies aren't important). |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7325 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7326 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7327 | |
| 7328 | // Setup some state (which we expect ResetStateForRestart() will clear). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7329 | trans.read_buf_ = new IOBuffer(15); |
| 7330 | trans.read_buf_len_ = 15; |
| 7331 | trans.request_headers_.SetHeader("Authorization", "NTLM"); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7332 | |
| 7333 | // Setup state in response_ |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7334 | HttpResponseInfo* response = &trans.response_; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7335 | response->auth_challenge = new AuthChallengeInfo(); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 7336 | response->ssl_info.cert_status = static_cast<CertStatus>(-1); // Nonsensical. |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7337 | response->response_time = base::Time::Now(); |
| 7338 | response->was_cached = true; // (Wouldn't ever actually be true...) |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7339 | |
| 7340 | { // Setup state for response_.vary_data |
| 7341 | HttpRequestInfo request; |
| 7342 | std::string temp("HTTP/1.1 200 OK\nVary: foo, bar\n\n"); |
| 7343 | std::replace(temp.begin(), temp.end(), '\n', '\0'); |
[email protected] | ad8e04a | 2010-11-01 04:16:27 | [diff] [blame] | 7344 | scoped_refptr<HttpResponseHeaders> headers(new HttpResponseHeaders(temp)); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 7345 | request.extra_headers.SetHeader("Foo", "1"); |
| 7346 | request.extra_headers.SetHeader("bar", "23"); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7347 | EXPECT_TRUE(response->vary_data.Init(request, *headers.get())); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7348 | } |
| 7349 | |
| 7350 | // Cause the above state to be reset. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7351 | trans.ResetStateForRestart(); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7352 | |
| 7353 | // Verify that the state that needed to be reset, has been reset. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7354 | EXPECT_FALSE(trans.read_buf_); |
| 7355 | EXPECT_EQ(0, trans.read_buf_len_); |
| 7356 | EXPECT_TRUE(trans.request_headers_.IsEmpty()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7357 | EXPECT_FALSE(response->auth_challenge); |
| 7358 | EXPECT_FALSE(response->headers); |
[email protected] | 34f4094 | 2010-10-04 00:34:04 | [diff] [blame] | 7359 | EXPECT_FALSE(response->was_cached); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 7360 | EXPECT_EQ(0U, response->ssl_info.cert_status); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7361 | EXPECT_FALSE(response->vary_data.is_valid()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7362 | } |
| 7363 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7364 | // Test HTTPS connections to a site with a bad certificate |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7365 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificate) { |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7366 | HttpRequestInfo request; |
| 7367 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7368 | request.url = GURL("https://www.example.org/"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7369 | request.load_flags = 0; |
| 7370 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7371 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7372 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7373 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7374 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7375 | MockWrite( |
| 7376 | "GET / HTTP/1.1\r\n" |
| 7377 | "Host: www.example.org\r\n" |
| 7378 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7379 | }; |
| 7380 | |
| 7381 | MockRead data_reads[] = { |
| 7382 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7383 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7384 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7385 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7386 | }; |
| 7387 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 7388 | StaticSocketDataProvider ssl_bad_certificate; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7389 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7390 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7391 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 7392 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7393 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7394 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 7395 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7396 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 7397 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7398 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7399 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7400 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7401 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7402 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7403 | |
| 7404 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7405 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7406 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7407 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7408 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7409 | |
| 7410 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7411 | EXPECT_THAT(rv, IsOk()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7412 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7413 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7414 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7415 | ASSERT_TRUE(response); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7416 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7417 | } |
| 7418 | |
| 7419 | // Test HTTPS connections to a site with a bad certificate, going through a |
| 7420 | // proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7421 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7422 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7423 | |
| 7424 | HttpRequestInfo request; |
| 7425 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7426 | request.url = GURL("https://www.example.org/"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7427 | request.load_flags = 0; |
| 7428 | |
| 7429 | MockWrite proxy_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7430 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7431 | "Host: www.example.org:443\r\n" |
| 7432 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7433 | }; |
| 7434 | |
| 7435 | MockRead proxy_reads[] = { |
| 7436 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7437 | MockRead(SYNCHRONOUS, OK) |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7438 | }; |
| 7439 | |
| 7440 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7441 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7442 | "Host: www.example.org:443\r\n" |
| 7443 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 7444 | MockWrite("GET / HTTP/1.1\r\n" |
| 7445 | "Host: www.example.org\r\n" |
| 7446 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7447 | }; |
| 7448 | |
| 7449 | MockRead data_reads[] = { |
| 7450 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 7451 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7452 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7453 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7454 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7455 | }; |
| 7456 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7457 | StaticSocketDataProvider ssl_bad_certificate( |
| 7458 | proxy_reads, arraysize(proxy_reads), |
| 7459 | proxy_writes, arraysize(proxy_writes)); |
| 7460 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7461 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7462 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 7463 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7464 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7465 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 7466 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7467 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 7468 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7469 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7470 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7471 | |
| 7472 | for (int i = 0; i < 2; i++) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7473 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7474 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7475 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7476 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7477 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7478 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7479 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7480 | |
| 7481 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7482 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7483 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7484 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7485 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7486 | |
| 7487 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7488 | EXPECT_THAT(rv, IsOk()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7489 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7490 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7491 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7492 | ASSERT_TRUE(response); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7493 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7494 | } |
| 7495 | } |
| 7496 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7497 | |
| 7498 | // Test HTTPS connections to a site, going through an HTTPS proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7499 | TEST_F(HttpNetworkTransactionTest, HTTPSViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7500 | session_deps_.proxy_service = |
| 7501 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7502 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7503 | session_deps_.net_log = &net_log; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7504 | |
| 7505 | HttpRequestInfo request; |
| 7506 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7507 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7508 | request.load_flags = 0; |
| 7509 | |
| 7510 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7511 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7512 | "Host: www.example.org:443\r\n" |
| 7513 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 7514 | MockWrite("GET / HTTP/1.1\r\n" |
| 7515 | "Host: www.example.org\r\n" |
| 7516 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7517 | }; |
| 7518 | |
| 7519 | MockRead data_reads[] = { |
| 7520 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 7521 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 7522 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7523 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7524 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7525 | }; |
| 7526 | |
| 7527 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7528 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7529 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
| 7530 | SSLSocketDataProvider tunnel_ssl(ASYNC, OK); // SSL through the tunnel |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7531 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7532 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7533 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
| 7534 | session_deps_.socket_factory->AddSSLSocketDataProvider(&tunnel_ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7535 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7536 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7537 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7538 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7539 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7540 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7541 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7542 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7543 | |
| 7544 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7545 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7546 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7547 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7548 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7549 | |
| 7550 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 7551 | EXPECT_EQ(200, response->headers->response_code()); |
| 7552 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7553 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7554 | |
| 7555 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7556 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7557 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 7558 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7559 | } |
| 7560 | |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7561 | // Test an HTTPS Proxy's ability to redirect a CONNECT request |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7562 | TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7563 | session_deps_.proxy_service = |
| 7564 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7565 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7566 | session_deps_.net_log = &net_log; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7567 | |
| 7568 | HttpRequestInfo request; |
| 7569 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7570 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7571 | request.load_flags = 0; |
| 7572 | |
| 7573 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7574 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7575 | "Host: www.example.org:443\r\n" |
| 7576 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7577 | }; |
| 7578 | |
| 7579 | MockRead data_reads[] = { |
| 7580 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 7581 | MockRead("Location: http://login.example.com/\r\n"), |
| 7582 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7583 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7584 | }; |
| 7585 | |
| 7586 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7587 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7588 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7589 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7590 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7591 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7592 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7593 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7594 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7595 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7596 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7597 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7598 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7599 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7600 | |
| 7601 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7602 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7603 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7604 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7605 | ASSERT_TRUE(response); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7606 | |
| 7607 | EXPECT_EQ(302, response->headers->response_code()); |
| 7608 | std::string url; |
| 7609 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 7610 | EXPECT_EQ("http://login.example.com/", url); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7611 | |
| 7612 | // In the case of redirects from proxies, HttpNetworkTransaction returns |
| 7613 | // timing for the proxy connection instead of the connection to the host, |
| 7614 | // and no send / receive times. |
| 7615 | // See HttpNetworkTransaction::OnHttpsProxyTunnelResponse. |
| 7616 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7617 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7618 | |
| 7619 | EXPECT_FALSE(load_timing_info.socket_reused); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 7620 | EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7621 | |
| 7622 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 7623 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 7624 | load_timing_info.proxy_resolve_end); |
| 7625 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 7626 | load_timing_info.connect_timing.connect_start); |
| 7627 | ExpectConnectTimingHasTimes( |
| 7628 | load_timing_info.connect_timing, |
| 7629 | CONNECT_TIMING_HAS_DNS_TIMES | CONNECT_TIMING_HAS_SSL_TIMES); |
| 7630 | |
| 7631 | EXPECT_TRUE(load_timing_info.send_start.is_null()); |
| 7632 | EXPECT_TRUE(load_timing_info.send_end.is_null()); |
| 7633 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7634 | } |
| 7635 | |
| 7636 | // Test an HTTPS (SPDY) Proxy's ability to redirect a CONNECT request |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7637 | TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaSpdyProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7638 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7639 | |
| 7640 | HttpRequestInfo request; |
| 7641 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7642 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7643 | request.load_flags = 0; |
| 7644 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7645 | SpdySerializedFrame conn(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7646 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7647 | SpdySerializedFrame goaway( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 7648 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7649 | MockWrite data_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7650 | CreateMockWrite(conn, 0, SYNCHRONOUS), |
| 7651 | CreateMockWrite(goaway, 2, SYNCHRONOUS), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7652 | }; |
| 7653 | |
| 7654 | static const char* const kExtraHeaders[] = { |
| 7655 | "location", |
| 7656 | "http://login.example.com/", |
| 7657 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 7658 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7659 | "302 Redirect", kExtraHeaders, arraysize(kExtraHeaders) / 2, 1)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7660 | MockRead data_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7661 | CreateMockRead(resp, 1), MockRead(ASYNC, 0, 3), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7662 | }; |
| 7663 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7664 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 7665 | arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7666 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 7667 | proxy_ssl.next_proto = kProtoHTTP2; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7668 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7669 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7670 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7671 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7672 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7673 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7674 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7675 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7676 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7677 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7678 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7679 | |
| 7680 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7681 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7682 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7683 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7684 | ASSERT_TRUE(response); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7685 | |
| 7686 | EXPECT_EQ(302, response->headers->response_code()); |
| 7687 | std::string url; |
| 7688 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 7689 | EXPECT_EQ("http://login.example.com/", url); |
| 7690 | } |
| 7691 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 7692 | // Test that an HTTPS proxy's response to a CONNECT request is filtered. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7693 | TEST_F(HttpNetworkTransactionTest, ErrorResponseToHttpsConnectViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7694 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7695 | |
| 7696 | HttpRequestInfo request; |
| 7697 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7698 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7699 | request.load_flags = 0; |
| 7700 | |
| 7701 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7702 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7703 | "Host: www.example.org:443\r\n" |
| 7704 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7705 | }; |
| 7706 | |
| 7707 | MockRead data_reads[] = { |
| 7708 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 7709 | MockRead("Content-Length: 23\r\n\r\n"), |
| 7710 | MockRead("The host does not exist"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7711 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7712 | }; |
| 7713 | |
| 7714 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7715 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7716 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7717 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7718 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7719 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7720 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7721 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7722 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7723 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7724 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7725 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7726 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7727 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7728 | |
| 7729 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7730 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7731 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 7732 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7733 | } |
| 7734 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 7735 | // Test that a SPDY proxy's response to a CONNECT request is filtered. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7736 | TEST_F(HttpNetworkTransactionTest, ErrorResponseToHttpsConnectViaSpdyProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7737 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7738 | |
| 7739 | HttpRequestInfo request; |
| 7740 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7741 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7742 | request.load_flags = 0; |
| 7743 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7744 | SpdySerializedFrame conn(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7745 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7746 | SpdySerializedFrame rst( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 7747 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7748 | MockWrite data_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7749 | CreateMockWrite(conn, 0), CreateMockWrite(rst, 3), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7750 | }; |
| 7751 | |
| 7752 | static const char* const kExtraHeaders[] = { |
| 7753 | "location", |
| 7754 | "http://login.example.com/", |
| 7755 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 7756 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7757 | "404 Not Found", kExtraHeaders, arraysize(kExtraHeaders) / 2, 1)); |
| 7758 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 7759 | 1, "The host does not exist", 23, true)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7760 | MockRead data_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7761 | CreateMockRead(resp, 1), CreateMockRead(body, 2), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7762 | MockRead(ASYNC, 0, 4), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7763 | }; |
| 7764 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7765 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 7766 | arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7767 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 7768 | proxy_ssl.next_proto = kProtoHTTP2; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7769 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7770 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7771 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7772 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7773 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7774 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7775 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7776 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7777 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7778 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7779 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7780 | |
| 7781 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7782 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7783 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 7784 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7785 | } |
| 7786 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7787 | // Test the request-challenge-retry sequence for basic auth, through |
| 7788 | // a SPDY proxy over a single SPDY session. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7789 | TEST_F(HttpNetworkTransactionTest, BasicAuthSpdyProxy) { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7790 | HttpRequestInfo request; |
| 7791 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7792 | request.url = GURL("https://www.example.org/"); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7793 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 7794 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7795 | |
| 7796 | // Configure against https proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7797 | session_deps_.proxy_service = |
| 7798 | ProxyService::CreateFixedFromPacResult("HTTPS myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7799 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7800 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7801 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7802 | |
| 7803 | // Since we have proxy, should try to establish tunnel. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7804 | SpdySerializedFrame req(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7805 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7806 | SpdySerializedFrame rst( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 7807 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 7808 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7809 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7810 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7811 | // be issuing -- the final header line contains the credentials. |
| 7812 | const char* const kAuthCredentials[] = { |
| 7813 | "proxy-authorization", "Basic Zm9vOmJhcg==", |
| 7814 | }; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7815 | SpdySerializedFrame connect2(spdy_util_.ConstructSpdyConnect( |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 7816 | kAuthCredentials, arraysize(kAuthCredentials) / 2, 3, LOWEST, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7817 | HostPortPair("www.example.org", 443))); |
| 7818 | // fetch https://www.example.org/ via HTTP |
| 7819 | const char get[] = |
| 7820 | "GET / HTTP/1.1\r\n" |
| 7821 | "Host: www.example.org\r\n" |
| 7822 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7823 | SpdySerializedFrame wrapped_get( |
| 7824 | spdy_util_.ConstructSpdyDataFrame(3, get, strlen(get), false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7825 | |
| 7826 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7827 | CreateMockWrite(req, 0, ASYNC), CreateMockWrite(rst, 2, ASYNC), |
| 7828 | CreateMockWrite(connect2, 3), CreateMockWrite(wrapped_get, 5), |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7829 | }; |
| 7830 | |
| 7831 | // The proxy responds to the connect with a 407, using a persistent |
| 7832 | // connection. |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 7833 | const char kAuthStatus[] = "407"; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7834 | const char* const kAuthChallenge[] = { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7835 | "proxy-authenticate", "Basic realm=\"MyRealm1\"", |
| 7836 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 7837 | SpdySerializedFrame conn_auth_resp(spdy_util_.ConstructSpdyReplyError( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7838 | kAuthStatus, kAuthChallenge, arraysize(kAuthChallenge) / 2, 1)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7839 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 7840 | SpdySerializedFrame conn_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7841 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 7842 | "Content-Length: 5\r\n\r\n"; |
| 7843 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7844 | SpdySerializedFrame wrapped_get_resp( |
| 7845 | spdy_util_.ConstructSpdyDataFrame(3, resp, strlen(resp), false)); |
| 7846 | SpdySerializedFrame wrapped_body( |
| 7847 | spdy_util_.ConstructSpdyDataFrame(3, "hello", 5, false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7848 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7849 | CreateMockRead(conn_auth_resp, 1, ASYNC), |
| 7850 | CreateMockRead(conn_resp, 4, ASYNC), |
| 7851 | CreateMockRead(wrapped_get_resp, 6, ASYNC), |
| 7852 | CreateMockRead(wrapped_body, 7, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7853 | MockRead(ASYNC, OK, 8), // EOF. May or may not be read. |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7854 | }; |
| 7855 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7856 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 7857 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7858 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7859 | // Negotiate SPDY to the proxy |
| 7860 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 7861 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7862 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7863 | // Vanilla SSL to the server |
| 7864 | SSLSocketDataProvider server(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7865 | session_deps_.socket_factory->AddSSLSocketDataProvider(&server); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7866 | |
| 7867 | TestCompletionCallback callback1; |
| 7868 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7869 | std::unique_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7870 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7871 | |
| 7872 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7873 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7874 | |
| 7875 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7876 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 7877 | TestNetLogEntry::List entries; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7878 | log.GetEntries(&entries); |
| 7879 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 7880 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 7881 | NetLogEventPhase::NONE); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7882 | ExpectLogContainsSomewhere( |
| 7883 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 7884 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 7885 | NetLogEventPhase::NONE); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7886 | |
| 7887 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7888 | ASSERT_TRUE(response); |
| 7889 | ASSERT_TRUE(response->headers); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7890 | EXPECT_EQ(407, response->headers->response_code()); |
| 7891 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7892 | EXPECT_TRUE(response->auth_challenge); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 7893 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7894 | |
| 7895 | TestCompletionCallback callback2; |
| 7896 | |
| 7897 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 7898 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7899 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7900 | |
| 7901 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7902 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7903 | |
| 7904 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7905 | ASSERT_TRUE(response); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7906 | |
| 7907 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 7908 | EXPECT_EQ(200, response->headers->response_code()); |
| 7909 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 7910 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 7911 | |
| 7912 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7913 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7914 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7915 | LoadTimingInfo load_timing_info; |
| 7916 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7917 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 7918 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 7919 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7920 | trans.reset(); |
| 7921 | session->CloseAllConnections(); |
| 7922 | } |
| 7923 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7924 | // Test that an explicitly trusted SPDY proxy can push a resource from an |
| 7925 | // origin that is different from that of its associated resource. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7926 | TEST_F(HttpNetworkTransactionTest, CrossOriginSPDYProxyPush) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 7927 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7928 | std::unique_ptr<TestProxyDelegate> proxy_delegate(new TestProxyDelegate()); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 7929 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 7930 | "https://myproxy:443", net::ProxyServer::SCHEME_HTTP)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7931 | HttpRequestInfo request; |
| 7932 | HttpRequestInfo push_request; |
| 7933 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7934 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7935 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7936 | push_request.method = "GET"; |
| 7937 | push_request.url = GURL("http://www.another-origin.com/foo.dat"); |
| 7938 | |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 7939 | // Configure against https proxy server "myproxy:443". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7940 | session_deps_.proxy_service = |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 7941 | ProxyService::CreateFixedFromPacResult("HTTPS myproxy:443"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7942 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7943 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 7944 | |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 7945 | session_deps_.proxy_delegate.reset(proxy_delegate.release()); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 7946 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7947 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7948 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7949 | SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 7950 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7951 | |
| 7952 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7953 | CreateMockWrite(stream1_syn, 0, ASYNC), |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7954 | }; |
| 7955 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7956 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 7957 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7958 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7959 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7960 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7961 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 7962 | NULL, 0, 2, 1, "http://www.another-origin.com/foo.dat")); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 7963 | const char kPushedData[] = "pushed"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7964 | SpdySerializedFrame stream2_body(spdy_util_.ConstructSpdyDataFrame( |
| 7965 | 2, kPushedData, strlen(kPushedData), true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7966 | |
| 7967 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7968 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 7969 | CreateMockRead(stream2_syn, 2, ASYNC), |
| 7970 | CreateMockRead(stream1_body, 3, ASYNC), |
| 7971 | CreateMockRead(stream2_body, 4, ASYNC), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 7972 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), // Force a hang |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7973 | }; |
| 7974 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7975 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 7976 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7977 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7978 | // Negotiate SPDY to the proxy |
| 7979 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 7980 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7981 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7982 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7983 | std::unique_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7984 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7985 | TestCompletionCallback callback; |
| 7986 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7987 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7988 | |
| 7989 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7990 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7991 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7992 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7993 | std::unique_ptr<HttpNetworkTransaction> push_trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7994 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 7995 | rv = push_trans->Start(&push_request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7996 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7997 | |
| 7998 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7999 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8000 | const HttpResponseInfo* push_response = push_trans->GetResponseInfo(); |
| 8001 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8002 | ASSERT_TRUE(response); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8003 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 8004 | |
| 8005 | EXPECT_EQ(200, response->headers->response_code()); |
| 8006 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 8007 | |
| 8008 | std::string response_data; |
| 8009 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8010 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8011 | EXPECT_EQ("hello!", response_data); |
| 8012 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8013 | LoadTimingInfo load_timing_info; |
| 8014 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 8015 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8016 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 8017 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8018 | // Verify the pushed stream. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8019 | EXPECT_TRUE(push_response->headers); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8020 | EXPECT_EQ(200, push_response->headers->response_code()); |
| 8021 | |
| 8022 | rv = ReadTransaction(push_trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8023 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8024 | EXPECT_EQ("pushed", response_data); |
| 8025 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8026 | LoadTimingInfo push_load_timing_info; |
| 8027 | EXPECT_TRUE(push_trans->GetLoadTimingInfo(&push_load_timing_info)); |
| 8028 | TestLoadTimingReusedWithPac(push_load_timing_info); |
| 8029 | // The transactions should share a socket ID, despite being for different |
| 8030 | // origins. |
| 8031 | EXPECT_EQ(load_timing_info.socket_log_id, |
| 8032 | push_load_timing_info.socket_log_id); |
| 8033 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8034 | trans.reset(); |
| 8035 | push_trans.reset(); |
| 8036 | session->CloseAllConnections(); |
| 8037 | } |
| 8038 | |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8039 | // Test that an explicitly trusted SPDY proxy cannot push HTTPS content. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8040 | TEST_F(HttpNetworkTransactionTest, CrossOriginProxyPushCorrectness) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8041 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8042 | std::unique_ptr<TestProxyDelegate> proxy_delegate(new TestProxyDelegate()); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8043 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 8044 | "https://myproxy:443", net::ProxyServer::SCHEME_HTTP)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8045 | HttpRequestInfo request; |
| 8046 | |
| 8047 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8048 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8049 | |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8050 | session_deps_.proxy_service = |
| 8051 | ProxyService::CreateFixed("https://myproxy:443"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8052 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8053 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 8054 | |
| 8055 | // Enable cross-origin push. |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8056 | session_deps_.proxy_delegate.reset(proxy_delegate.release()); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 8057 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8058 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8059 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8060 | SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 8061 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8062 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8063 | SpdySerializedFrame push_rst( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 8064 | spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_REFUSED_STREAM)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8065 | |
| 8066 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8067 | CreateMockWrite(stream1_syn, 0, ASYNC), CreateMockWrite(push_rst, 3), |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8068 | }; |
| 8069 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8070 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8071 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8072 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8073 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8074 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8075 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 8076 | NULL, 0, 2, 1, "https://www.another-origin.com/foo.dat")); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8077 | |
| 8078 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8079 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 8080 | CreateMockRead(stream2_syn, 2, ASYNC), |
| 8081 | CreateMockRead(stream1_body, 4, ASYNC), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 8082 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), // Force a hang |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8083 | }; |
| 8084 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8085 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 8086 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8087 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8088 | // Negotiate SPDY to the proxy |
| 8089 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8090 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8091 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8092 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8093 | std::unique_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8094 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8095 | TestCompletionCallback callback; |
| 8096 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8097 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8098 | |
| 8099 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8100 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8101 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8102 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8103 | ASSERT_TRUE(response); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8104 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 8105 | |
| 8106 | EXPECT_EQ(200, response->headers->response_code()); |
| 8107 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 8108 | |
| 8109 | std::string response_data; |
| 8110 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8111 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8112 | EXPECT_EQ("hello!", response_data); |
| 8113 | |
| 8114 | trans.reset(); |
| 8115 | session->CloseAllConnections(); |
| 8116 | } |
| 8117 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8118 | // Test that an explicitly trusted SPDY proxy can push same-origin HTTPS |
| 8119 | // resources. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8120 | TEST_F(HttpNetworkTransactionTest, SameOriginProxyPushCorrectness) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8121 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8122 | std::unique_ptr<TestProxyDelegate> proxy_delegate(new TestProxyDelegate()); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8123 | proxy_delegate->set_trusted_spdy_proxy( |
| 8124 | net::ProxyServer::FromURI("myproxy:70", net::ProxyServer::SCHEME_HTTP)); |
| 8125 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8126 | HttpRequestInfo request; |
| 8127 | |
| 8128 | request.method = "GET"; |
| 8129 | request.url = GURL("http://www.example.org/"); |
| 8130 | |
| 8131 | // Configure against https proxy server "myproxy:70". |
| 8132 | session_deps_.proxy_service = ProxyService::CreateFixed("https://myproxy:70"); |
| 8133 | BoundTestNetLog log; |
| 8134 | session_deps_.net_log = log.bound().net_log(); |
| 8135 | |
| 8136 | // Enable cross-origin push. |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8137 | session_deps_.proxy_delegate.reset(proxy_delegate.release()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8138 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8139 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8140 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8141 | SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 8142 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8143 | |
| 8144 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8145 | CreateMockWrite(stream1_syn, 0, ASYNC), |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8146 | }; |
| 8147 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8148 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8149 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8150 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8151 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 8152 | nullptr, 0, 2, 1, "https://myproxy:70/foo.dat")); |
| 8153 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8154 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8155 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8156 | SpdySerializedFrame stream2_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8157 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8158 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8159 | SpdySerializedFrame stream2_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8160 | |
| 8161 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8162 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 8163 | CreateMockRead(stream2_syn, 2, ASYNC), |
| 8164 | CreateMockRead(stream1_body, 3, ASYNC), |
| 8165 | CreateMockRead(stream2_body, 4, ASYNC), |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8166 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), // Force a hang |
| 8167 | }; |
| 8168 | |
| 8169 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 8170 | arraysize(spdy_writes)); |
| 8171 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 8172 | // Negotiate SPDY to the proxy |
| 8173 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8174 | proxy.next_proto = kProtoHTTP2; |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8175 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
| 8176 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8177 | std::unique_ptr<HttpNetworkTransaction> trans( |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8178 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 8179 | TestCompletionCallback callback; |
| 8180 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8181 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8182 | |
| 8183 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8184 | EXPECT_THAT(rv, IsOk()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8185 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8186 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8187 | ASSERT_TRUE(response); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8188 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 8189 | |
| 8190 | EXPECT_EQ(200, response->headers->response_code()); |
| 8191 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 8192 | |
| 8193 | std::string response_data; |
| 8194 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8195 | EXPECT_THAT(rv, IsOk()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8196 | EXPECT_EQ("hello!", response_data); |
| 8197 | |
| 8198 | trans.reset(); |
| 8199 | session->CloseAllConnections(); |
| 8200 | } |
| 8201 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8202 | // Test HTTPS connections to a site with a bad certificate, going through an |
| 8203 | // HTTPS proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8204 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8205 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8206 | |
| 8207 | HttpRequestInfo request; |
| 8208 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8209 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8210 | request.load_flags = 0; |
| 8211 | |
| 8212 | // Attempt to fetch the URL from a server with a bad cert |
| 8213 | MockWrite bad_cert_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8214 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8215 | "Host: www.example.org:443\r\n" |
| 8216 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8217 | }; |
| 8218 | |
| 8219 | MockRead bad_cert_reads[] = { |
| 8220 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8221 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8222 | }; |
| 8223 | |
| 8224 | // Attempt to fetch the URL with a good cert |
| 8225 | MockWrite good_data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8226 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8227 | "Host: www.example.org:443\r\n" |
| 8228 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 8229 | MockWrite("GET / HTTP/1.1\r\n" |
| 8230 | "Host: www.example.org\r\n" |
| 8231 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8232 | }; |
| 8233 | |
| 8234 | MockRead good_cert_reads[] = { |
| 8235 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 8236 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8237 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8238 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8239 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8240 | }; |
| 8241 | |
| 8242 | StaticSocketDataProvider ssl_bad_certificate( |
| 8243 | bad_cert_reads, arraysize(bad_cert_reads), |
| 8244 | bad_cert_writes, arraysize(bad_cert_writes)); |
| 8245 | StaticSocketDataProvider data(good_cert_reads, arraysize(good_cert_reads), |
| 8246 | good_data_writes, arraysize(good_data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8247 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 8248 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8249 | |
| 8250 | // SSL to the proxy, then CONNECT request, then SSL with bad certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8251 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 8252 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 8253 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8254 | |
| 8255 | // SSL to the proxy, then CONNECT request, then valid SSL certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8256 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 8257 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8258 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8259 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8260 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8261 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8262 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8263 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8264 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8265 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8266 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8267 | |
| 8268 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8269 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8270 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8271 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8272 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8273 | |
| 8274 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8275 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8276 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8277 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8278 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8279 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8280 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8281 | } |
| 8282 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8283 | TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgent) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8284 | HttpRequestInfo request; |
| 8285 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8286 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 8287 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 8288 | "Chromium Ultra Awesome X Edition"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8289 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8290 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8291 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8292 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8293 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8294 | MockWrite( |
| 8295 | "GET / HTTP/1.1\r\n" |
| 8296 | "Host: www.example.org\r\n" |
| 8297 | "Connection: keep-alive\r\n" |
| 8298 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8299 | }; |
| 8300 | |
| 8301 | // Lastly, the server responds with the actual content. |
| 8302 | MockRead data_reads[] = { |
| 8303 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8304 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8305 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8306 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8307 | }; |
| 8308 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8309 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8310 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8311 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8312 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8313 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8314 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8315 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8316 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8317 | |
| 8318 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8319 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8320 | } |
| 8321 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8322 | TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgentOverTunnel) { |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8323 | HttpRequestInfo request; |
| 8324 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8325 | request.url = GURL("https://www.example.org/"); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8326 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 8327 | "Chromium Ultra Awesome X Edition"); |
| 8328 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8329 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8330 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8331 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8332 | |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8333 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8334 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8335 | "Host: www.example.org:443\r\n" |
| 8336 | "Proxy-Connection: keep-alive\r\n" |
| 8337 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8338 | }; |
| 8339 | MockRead data_reads[] = { |
| 8340 | // Return an error, so the transaction stops here (this test isn't |
| 8341 | // interested in the rest). |
| 8342 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 8343 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8344 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 8345 | }; |
| 8346 | |
| 8347 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8348 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8349 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8350 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8351 | TestCompletionCallback callback; |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8352 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8353 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8354 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8355 | |
| 8356 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8357 | EXPECT_THAT(rv, IsOk()); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8358 | } |
| 8359 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8360 | TEST_F(HttpNetworkTransactionTest, BuildRequest_Referer) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8361 | HttpRequestInfo request; |
| 8362 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8363 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8364 | request.load_flags = 0; |
[email protected] | c1045010 | 2011-06-27 09:06:16 | [diff] [blame] | 8365 | request.extra_headers.SetHeader(HttpRequestHeaders::kReferer, |
| 8366 | "http://the.previous.site.com/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8367 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8368 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8369 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8370 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8371 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8372 | MockWrite( |
| 8373 | "GET / HTTP/1.1\r\n" |
| 8374 | "Host: www.example.org\r\n" |
| 8375 | "Connection: keep-alive\r\n" |
| 8376 | "Referer: http://the.previous.site.com/\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8377 | }; |
| 8378 | |
| 8379 | // Lastly, the server responds with the actual content. |
| 8380 | MockRead data_reads[] = { |
| 8381 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8382 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8383 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8384 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8385 | }; |
| 8386 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8387 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8388 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8389 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8390 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8391 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8392 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8393 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8394 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8395 | |
| 8396 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8397 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8398 | } |
| 8399 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8400 | TEST_F(HttpNetworkTransactionTest, BuildRequest_PostContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8401 | HttpRequestInfo request; |
| 8402 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8403 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8404 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8405 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8406 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8407 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8408 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8409 | MockWrite( |
| 8410 | "POST / HTTP/1.1\r\n" |
| 8411 | "Host: www.example.org\r\n" |
| 8412 | "Connection: keep-alive\r\n" |
| 8413 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8414 | }; |
| 8415 | |
| 8416 | // Lastly, the server responds with the actual content. |
| 8417 | MockRead data_reads[] = { |
| 8418 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8419 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8420 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8421 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8422 | }; |
| 8423 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8424 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8425 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8426 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8427 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8428 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8429 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8430 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8431 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8432 | |
| 8433 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8434 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8435 | } |
| 8436 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8437 | TEST_F(HttpNetworkTransactionTest, BuildRequest_PutContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8438 | HttpRequestInfo request; |
| 8439 | request.method = "PUT"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8440 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8441 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8442 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8443 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8444 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8445 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8446 | MockWrite( |
| 8447 | "PUT / HTTP/1.1\r\n" |
| 8448 | "Host: www.example.org\r\n" |
| 8449 | "Connection: keep-alive\r\n" |
| 8450 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8451 | }; |
| 8452 | |
| 8453 | // Lastly, the server responds with the actual content. |
| 8454 | MockRead data_reads[] = { |
| 8455 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8456 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8457 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8458 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8459 | }; |
| 8460 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8461 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8462 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8463 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8464 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8465 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8466 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8467 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8468 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8469 | |
| 8470 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8471 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8472 | } |
| 8473 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8474 | TEST_F(HttpNetworkTransactionTest, BuildRequest_HeadContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8475 | HttpRequestInfo request; |
| 8476 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8477 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8478 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8479 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8480 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8481 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8482 | MockWrite data_writes[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 8483 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 8484 | "Host: www.example.org\r\n" |
| 8485 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8486 | }; |
| 8487 | |
| 8488 | // Lastly, the server responds with the actual content. |
| 8489 | MockRead data_reads[] = { |
| 8490 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8491 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8492 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8493 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8494 | }; |
| 8495 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8496 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8497 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8498 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8499 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8500 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8501 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8502 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8503 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8504 | |
| 8505 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8506 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8507 | } |
| 8508 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8509 | TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlNoCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8510 | HttpRequestInfo request; |
| 8511 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8512 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8513 | request.load_flags = LOAD_BYPASS_CACHE; |
| 8514 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8515 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8516 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8517 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8518 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8519 | MockWrite( |
| 8520 | "GET / HTTP/1.1\r\n" |
| 8521 | "Host: www.example.org\r\n" |
| 8522 | "Connection: keep-alive\r\n" |
| 8523 | "Pragma: no-cache\r\n" |
| 8524 | "Cache-Control: no-cache\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8525 | }; |
| 8526 | |
| 8527 | // Lastly, the server responds with the actual content. |
| 8528 | MockRead data_reads[] = { |
| 8529 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8530 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8531 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8532 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8533 | }; |
| 8534 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8535 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8536 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8537 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8538 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8539 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8540 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8541 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8542 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8543 | |
| 8544 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8545 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8546 | } |
| 8547 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8548 | TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlValidateCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8549 | HttpRequestInfo request; |
| 8550 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8551 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8552 | request.load_flags = LOAD_VALIDATE_CACHE; |
| 8553 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8554 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8555 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8556 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8557 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8558 | MockWrite( |
| 8559 | "GET / HTTP/1.1\r\n" |
| 8560 | "Host: www.example.org\r\n" |
| 8561 | "Connection: keep-alive\r\n" |
| 8562 | "Cache-Control: max-age=0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8563 | }; |
| 8564 | |
| 8565 | // Lastly, the server responds with the actual content. |
| 8566 | MockRead data_reads[] = { |
| 8567 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8568 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8569 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8570 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8571 | }; |
| 8572 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8573 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8574 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8575 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8576 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8577 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8578 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8579 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8580 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8581 | |
| 8582 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8583 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8584 | } |
| 8585 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8586 | TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeaders) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8587 | HttpRequestInfo request; |
| 8588 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8589 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 8590 | request.extra_headers.SetHeader("FooHeader", "Bar"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8591 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8592 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8593 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8594 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8595 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8596 | MockWrite( |
| 8597 | "GET / HTTP/1.1\r\n" |
| 8598 | "Host: www.example.org\r\n" |
| 8599 | "Connection: keep-alive\r\n" |
| 8600 | "FooHeader: Bar\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8601 | }; |
| 8602 | |
| 8603 | // Lastly, the server responds with the actual content. |
| 8604 | MockRead data_reads[] = { |
| 8605 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8606 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8607 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8608 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8609 | }; |
| 8610 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8611 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8612 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8613 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8614 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8615 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8616 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8617 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8618 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8619 | |
| 8620 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8621 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8622 | } |
| 8623 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8624 | TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeadersStripped) { |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8625 | HttpRequestInfo request; |
| 8626 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8627 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 8628 | request.extra_headers.SetHeader("referer", "www.foo.com"); |
| 8629 | request.extra_headers.SetHeader("hEllo", "Kitty"); |
| 8630 | request.extra_headers.SetHeader("FoO", "bar"); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8631 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8632 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8633 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8634 | |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8635 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8636 | MockWrite( |
| 8637 | "GET / HTTP/1.1\r\n" |
| 8638 | "Host: www.example.org\r\n" |
| 8639 | "Connection: keep-alive\r\n" |
| 8640 | "referer: www.foo.com\r\n" |
| 8641 | "hEllo: Kitty\r\n" |
| 8642 | "FoO: bar\r\n\r\n"), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8643 | }; |
| 8644 | |
| 8645 | // Lastly, the server responds with the actual content. |
| 8646 | MockRead data_reads[] = { |
| 8647 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8648 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8649 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8650 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8651 | }; |
| 8652 | |
| 8653 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8654 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8655 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8656 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8657 | TestCompletionCallback callback; |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8658 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8659 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8660 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8661 | |
| 8662 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8663 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8664 | } |
| 8665 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8666 | TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8667 | HttpRequestInfo request; |
| 8668 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8669 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8670 | request.load_flags = 0; |
| 8671 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8672 | session_deps_.proxy_service = |
| 8673 | ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8674 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8675 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8676 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8677 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8678 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8679 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8680 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 8681 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 8682 | |
| 8683 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8684 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
| 8685 | MockWrite( |
| 8686 | "GET / HTTP/1.1\r\n" |
| 8687 | "Host: www.example.org\r\n" |
| 8688 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8689 | |
| 8690 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8691 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8692 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8693 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 8694 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8695 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8696 | }; |
| 8697 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8698 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8699 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8700 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8701 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8702 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8703 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8704 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8705 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8706 | |
| 8707 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8708 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8709 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8710 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8711 | ASSERT_TRUE(response); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8712 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8713 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8714 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8715 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8716 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 8717 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8718 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8719 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8720 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8721 | EXPECT_EQ("Payload", response_text); |
| 8722 | } |
| 8723 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8724 | TEST_F(HttpNetworkTransactionTest, SOCKS4_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8725 | HttpRequestInfo request; |
| 8726 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8727 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8728 | request.load_flags = 0; |
| 8729 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8730 | session_deps_.proxy_service = |
| 8731 | ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8732 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8733 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8734 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8735 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8736 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8737 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8738 | unsigned char write_buffer[] = { 0x04, 0x01, 0x01, 0xBB, 127, 0, 0, 1, 0 }; |
| 8739 | unsigned char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 8740 | |
| 8741 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8742 | MockWrite(ASYNC, reinterpret_cast<char*>(write_buffer), |
| 8743 | arraysize(write_buffer)), |
| 8744 | MockWrite( |
| 8745 | "GET / HTTP/1.1\r\n" |
| 8746 | "Host: www.example.org\r\n" |
| 8747 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8748 | |
| 8749 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 8750 | MockRead(ASYNC, reinterpret_cast<char*>(read_buffer), |
| 8751 | arraysize(read_buffer)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8752 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8753 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 8754 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8755 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8756 | }; |
| 8757 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8758 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8759 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8760 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8761 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8762 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8763 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8764 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8765 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8766 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8767 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8768 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8769 | |
| 8770 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8771 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8772 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8773 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8774 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8775 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8776 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 8777 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8778 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8779 | ASSERT_TRUE(response); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8780 | |
| 8781 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8782 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8783 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8784 | EXPECT_EQ("Payload", response_text); |
| 8785 | } |
| 8786 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8787 | TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET_no_PAC) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8788 | HttpRequestInfo request; |
| 8789 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8790 | request.url = GURL("http://www.example.org/"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8791 | request.load_flags = 0; |
| 8792 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8793 | session_deps_.proxy_service = |
| 8794 | ProxyService::CreateFixed("socks4://myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8795 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8796 | session_deps_.net_log = &net_log; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8797 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8798 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8799 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8800 | |
| 8801 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 8802 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 8803 | |
| 8804 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8805 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
| 8806 | MockWrite( |
| 8807 | "GET / HTTP/1.1\r\n" |
| 8808 | "Host: www.example.org\r\n" |
| 8809 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8810 | |
| 8811 | MockRead data_reads[] = { |
| 8812 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
| 8813 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8814 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 8815 | MockRead("Payload"), |
| 8816 | MockRead(SYNCHRONOUS, OK) |
| 8817 | }; |
| 8818 | |
| 8819 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8820 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8821 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8822 | |
| 8823 | TestCompletionCallback callback; |
| 8824 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8825 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8826 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8827 | |
| 8828 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8829 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8830 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8831 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8832 | ASSERT_TRUE(response); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8833 | |
| 8834 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8835 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8836 | TestLoadTimingNotReused(load_timing_info, |
| 8837 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 8838 | |
| 8839 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8840 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8841 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8842 | EXPECT_EQ("Payload", response_text); |
| 8843 | } |
| 8844 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8845 | TEST_F(HttpNetworkTransactionTest, SOCKS5_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8846 | HttpRequestInfo request; |
| 8847 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8848 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8849 | request.load_flags = 0; |
| 8850 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8851 | session_deps_.proxy_service = |
| 8852 | ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8853 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8854 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8855 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8856 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8857 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8858 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8859 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 8860 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 8861 | const char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8862 | 0x05, // Version |
| 8863 | 0x01, // Command (CONNECT) |
| 8864 | 0x00, // Reserved. |
| 8865 | 0x03, // Address type (DOMAINNAME). |
| 8866 | 0x0F, // Length of domain (15) |
| 8867 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 8868 | '.', 'o', 'r', 'g', 0x00, 0x50, // 16-bit port (80) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 8869 | }; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8870 | const char kSOCKS5OkResponse[] = |
| 8871 | { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; |
| 8872 | |
| 8873 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8874 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 8875 | MockWrite(ASYNC, kSOCKS5OkRequest, arraysize(kSOCKS5OkRequest)), |
| 8876 | MockWrite( |
| 8877 | "GET / HTTP/1.1\r\n" |
| 8878 | "Host: www.example.org\r\n" |
| 8879 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8880 | |
| 8881 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 8882 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 8883 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8884 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8885 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 8886 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8887 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8888 | }; |
| 8889 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8890 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8891 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8892 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8893 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8894 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8895 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8896 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8897 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8898 | |
| 8899 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8900 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8901 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8902 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8903 | ASSERT_TRUE(response); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8904 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8905 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8906 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8907 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8908 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 8909 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8910 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8911 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8912 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8913 | EXPECT_EQ("Payload", response_text); |
| 8914 | } |
| 8915 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8916 | TEST_F(HttpNetworkTransactionTest, SOCKS5_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8917 | HttpRequestInfo request; |
| 8918 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8919 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8920 | request.load_flags = 0; |
| 8921 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8922 | session_deps_.proxy_service = |
| 8923 | ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8924 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8925 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8926 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8927 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8928 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8929 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8930 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 8931 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 8932 | const unsigned char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8933 | 0x05, // Version |
| 8934 | 0x01, // Command (CONNECT) |
| 8935 | 0x00, // Reserved. |
| 8936 | 0x03, // Address type (DOMAINNAME). |
| 8937 | 0x0F, // Length of domain (15) |
| 8938 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 8939 | '.', 'o', 'r', 'g', 0x01, 0xBB, // 16-bit port (443) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 8940 | }; |
| 8941 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8942 | const char kSOCKS5OkResponse[] = |
| 8943 | { 0x05, 0x00, 0x00, 0x01, 0, 0, 0, 0, 0x00, 0x00 }; |
| 8944 | |
| 8945 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8946 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 8947 | MockWrite(ASYNC, reinterpret_cast<const char*>(kSOCKS5OkRequest), |
| 8948 | arraysize(kSOCKS5OkRequest)), |
| 8949 | MockWrite( |
| 8950 | "GET / HTTP/1.1\r\n" |
| 8951 | "Host: www.example.org\r\n" |
| 8952 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8953 | |
| 8954 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 8955 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 8956 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8957 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8958 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 8959 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8960 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8961 | }; |
| 8962 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8963 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8964 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8965 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8966 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8967 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8968 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8969 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8970 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8971 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8972 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8973 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8974 | |
| 8975 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8976 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8977 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8978 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8979 | ASSERT_TRUE(response); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8980 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8981 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8982 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8983 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8984 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 8985 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8986 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8987 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8988 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8989 | EXPECT_EQ("Payload", response_text); |
| 8990 | } |
| 8991 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 8992 | namespace { |
| 8993 | |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 8994 | // Tests that for connection endpoints the group names are correctly set. |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8995 | |
| 8996 | struct GroupNameTest { |
| 8997 | std::string proxy_server; |
| 8998 | std::string url; |
| 8999 | std::string expected_group_name; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9000 | bool ssl; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9001 | }; |
| 9002 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9003 | std::unique_ptr<HttpNetworkSession> SetupSessionForGroupNameTests( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9004 | SpdySessionDependencies* session_deps_) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9005 | std::unique_ptr<HttpNetworkSession> session(CreateSession(session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9006 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 9007 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 9008 | session->http_server_properties(); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9009 | AlternativeService alternative_service( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 9010 | AlternateProtocolFromNextProto(kProtoHTTP2), "", 444); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9011 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9012 | http_server_properties->SetAlternativeService( |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 9013 | url::SchemeHostPort("https", "host.with.alternate", 443), |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 9014 | alternative_service, expiration); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9015 | |
| 9016 | return session; |
| 9017 | } |
| 9018 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9019 | int GroupNameTransactionHelper(const std::string& url, |
| 9020 | HttpNetworkSession* session) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9021 | HttpRequestInfo request; |
| 9022 | request.method = "GET"; |
| 9023 | request.url = GURL(url); |
| 9024 | request.load_flags = 0; |
| 9025 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9026 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9027 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9028 | TestCompletionCallback callback; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9029 | |
| 9030 | // We do not complete this request, the dtor will clean the transaction up. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9031 | return trans.Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9032 | } |
| 9033 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9034 | } // namespace |
| 9035 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9036 | TEST_F(HttpNetworkTransactionTest, GroupNameForDirectConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9037 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9038 | { |
| 9039 | "", // unused |
| 9040 | "http://www.example.org/direct", |
| 9041 | "www.example.org:80", |
| 9042 | false, |
| 9043 | }, |
| 9044 | { |
| 9045 | "", // unused |
| 9046 | "http://[2001:1418:13:1::25]/direct", |
| 9047 | "[2001:1418:13:1::25]:80", |
| 9048 | false, |
| 9049 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9050 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9051 | // SSL Tests |
| 9052 | { |
| 9053 | "", // unused |
| 9054 | "https://www.example.org/direct_ssl", |
| 9055 | "ssl/www.example.org:443", |
| 9056 | true, |
| 9057 | }, |
| 9058 | { |
| 9059 | "", // unused |
| 9060 | "https://[2001:1418:13:1::25]/direct", |
| 9061 | "ssl/[2001:1418:13:1::25]:443", |
| 9062 | true, |
| 9063 | }, |
| 9064 | { |
| 9065 | "", // unused |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 9066 | "https://host.with.alternate/direct", |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9067 | "ssl/host.with.alternate:443", |
| 9068 | true, |
| 9069 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9070 | }; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9071 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 9072 | for (size_t i = 0; i < arraysize(tests); ++i) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9073 | session_deps_.proxy_service = |
| 9074 | ProxyService::CreateFixed(tests[i].proxy_server); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9075 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 9076 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9077 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9078 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 9079 | CaptureGroupNameTransportSocketPool* transport_conn_pool = |
| 9080 | new CaptureGroupNameTransportSocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 9081 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 9082 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9083 | std::unique_ptr<MockClientSocketPoolManager> mock_pool_manager( |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 9084 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 9085 | mock_pool_manager->SetTransportSocketPool(transport_conn_pool); |
| 9086 | mock_pool_manager->SetSSLSocketPool(ssl_conn_pool); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 9087 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9088 | |
| 9089 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9090 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9091 | if (tests[i].ssl) |
| 9092 | EXPECT_EQ(tests[i].expected_group_name, |
| 9093 | ssl_conn_pool->last_group_name_received()); |
| 9094 | else |
| 9095 | EXPECT_EQ(tests[i].expected_group_name, |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 9096 | transport_conn_pool->last_group_name_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9097 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9098 | } |
| 9099 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9100 | TEST_F(HttpNetworkTransactionTest, GroupNameForHTTPProxyConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9101 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9102 | { |
| 9103 | "http_proxy", |
| 9104 | "http://www.example.org/http_proxy_normal", |
| 9105 | "www.example.org:80", |
| 9106 | false, |
| 9107 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9108 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9109 | // SSL Tests |
| 9110 | { |
| 9111 | "http_proxy", |
| 9112 | "https://www.example.org/http_connect_ssl", |
| 9113 | "ssl/www.example.org:443", |
| 9114 | true, |
| 9115 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 9116 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9117 | { |
| 9118 | "http_proxy", |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 9119 | "https://host.with.alternate/direct", |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9120 | "ssl/host.with.alternate:443", |
| 9121 | true, |
| 9122 | }, |
[email protected] | 4549925 | 2013-01-23 17:12:56 | [diff] [blame] | 9123 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9124 | { |
| 9125 | "http_proxy", |
| 9126 | "ftp://ftp.google.com/http_proxy_normal", |
| 9127 | "ftp/ftp.google.com:21", |
| 9128 | false, |
| 9129 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9130 | }; |
| 9131 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 9132 | for (size_t i = 0; i < arraysize(tests); ++i) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9133 | session_deps_.proxy_service = |
| 9134 | ProxyService::CreateFixed(tests[i].proxy_server); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9135 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 9136 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9137 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9138 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9139 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9140 | HostPortPair proxy_host("http_proxy", 80); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 9141 | CaptureGroupNameHttpProxySocketPool* http_proxy_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 9142 | new CaptureGroupNameHttpProxySocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 9143 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 9144 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 9145 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9146 | std::unique_ptr<MockClientSocketPoolManager> mock_pool_manager( |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 9147 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 9148 | mock_pool_manager->SetSocketPoolForHTTPProxy(proxy_host, http_proxy_pool); |
| 9149 | mock_pool_manager->SetSocketPoolForSSLWithProxy(proxy_host, ssl_conn_pool); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 9150 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9151 | |
| 9152 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9153 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9154 | if (tests[i].ssl) |
| 9155 | EXPECT_EQ(tests[i].expected_group_name, |
| 9156 | ssl_conn_pool->last_group_name_received()); |
| 9157 | else |
| 9158 | EXPECT_EQ(tests[i].expected_group_name, |
| 9159 | http_proxy_pool->last_group_name_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9160 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9161 | } |
| 9162 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9163 | TEST_F(HttpNetworkTransactionTest, GroupNameForSOCKSConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9164 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9165 | { |
| 9166 | "socks4://socks_proxy:1080", |
| 9167 | "http://www.example.org/socks4_direct", |
| 9168 | "socks4/www.example.org:80", |
| 9169 | false, |
| 9170 | }, |
| 9171 | { |
| 9172 | "socks5://socks_proxy:1080", |
| 9173 | "http://www.example.org/socks5_direct", |
| 9174 | "socks5/www.example.org:80", |
| 9175 | false, |
| 9176 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9177 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9178 | // SSL Tests |
| 9179 | { |
| 9180 | "socks4://socks_proxy:1080", |
| 9181 | "https://www.example.org/socks4_ssl", |
| 9182 | "socks4/ssl/www.example.org:443", |
| 9183 | true, |
| 9184 | }, |
| 9185 | { |
| 9186 | "socks5://socks_proxy:1080", |
| 9187 | "https://www.example.org/socks5_ssl", |
| 9188 | "socks5/ssl/www.example.org:443", |
| 9189 | true, |
| 9190 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 9191 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9192 | { |
| 9193 | "socks4://socks_proxy:1080", |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 9194 | "https://host.with.alternate/direct", |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9195 | "socks4/ssl/host.with.alternate:443", |
| 9196 | true, |
| 9197 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9198 | }; |
| 9199 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 9200 | for (size_t i = 0; i < arraysize(tests); ++i) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9201 | session_deps_.proxy_service = |
| 9202 | ProxyService::CreateFixed(tests[i].proxy_server); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9203 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 9204 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 9205 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9206 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9207 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9208 | HostPortPair proxy_host("socks_proxy", 1080); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 9209 | CaptureGroupNameSOCKSSocketPool* socks_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 9210 | new CaptureGroupNameSOCKSSocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 9211 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 9212 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 9213 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9214 | std::unique_ptr<MockClientSocketPoolManager> mock_pool_manager( |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 9215 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 9216 | mock_pool_manager->SetSocketPoolForSOCKSProxy(proxy_host, socks_conn_pool); |
| 9217 | mock_pool_manager->SetSocketPoolForSSLWithProxy(proxy_host, ssl_conn_pool); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 9218 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9219 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9220 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9221 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9222 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9223 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9224 | if (tests[i].ssl) |
| 9225 | EXPECT_EQ(tests[i].expected_group_name, |
| 9226 | ssl_conn_pool->last_group_name_received()); |
| 9227 | else |
| 9228 | EXPECT_EQ(tests[i].expected_group_name, |
| 9229 | socks_conn_pool->last_group_name_received()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9230 | } |
| 9231 | } |
| 9232 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9233 | TEST_F(HttpNetworkTransactionTest, ReconsiderProxyAfterFailedConnection) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9234 | HttpRequestInfo request; |
| 9235 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9236 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9237 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9238 | session_deps_.proxy_service = |
| 9239 | ProxyService::CreateFixed("myproxy:70;foobar:80"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 9240 | |
[email protected] | 6971906 | 2010-01-05 20:09:21 | [diff] [blame] | 9241 | // This simulates failure resolving all hostnames; that means we will fail |
| 9242 | // connecting to both proxies (myproxy:70 and foobar:80). |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9243 | session_deps_.host_resolver->rules()->AddSimulatedFailure("*"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 9244 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9245 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9246 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 9247 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9248 | TestCompletionCallback callback; |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 9249 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9250 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9251 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 9252 | |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 9253 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9254 | EXPECT_THAT(rv, IsError(ERR_PROXY_CONNECTION_FAILED)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 9255 | } |
| 9256 | |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9257 | // Base test to make sure that when the load flags for a request specify to |
| 9258 | // bypass the cache, the DNS cache is not used. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9259 | void HttpNetworkTransactionTest::BypassHostCacheOnRefreshHelper( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9260 | int load_flags) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9261 | // Issue a request, asking to bypass the cache(s). |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 9262 | HttpRequestInfo request_info; |
| 9263 | request_info.method = "GET"; |
| 9264 | request_info.load_flags = load_flags; |
| 9265 | request_info.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9266 | |
[email protected] | a2c2fb9 | 2009-07-18 07:31:04 | [diff] [blame] | 9267 | // Select a host resolver that does caching. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9268 | session_deps_.host_resolver.reset(new MockCachingHostResolver); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 9269 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9270 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9271 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9272 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9273 | // 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] | 9274 | AddressList addrlist; |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 9275 | TestCompletionCallback callback; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 9276 | std::unique_ptr<HostResolver::Request> request1; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9277 | int rv = session_deps_.host_resolver->Resolve( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9278 | HostResolver::RequestInfo(HostPortPair("www.example.org", 80)), |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 9279 | DEFAULT_PRIORITY, &addrlist, callback.callback(), &request1, |
| 9280 | BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9281 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 9282 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9283 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9284 | |
| 9285 | // Verify that it was added to host cache, by doing a subsequent async lookup |
| 9286 | // and confirming it completes synchronously. |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 9287 | std::unique_ptr<HostResolver::Request> request2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9288 | rv = session_deps_.host_resolver->Resolve( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9289 | HostResolver::RequestInfo(HostPortPair("www.example.org", 80)), |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 9290 | DEFAULT_PRIORITY, &addrlist, callback.callback(), &request2, |
| 9291 | BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9292 | ASSERT_THAT(rv, IsOk()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9293 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9294 | // 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] | 9295 | // we can tell if the next lookup hit the cache, or the "network". |
| 9296 | // (cache --> success, "network" --> failure). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9297 | session_deps_.host_resolver->rules()->AddSimulatedFailure("www.example.org"); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9298 | |
| 9299 | // Connect up a mock socket which will fail with ERR_UNEXPECTED during the |
| 9300 | // 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] | 9301 | MockRead data_reads[] = { MockRead(SYNCHRONOUS, ERR_UNEXPECTED) }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9302 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9303 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9304 | |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9305 | // Run the request. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9306 | rv = trans.Start(&request_info, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9307 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9308 | rv = callback.WaitForResult(); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9309 | |
| 9310 | // If we bypassed the cache, we would have gotten a failure while resolving |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9311 | // "www.example.org". |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9312 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9313 | } |
| 9314 | |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9315 | // There are multiple load flags that should trigger the host cache bypass. |
| 9316 | // Test each in isolation: |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9317 | TEST_F(HttpNetworkTransactionTest, BypassHostCacheOnRefresh1) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9318 | BypassHostCacheOnRefreshHelper(LOAD_BYPASS_CACHE); |
| 9319 | } |
| 9320 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9321 | TEST_F(HttpNetworkTransactionTest, BypassHostCacheOnRefresh2) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9322 | BypassHostCacheOnRefreshHelper(LOAD_VALIDATE_CACHE); |
| 9323 | } |
| 9324 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9325 | TEST_F(HttpNetworkTransactionTest, BypassHostCacheOnRefresh3) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9326 | BypassHostCacheOnRefreshHelper(LOAD_DISABLE_CACHE); |
| 9327 | } |
| 9328 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9329 | // Make sure we can handle an error when writing the request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9330 | TEST_F(HttpNetworkTransactionTest, RequestWriteError) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9331 | HttpRequestInfo request; |
| 9332 | request.method = "GET"; |
| 9333 | request.url = GURL("http://www.foo.com/"); |
| 9334 | request.load_flags = 0; |
| 9335 | |
| 9336 | MockWrite write_failure[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9337 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9338 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9339 | StaticSocketDataProvider data(NULL, 0, |
| 9340 | write_failure, arraysize(write_failure)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9341 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9342 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9343 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9344 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9345 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9346 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9347 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9348 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9349 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9350 | |
| 9351 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9352 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 9353 | |
| 9354 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9355 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 9356 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9357 | } |
| 9358 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9359 | // Check that a connection closed after the start of the headers finishes ok. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9360 | TEST_F(HttpNetworkTransactionTest, ConnectionClosedAfterStartOfHeaders) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9361 | HttpRequestInfo request; |
| 9362 | request.method = "GET"; |
| 9363 | request.url = GURL("http://www.foo.com/"); |
| 9364 | request.load_flags = 0; |
| 9365 | |
| 9366 | MockRead data_reads[] = { |
| 9367 | MockRead("HTTP/1."), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9368 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9369 | }; |
| 9370 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9371 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9372 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9373 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9374 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9375 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9376 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9377 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9378 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9379 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9380 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9381 | |
| 9382 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9383 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9384 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9385 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9386 | ASSERT_TRUE(response); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9387 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9388 | EXPECT_TRUE(response->headers); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9389 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 9390 | |
| 9391 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9392 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9393 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9394 | EXPECT_EQ("", response_data); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 9395 | |
| 9396 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9397 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 9398 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9399 | } |
| 9400 | |
| 9401 | // Make sure that a dropped connection while draining the body for auth |
| 9402 | // restart does the right thing. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9403 | TEST_F(HttpNetworkTransactionTest, DrainResetOK) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9404 | HttpRequestInfo request; |
| 9405 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9406 | request.url = GURL("http://www.example.org/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9407 | request.load_flags = 0; |
| 9408 | |
| 9409 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9410 | MockWrite( |
| 9411 | "GET / HTTP/1.1\r\n" |
| 9412 | "Host: www.example.org\r\n" |
| 9413 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9414 | }; |
| 9415 | |
| 9416 | MockRead data_reads1[] = { |
| 9417 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 9418 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 9419 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9420 | MockRead("Content-Length: 14\r\n\r\n"), |
| 9421 | MockRead("Unauth"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9422 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9423 | }; |
| 9424 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9425 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 9426 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9427 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9428 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9429 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9430 | // be issuing -- the final header line contains the credentials. |
| 9431 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9432 | MockWrite( |
| 9433 | "GET / HTTP/1.1\r\n" |
| 9434 | "Host: www.example.org\r\n" |
| 9435 | "Connection: keep-alive\r\n" |
| 9436 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9437 | }; |
| 9438 | |
| 9439 | // Lastly, the server responds with the actual content. |
| 9440 | MockRead data_reads2[] = { |
| 9441 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9442 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9443 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9444 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9445 | }; |
| 9446 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9447 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 9448 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9449 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9450 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9451 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9452 | TestCompletionCallback callback1; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9453 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9454 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 9455 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9456 | int rv = trans.Start(&request, callback1.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9457 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9458 | |
| 9459 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9460 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9461 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9462 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9463 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9464 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9465 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9466 | TestCompletionCallback callback2; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9467 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9468 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9469 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9470 | |
| 9471 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9472 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9473 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9474 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9475 | ASSERT_TRUE(response); |
| 9476 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9477 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9478 | } |
| 9479 | |
| 9480 | // Test HTTPS connections going through a proxy that sends extra data. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9481 | TEST_F(HttpNetworkTransactionTest, HTTPSViaProxyWithExtraData) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9482 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9483 | |
| 9484 | HttpRequestInfo request; |
| 9485 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9486 | request.url = GURL("https://www.example.org/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9487 | request.load_flags = 0; |
| 9488 | |
| 9489 | MockRead proxy_reads[] = { |
| 9490 | MockRead("HTTP/1.0 200 Connected\r\n\r\nExtra data"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9491 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9492 | }; |
| 9493 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9494 | StaticSocketDataProvider data(proxy_reads, arraysize(proxy_reads), NULL, 0); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9495 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9496 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9497 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9498 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9499 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9500 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9501 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9502 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9503 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9504 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9505 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9506 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9507 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9508 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9509 | |
| 9510 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9511 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9512 | } |
| 9513 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9514 | TEST_F(HttpNetworkTransactionTest, LargeContentLengthThenClose) { |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9515 | HttpRequestInfo request; |
| 9516 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9517 | request.url = GURL("http://www.example.org/"); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9518 | request.load_flags = 0; |
| 9519 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9520 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9521 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9522 | |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 9523 | MockRead data_reads[] = { |
| 9524 | 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] | 9525 | MockRead(SYNCHRONOUS, OK), |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 9526 | }; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9527 | |
| 9528 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9529 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9530 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9531 | TestCompletionCallback callback; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9532 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9533 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9534 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9535 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9536 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9537 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9538 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9539 | ASSERT_TRUE(response); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9540 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9541 | EXPECT_TRUE(response->headers); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9542 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 9543 | |
| 9544 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9545 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9546 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 9547 | } |
| 9548 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9549 | TEST_F(HttpNetworkTransactionTest, UploadFileSmallerThanLength) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 9550 | base::FilePath temp_file_path; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 9551 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file_path)); |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 9552 | const uint64_t kFakeSize = 100000; // file is actually blank |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 9553 | UploadFileElementReader::ScopedOverridingContentLengthForTests |
| 9554 | overriding_content_length(kFakeSize); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9555 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9556 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 9557 | element_readers.push_back(base::MakeUnique<UploadFileElementReader>( |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 9558 | base::ThreadTaskRunnerHandle::Get().get(), temp_file_path, 0, |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 9559 | std::numeric_limits<uint64_t>::max(), base::Time())); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 9560 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9561 | |
| 9562 | HttpRequestInfo request; |
| 9563 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9564 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9565 | request.upload_data_stream = &upload_data_stream; |
| 9566 | request.load_flags = 0; |
| 9567 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9568 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9569 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9570 | |
| 9571 | MockRead data_reads[] = { |
| 9572 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 9573 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9574 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9575 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9576 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9577 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9578 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9579 | TestCompletionCallback callback; |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9580 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9581 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9582 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9583 | |
| 9584 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9585 | EXPECT_THAT(rv, IsError(ERR_UPLOAD_FILE_CHANGED)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9586 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9587 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9588 | ASSERT_TRUE(response); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9589 | |
maksim.sisov | e869bf5 | 2016-06-23 17:11:52 | [diff] [blame] | 9590 | EXPECT_FALSE(response->headers); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9591 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 9592 | base::DeleteFile(temp_file_path, false); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9593 | } |
| 9594 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9595 | TEST_F(HttpNetworkTransactionTest, UploadUnreadableFile) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 9596 | base::FilePath temp_file; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 9597 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9598 | std::string temp_file_content("Unreadable file."); |
[email protected] | e5c2a22e | 2014-03-06 20:42:30 | [diff] [blame] | 9599 | ASSERT_TRUE(base::WriteFile(temp_file, temp_file_content.c_str(), |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9600 | temp_file_content.length())); |
[email protected] | 92be8eb | 2014-08-07 22:57:11 | [diff] [blame] | 9601 | ASSERT_TRUE(base::MakeFileUnreadable(temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9602 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9603 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 9604 | element_readers.push_back(base::MakeUnique<UploadFileElementReader>( |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 9605 | base::ThreadTaskRunnerHandle::Get().get(), temp_file, 0, |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 9606 | std::numeric_limits<uint64_t>::max(), base::Time())); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 9607 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9608 | |
| 9609 | HttpRequestInfo request; |
| 9610 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9611 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9612 | request.upload_data_stream = &upload_data_stream; |
| 9613 | request.load_flags = 0; |
| 9614 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 9615 | // If we try to upload an unreadable file, the transaction should fail. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9616 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9617 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9618 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 9619 | StaticSocketDataProvider data(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9620 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9621 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9622 | TestCompletionCallback callback; |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9623 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9624 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9625 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9626 | |
| 9627 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9628 | EXPECT_THAT(rv, IsError(ERR_ACCESS_DENIED)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9629 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 9630 | base::DeleteFile(temp_file, false); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9631 | } |
| 9632 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9633 | TEST_F(HttpNetworkTransactionTest, CancelDuringInitRequestBody) { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9634 | class FakeUploadElementReader : public UploadElementReader { |
| 9635 | public: |
| 9636 | FakeUploadElementReader() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9637 | ~FakeUploadElementReader() override {} |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9638 | |
| 9639 | const CompletionCallback& callback() const { return callback_; } |
| 9640 | |
| 9641 | // UploadElementReader overrides: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9642 | int Init(const CompletionCallback& callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9643 | callback_ = callback; |
| 9644 | return ERR_IO_PENDING; |
| 9645 | } |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 9646 | uint64_t GetContentLength() const override { return 0; } |
| 9647 | uint64_t BytesRemaining() const override { return 0; } |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9648 | int Read(IOBuffer* buf, |
| 9649 | int buf_length, |
| 9650 | const CompletionCallback& callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9651 | return ERR_FAILED; |
| 9652 | } |
| 9653 | |
| 9654 | private: |
| 9655 | CompletionCallback callback_; |
| 9656 | }; |
| 9657 | |
| 9658 | FakeUploadElementReader* fake_reader = new FakeUploadElementReader; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9659 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
| 9660 | element_readers.push_back(base::WrapUnique(fake_reader)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 9661 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9662 | |
| 9663 | HttpRequestInfo request; |
| 9664 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9665 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9666 | request.upload_data_stream = &upload_data_stream; |
| 9667 | request.load_flags = 0; |
| 9668 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9669 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9670 | std::unique_ptr<HttpNetworkTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 9671 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9672 | |
| 9673 | StaticSocketDataProvider data; |
| 9674 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9675 | |
| 9676 | TestCompletionCallback callback; |
| 9677 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9678 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 9679 | base::RunLoop().RunUntilIdle(); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9680 | |
| 9681 | // Transaction is pending on request body initialization. |
| 9682 | ASSERT_FALSE(fake_reader->callback().is_null()); |
| 9683 | |
| 9684 | // Return Init()'s result after the transaction gets destroyed. |
| 9685 | trans.reset(); |
| 9686 | fake_reader->callback().Run(OK); // Should not crash. |
| 9687 | } |
| 9688 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9689 | // Tests that changes to Auth realms are treated like auth rejections. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9690 | TEST_F(HttpNetworkTransactionTest, ChangeAuthRealms) { |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9691 | HttpRequestInfo request; |
| 9692 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9693 | request.url = GURL("http://www.example.org/"); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9694 | request.load_flags = 0; |
| 9695 | |
| 9696 | // First transaction will request a resource and receive a Basic challenge |
| 9697 | // with realm="first_realm". |
| 9698 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9699 | MockWrite( |
| 9700 | "GET / HTTP/1.1\r\n" |
| 9701 | "Host: www.example.org\r\n" |
| 9702 | "Connection: keep-alive\r\n" |
| 9703 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9704 | }; |
| 9705 | MockRead data_reads1[] = { |
| 9706 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 9707 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 9708 | "\r\n"), |
| 9709 | }; |
| 9710 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9711 | // After calling trans.RestartWithAuth(), provide an Authentication header |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9712 | // for first_realm. The server will reject and provide a challenge with |
| 9713 | // second_realm. |
| 9714 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9715 | MockWrite( |
| 9716 | "GET / HTTP/1.1\r\n" |
| 9717 | "Host: www.example.org\r\n" |
| 9718 | "Connection: keep-alive\r\n" |
| 9719 | "Authorization: Basic Zmlyc3Q6YmF6\r\n" |
| 9720 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9721 | }; |
| 9722 | MockRead data_reads2[] = { |
| 9723 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 9724 | "WWW-Authenticate: Basic realm=\"second_realm\"\r\n" |
| 9725 | "\r\n"), |
| 9726 | }; |
| 9727 | |
| 9728 | // This again fails, and goes back to first_realm. Make sure that the |
| 9729 | // entry is removed from cache. |
| 9730 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9731 | MockWrite( |
| 9732 | "GET / HTTP/1.1\r\n" |
| 9733 | "Host: www.example.org\r\n" |
| 9734 | "Connection: keep-alive\r\n" |
| 9735 | "Authorization: Basic c2Vjb25kOmZvdQ==\r\n" |
| 9736 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9737 | }; |
| 9738 | MockRead data_reads3[] = { |
| 9739 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 9740 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 9741 | "\r\n"), |
| 9742 | }; |
| 9743 | |
| 9744 | // Try one last time (with the correct password) and get the resource. |
| 9745 | MockWrite data_writes4[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9746 | MockWrite( |
| 9747 | "GET / HTTP/1.1\r\n" |
| 9748 | "Host: www.example.org\r\n" |
| 9749 | "Connection: keep-alive\r\n" |
| 9750 | "Authorization: Basic Zmlyc3Q6YmFy\r\n" |
| 9751 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9752 | }; |
| 9753 | MockRead data_reads4[] = { |
| 9754 | MockRead("HTTP/1.1 200 OK\r\n" |
| 9755 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 9756 | "Content-Length: 5\r\n" |
| 9757 | "\r\n" |
| 9758 | "hello"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9759 | }; |
| 9760 | |
| 9761 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 9762 | data_writes1, arraysize(data_writes1)); |
| 9763 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 9764 | data_writes2, arraysize(data_writes2)); |
| 9765 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 9766 | data_writes3, arraysize(data_writes3)); |
| 9767 | StaticSocketDataProvider data4(data_reads4, arraysize(data_reads4), |
| 9768 | data_writes4, arraysize(data_writes4)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9769 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 9770 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 9771 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 9772 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9773 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9774 | TestCompletionCallback callback1; |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9775 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9776 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9777 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 9778 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9779 | // Issue the first request with Authorize headers. There should be a |
| 9780 | // password prompt for first_realm waiting to be filled in after the |
| 9781 | // transaction completes. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9782 | int rv = trans.Start(&request, callback1.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9783 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9784 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9785 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9786 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9787 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9788 | const AuthChallengeInfo* challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9789 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9790 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 9791 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9792 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 9793 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9794 | |
| 9795 | // Issue the second request with an incorrect password. There should be a |
| 9796 | // password prompt for second_realm waiting to be filled in after the |
| 9797 | // transaction completes. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9798 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9799 | rv = trans.RestartWithAuth(AuthCredentials(kFirst, kBaz), |
| 9800 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9801 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9802 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9803 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9804 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9805 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9806 | challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9807 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9808 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 9809 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9810 | EXPECT_EQ("second_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 9811 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9812 | |
| 9813 | // Issue the third request with another incorrect password. There should be |
| 9814 | // a password prompt for first_realm waiting to be filled in. If the password |
| 9815 | // prompt is not present, it indicates that the HttpAuthCacheEntry for |
| 9816 | // first_realm was not correctly removed. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9817 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9818 | rv = trans.RestartWithAuth(AuthCredentials(kSecond, kFou), |
| 9819 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9820 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9821 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9822 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9823 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9824 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9825 | challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9826 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9827 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 9828 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9829 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 9830 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9831 | |
| 9832 | // Issue the fourth request with the correct password and username. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9833 | TestCompletionCallback callback4; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9834 | rv = trans.RestartWithAuth(AuthCredentials(kFirst, kBar), |
| 9835 | callback4.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9836 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9837 | rv = callback4.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9838 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9839 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9840 | ASSERT_TRUE(response); |
| 9841 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9842 | } |
| 9843 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9844 | TEST_F(HttpNetworkTransactionTest, HonorAlternativeServiceHeader) { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9845 | MockRead data_reads[] = { |
| 9846 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 9847 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9848 | MockRead("\r\n"), |
| 9849 | MockRead("hello world"), |
| 9850 | MockRead(SYNCHRONOUS, OK), |
| 9851 | }; |
| 9852 | |
| 9853 | HttpRequestInfo request; |
| 9854 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 9855 | request.url = GURL("https://www.example.org/"); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9856 | request.load_flags = 0; |
| 9857 | |
| 9858 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9859 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9860 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 9861 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 9862 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 9863 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9864 | TestCompletionCallback callback; |
| 9865 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9866 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9867 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9868 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9869 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9870 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9871 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 9872 | url::SchemeHostPort test_server(request.url); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 9873 | HttpServerProperties* http_server_properties = |
| 9874 | session->http_server_properties(); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9875 | AlternativeServiceVector alternative_service_vector = |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 9876 | http_server_properties->GetAlternativeServices(test_server); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9877 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 9878 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9879 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9880 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9881 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9882 | ASSERT_TRUE(response); |
| 9883 | ASSERT_TRUE(response->headers); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9884 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9885 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9886 | EXPECT_FALSE(response->was_npn_negotiated); |
| 9887 | |
| 9888 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9889 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9890 | EXPECT_EQ("hello world", response_data); |
| 9891 | |
| 9892 | alternative_service_vector = |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 9893 | http_server_properties->GetAlternativeServices(test_server); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9894 | ASSERT_EQ(1u, alternative_service_vector.size()); |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 9895 | EXPECT_EQ(AlternateProtocolFromNextProto(kProtoHTTP2), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9896 | alternative_service_vector[0].protocol); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 9897 | EXPECT_EQ("mail.example.org", alternative_service_vector[0].host); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9898 | EXPECT_EQ(443, alternative_service_vector[0].port); |
| 9899 | } |
| 9900 | |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 9901 | // Regression test for https://crbug.com/615497. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9902 | TEST_F(HttpNetworkTransactionTest, |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 9903 | DoNotParseAlternativeServiceHeaderOnInsecureRequest) { |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 9904 | MockRead data_reads[] = { |
| 9905 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 9906 | MockRead(kAlternativeServiceHttpHeader), |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 9907 | MockRead("\r\n"), |
| 9908 | MockRead("hello world"), |
| 9909 | MockRead(SYNCHRONOUS, OK), |
| 9910 | }; |
| 9911 | |
| 9912 | HttpRequestInfo request; |
| 9913 | request.method = "GET"; |
| 9914 | request.url = GURL("http://www.example.org/"); |
| 9915 | request.load_flags = 0; |
| 9916 | |
| 9917 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 9918 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9919 | |
| 9920 | TestCompletionCallback callback; |
| 9921 | |
| 9922 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9923 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 9924 | |
| 9925 | url::SchemeHostPort test_server(request.url); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 9926 | HttpServerProperties* http_server_properties = |
| 9927 | session->http_server_properties(); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 9928 | AlternativeServiceVector alternative_service_vector = |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 9929 | http_server_properties->GetAlternativeServices(test_server); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 9930 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 9931 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9932 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9933 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 9934 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 9935 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9936 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 9937 | ASSERT_TRUE(response); |
| 9938 | ASSERT_TRUE(response->headers); |
| 9939 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9940 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9941 | EXPECT_FALSE(response->was_npn_negotiated); |
| 9942 | |
| 9943 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9944 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 9945 | EXPECT_EQ("hello world", response_data); |
| 9946 | |
| 9947 | alternative_service_vector = |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 9948 | http_server_properties->GetAlternativeServices(test_server); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 9949 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 9950 | } |
| 9951 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 9952 | // HTTP/2 Alternative Services should be disabled if alternative service |
| 9953 | // hostname is different from that of origin. |
| 9954 | // TODO(bnc): Remove when https://crbug.com/615413 is fixed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9955 | TEST_F(HttpNetworkTransactionTest, |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 9956 | DisableHTTP2AlternativeServicesWithDifferentHost) { |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 9957 | session_deps_.enable_http2_alternative_service_with_different_host = false; |
| 9958 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 9959 | HttpRequestInfo request; |
| 9960 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 9961 | request.url = GURL("https://www.example.org/"); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 9962 | request.load_flags = 0; |
| 9963 | |
| 9964 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 9965 | StaticSocketDataProvider first_data; |
| 9966 | first_data.set_connect_data(mock_connect); |
| 9967 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 9968 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 9969 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 9970 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 9971 | |
| 9972 | MockRead data_reads[] = { |
| 9973 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 9974 | MockRead(ASYNC, OK), |
| 9975 | }; |
| 9976 | StaticSocketDataProvider second_data(data_reads, arraysize(data_reads), NULL, |
| 9977 | 0); |
| 9978 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 9979 | |
| 9980 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 9981 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 9982 | HttpServerProperties* http_server_properties = |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 9983 | session->http_server_properties(); |
| 9984 | AlternativeService alternative_service( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 9985 | AlternateProtocolFromNextProto(kProtoHTTP2), "different.example.org", |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 9986 | 444); |
| 9987 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 9988 | http_server_properties->SetAlternativeService( |
| 9989 | url::SchemeHostPort(request.url), alternative_service, expiration); |
| 9990 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9991 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 9992 | TestCompletionCallback callback; |
| 9993 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9994 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 9995 | // Alternative service is not used, request fails. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9996 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 9997 | } |
| 9998 | |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 9999 | // Regression test for https://crbug.com/615497: |
| 10000 | // Alternative Services should be disabled for http origin. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10001 | TEST_F(HttpNetworkTransactionTest, |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10002 | DisableAlternativeServicesForInsecureOrigin) { |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10003 | HttpRequestInfo request; |
| 10004 | request.method = "GET"; |
| 10005 | request.url = GURL("http://www.example.org/"); |
| 10006 | request.load_flags = 0; |
| 10007 | |
| 10008 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 10009 | StaticSocketDataProvider first_data; |
| 10010 | first_data.set_connect_data(mock_connect); |
| 10011 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
| 10012 | |
| 10013 | MockRead data_reads[] = { |
| 10014 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 10015 | MockRead(ASYNC, OK), |
| 10016 | }; |
| 10017 | StaticSocketDataProvider second_data(data_reads, arraysize(data_reads), NULL, |
| 10018 | 0); |
| 10019 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 10020 | |
| 10021 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 10022 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10023 | HttpServerProperties* http_server_properties = |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10024 | session->http_server_properties(); |
| 10025 | AlternativeService alternative_service( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 10026 | AlternateProtocolFromNextProto(kProtoHTTP2), "", 444); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10027 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 10028 | http_server_properties->SetAlternativeService( |
| 10029 | url::SchemeHostPort(request.url), alternative_service, expiration); |
| 10030 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10031 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10032 | TestCompletionCallback callback; |
| 10033 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10034 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10035 | // Alternative service is not used, request fails. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10036 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10037 | } |
| 10038 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10039 | TEST_F(HttpNetworkTransactionTest, ClearAlternativeServices) { |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10040 | // Set an alternative service for origin. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10041 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10042 | HttpServerProperties* http_server_properties = |
| 10043 | session->http_server_properties(); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10044 | url::SchemeHostPort test_server("https", "www.example.org", 443); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10045 | AlternativeService alternative_service(QUIC, "", 80); |
| 10046 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10047 | http_server_properties->SetAlternativeService( |
| 10048 | test_server, alternative_service, expiration); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10049 | AlternativeServiceVector alternative_service_vector = |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10050 | http_server_properties->GetAlternativeServices(test_server); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10051 | EXPECT_EQ(1u, alternative_service_vector.size()); |
| 10052 | |
| 10053 | // Send a clear header. |
| 10054 | MockRead data_reads[] = { |
| 10055 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10056 | MockRead("Alt-Svc: clear\r\n"), |
| 10057 | MockRead("\r\n"), |
| 10058 | MockRead("hello world"), |
| 10059 | MockRead(SYNCHRONOUS, OK), |
| 10060 | }; |
| 10061 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), nullptr, 0); |
| 10062 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10063 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10064 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 10065 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10066 | |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10067 | HttpRequestInfo request; |
| 10068 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10069 | request.url = GURL("https://www.example.org/"); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10070 | request.load_flags = 0; |
| 10071 | |
| 10072 | TestCompletionCallback callback; |
| 10073 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10074 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10075 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10076 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10077 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10078 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10079 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10080 | ASSERT_TRUE(response); |
| 10081 | ASSERT_TRUE(response->headers); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10082 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10083 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 10084 | EXPECT_FALSE(response->was_npn_negotiated); |
| 10085 | |
| 10086 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10087 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10088 | EXPECT_EQ("hello world", response_data); |
| 10089 | |
| 10090 | alternative_service_vector = |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10091 | http_server_properties->GetAlternativeServices(test_server); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10092 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 10093 | } |
| 10094 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10095 | TEST_F(HttpNetworkTransactionTest, HonorMultipleAlternativeServiceHeaders) { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10096 | MockRead data_reads[] = { |
| 10097 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 10098 | MockRead("Alt-Svc: h2=\"www.example.com:443\","), |
| 10099 | MockRead("h2=\":1234\"\r\n\r\n"), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10100 | MockRead("hello world"), |
| 10101 | MockRead(SYNCHRONOUS, OK), |
| 10102 | }; |
| 10103 | |
| 10104 | HttpRequestInfo request; |
| 10105 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10106 | request.url = GURL("https://www.example.org/"); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10107 | request.load_flags = 0; |
| 10108 | |
| 10109 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10110 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10111 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10112 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 10113 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10114 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10115 | TestCompletionCallback callback; |
| 10116 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10117 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10118 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10119 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10120 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10121 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10122 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10123 | url::SchemeHostPort test_server("https", "www.example.org", 443); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10124 | HttpServerProperties* http_server_properties = |
| 10125 | session->http_server_properties(); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10126 | AlternativeServiceVector alternative_service_vector = |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10127 | http_server_properties->GetAlternativeServices(test_server); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10128 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 10129 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10130 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10131 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10132 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10133 | ASSERT_TRUE(response); |
| 10134 | ASSERT_TRUE(response->headers); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10135 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10136 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 10137 | EXPECT_FALSE(response->was_npn_negotiated); |
| 10138 | |
| 10139 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10140 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10141 | EXPECT_EQ("hello world", response_data); |
| 10142 | |
| 10143 | alternative_service_vector = |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10144 | http_server_properties->GetAlternativeServices(test_server); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10145 | ASSERT_EQ(2u, alternative_service_vector.size()); |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 10146 | EXPECT_EQ(AlternateProtocolFromNextProto(kProtoHTTP2), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10147 | alternative_service_vector[0].protocol); |
| 10148 | EXPECT_EQ("www.example.com", alternative_service_vector[0].host); |
| 10149 | EXPECT_EQ(443, alternative_service_vector[0].port); |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 10150 | EXPECT_EQ(AlternateProtocolFromNextProto(kProtoHTTP2), |
bnc | 3f0118e | 2016-02-02 15:42:22 | [diff] [blame] | 10151 | alternative_service_vector[1].protocol); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10152 | EXPECT_EQ("www.example.org", alternative_service_vector[1].host); |
| 10153 | EXPECT_EQ(1234, alternative_service_vector[1].port); |
| 10154 | } |
| 10155 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10156 | TEST_F(HttpNetworkTransactionTest, IdentifyQuicBroken) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10157 | url::SchemeHostPort server("https", "origin.example.org", 443); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10158 | HostPortPair alternative("alternative.example.org", 443); |
| 10159 | std::string origin_url = "https://origin.example.org:443"; |
| 10160 | std::string alternative_url = "https://alternative.example.org:443"; |
| 10161 | |
| 10162 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 10163 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10164 | ssl.next_proto = kProtoHTTP11; |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10165 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10166 | |
| 10167 | // HTTP/1.1 data for request. |
| 10168 | MockWrite http_writes[] = { |
| 10169 | MockWrite("GET / HTTP/1.1\r\n" |
| 10170 | "Host: alternative.example.org\r\n" |
| 10171 | "Connection: keep-alive\r\n\r\n"), |
| 10172 | }; |
| 10173 | |
| 10174 | MockRead http_reads[] = { |
| 10175 | MockRead("HTTP/1.1 200 OK\r\n" |
| 10176 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 10177 | "Content-Length: 40\r\n\r\n" |
| 10178 | "first HTTP/1.1 response from alternative"), |
| 10179 | }; |
| 10180 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 10181 | http_writes, arraysize(http_writes)); |
| 10182 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 10183 | |
| 10184 | StaticSocketDataProvider data_refused; |
| 10185 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 10186 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 10187 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10188 | // Set up a QUIC alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10189 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10190 | HttpServerProperties* http_server_properties = |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10191 | session->http_server_properties(); |
| 10192 | AlternativeService alternative_service(QUIC, alternative); |
| 10193 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10194 | http_server_properties->SetAlternativeService(server, alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10195 | expiration); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10196 | // Mark the QUIC alternative service as broken. |
| 10197 | http_server_properties->MarkAlternativeServiceBroken(alternative_service); |
| 10198 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10199 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10200 | HttpRequestInfo request; |
| 10201 | request.method = "GET"; |
| 10202 | request.url = GURL(origin_url); |
| 10203 | request.load_flags = 0; |
| 10204 | TestCompletionCallback callback; |
| 10205 | NetErrorDetails details; |
| 10206 | EXPECT_FALSE(details.quic_broken); |
| 10207 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10208 | trans.Start(&request, callback.callback(), BoundNetLog()); |
| 10209 | trans.PopulateNetErrorDetails(&details); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10210 | EXPECT_TRUE(details.quic_broken); |
| 10211 | } |
| 10212 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10213 | TEST_F(HttpNetworkTransactionTest, IdentifyQuicNotBroken) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10214 | url::SchemeHostPort server("https", "origin.example.org", 443); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10215 | HostPortPair alternative1("alternative1.example.org", 443); |
| 10216 | HostPortPair alternative2("alternative2.example.org", 443); |
| 10217 | std::string origin_url = "https://origin.example.org:443"; |
| 10218 | std::string alternative_url1 = "https://alternative1.example.org:443"; |
| 10219 | std::string alternative_url2 = "https://alternative2.example.org:443"; |
| 10220 | |
| 10221 | // Negotiate HTTP/1.1 with alternative1.example.org. |
| 10222 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10223 | ssl.next_proto = kProtoHTTP11; |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10224 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10225 | |
| 10226 | // HTTP/1.1 data for request. |
| 10227 | MockWrite http_writes[] = { |
| 10228 | MockWrite("GET / HTTP/1.1\r\n" |
| 10229 | "Host: alternative1.example.org\r\n" |
| 10230 | "Connection: keep-alive\r\n\r\n"), |
| 10231 | }; |
| 10232 | |
| 10233 | MockRead http_reads[] = { |
| 10234 | MockRead("HTTP/1.1 200 OK\r\n" |
| 10235 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 10236 | "Content-Length: 40\r\n\r\n" |
| 10237 | "first HTTP/1.1 response from alternative1"), |
| 10238 | }; |
| 10239 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 10240 | http_writes, arraysize(http_writes)); |
| 10241 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 10242 | |
| 10243 | StaticSocketDataProvider data_refused; |
| 10244 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 10245 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 10246 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10247 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10248 | HttpServerProperties* http_server_properties = |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10249 | session->http_server_properties(); |
| 10250 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10251 | // Set up two QUIC alternative services for server. |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10252 | AlternativeServiceInfoVector alternative_service_info_vector; |
| 10253 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 10254 | |
| 10255 | AlternativeService alternative_service1(QUIC, alternative1); |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10256 | AlternativeServiceInfo alternative_service_info1(alternative_service1, |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10257 | expiration); |
| 10258 | alternative_service_info_vector.push_back(alternative_service_info1); |
| 10259 | AlternativeService alternative_service2(QUIC, alternative2); |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10260 | AlternativeServiceInfo alternative_service_info2(alternative_service2, |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10261 | expiration); |
| 10262 | alternative_service_info_vector.push_back(alternative_service_info2); |
| 10263 | |
| 10264 | http_server_properties->SetAlternativeServices( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10265 | server, alternative_service_info_vector); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10266 | |
| 10267 | // Mark one of the QUIC alternative service as broken. |
| 10268 | http_server_properties->MarkAlternativeServiceBroken(alternative_service1); |
| 10269 | |
| 10270 | const AlternativeServiceVector alternative_service_vector = |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10271 | http_server_properties->GetAlternativeServices(server); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10272 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10273 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10274 | HttpRequestInfo request; |
| 10275 | request.method = "GET"; |
| 10276 | request.url = GURL(origin_url); |
| 10277 | request.load_flags = 0; |
| 10278 | TestCompletionCallback callback; |
| 10279 | NetErrorDetails details; |
| 10280 | EXPECT_FALSE(details.quic_broken); |
| 10281 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10282 | trans.Start(&request, callback.callback(), BoundNetLog()); |
| 10283 | trans.PopulateNetErrorDetails(&details); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10284 | EXPECT_FALSE(details.quic_broken); |
| 10285 | } |
| 10286 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10287 | TEST_F(HttpNetworkTransactionTest, MarkBrokenAlternateProtocolAndFallback) { |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10288 | HttpRequestInfo request; |
| 10289 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10290 | request.url = GURL("https://www.example.org/"); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10291 | request.load_flags = 0; |
| 10292 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10293 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10294 | StaticSocketDataProvider first_data; |
| 10295 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10296 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10297 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10298 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10299 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10300 | |
| 10301 | MockRead data_reads[] = { |
| 10302 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10303 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10304 | MockRead(ASYNC, OK), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10305 | }; |
| 10306 | StaticSocketDataProvider second_data( |
| 10307 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10308 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10309 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10310 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10311 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10312 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10313 | session->http_server_properties(); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10314 | const url::SchemeHostPort server(request.url); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10315 | // Port must be < 1024, or the header will be ignored (since initial port was |
| 10316 | // port 80 (another restricted port). |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 10317 | const AlternativeService alternative_service( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 10318 | AlternateProtocolFromNextProto(kProtoHTTP2), "www.example.org", |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 10319 | 666); // Port is ignored by MockConnect anyway. |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10320 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10321 | http_server_properties->SetAlternativeService(server, alternative_service, |
| 10322 | expiration); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10323 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10324 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10325 | TestCompletionCallback callback; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10326 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10327 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10328 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 10329 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10330 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10331 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10332 | ASSERT_TRUE(response); |
| 10333 | ASSERT_TRUE(response->headers); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10334 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10335 | |
| 10336 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10337 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10338 | EXPECT_EQ("hello world", response_data); |
| 10339 | |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 10340 | const AlternativeServiceVector alternative_service_vector = |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10341 | http_server_properties->GetAlternativeServices(server); |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 10342 | ASSERT_EQ(1u, alternative_service_vector.size()); |
| 10343 | EXPECT_EQ(alternative_service, alternative_service_vector[0]); |
| 10344 | EXPECT_TRUE(http_server_properties->IsAlternativeServiceBroken( |
| 10345 | alternative_service_vector[0])); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10346 | } |
| 10347 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10348 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10349 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 10350 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 10351 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10352 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedBlocked) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10353 | HttpRequestInfo restricted_port_request; |
| 10354 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10355 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10356 | restricted_port_request.load_flags = 0; |
| 10357 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10358 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10359 | StaticSocketDataProvider first_data; |
| 10360 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10361 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10362 | |
| 10363 | MockRead data_reads[] = { |
| 10364 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10365 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10366 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10367 | }; |
| 10368 | StaticSocketDataProvider second_data( |
| 10369 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10370 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10371 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10372 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10373 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10374 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10375 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10376 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10377 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10378 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10379 | const int kUnrestrictedAlternatePort = 1024; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10380 | AlternativeService alternative_service( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 10381 | AlternateProtocolFromNextProto(kProtoHTTP2), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10382 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10383 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10384 | http_server_properties->SetAlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10385 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10386 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10387 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10388 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10389 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10390 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10391 | int rv = |
| 10392 | trans.Start(&restricted_port_request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10393 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10394 | // Invalid change to unrestricted port should fail. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10395 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_REFUSED)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10396 | } |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10397 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10398 | // Ensure that we are allowed to redirect traffic via an alternate protocol to |
| 10399 | // an unrestricted (port >= 1024) when the original traffic was on a restricted |
| 10400 | // port (port < 1024) if we set |enable_user_alternate_protocol_ports|. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10401 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedPermitted) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10402 | session_deps_.enable_user_alternate_protocol_ports = true; |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10403 | |
| 10404 | HttpRequestInfo restricted_port_request; |
| 10405 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10406 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10407 | restricted_port_request.load_flags = 0; |
| 10408 | |
| 10409 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 10410 | StaticSocketDataProvider first_data; |
| 10411 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10412 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10413 | |
| 10414 | MockRead data_reads[] = { |
| 10415 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10416 | MockRead("hello world"), |
| 10417 | MockRead(ASYNC, OK), |
| 10418 | }; |
| 10419 | StaticSocketDataProvider second_data( |
| 10420 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10421 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10422 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10423 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10424 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10425 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10426 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10427 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10428 | HttpServerProperties* http_server_properties = |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10429 | session->http_server_properties(); |
| 10430 | const int kUnrestrictedAlternatePort = 1024; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10431 | AlternativeService alternative_service( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 10432 | AlternateProtocolFromNextProto(kProtoHTTP2), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10433 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10434 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10435 | http_server_properties->SetAlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10436 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10437 | expiration); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10438 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10439 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10440 | TestCompletionCallback callback; |
| 10441 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10442 | EXPECT_EQ(ERR_IO_PENDING, trans.Start(&restricted_port_request, |
| 10443 | callback.callback(), BoundNetLog())); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10444 | // Change to unrestricted port should succeed. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10445 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10446 | } |
| 10447 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10448 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10449 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 10450 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 10451 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10452 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedAllowed) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10453 | HttpRequestInfo restricted_port_request; |
| 10454 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10455 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10456 | restricted_port_request.load_flags = 0; |
| 10457 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10458 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10459 | StaticSocketDataProvider first_data; |
| 10460 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10461 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10462 | |
| 10463 | MockRead data_reads[] = { |
| 10464 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10465 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10466 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10467 | }; |
| 10468 | StaticSocketDataProvider second_data( |
| 10469 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10470 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10471 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10472 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 10473 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10474 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10475 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10476 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10477 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10478 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10479 | const int kRestrictedAlternatePort = 80; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10480 | AlternativeService alternative_service( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 10481 | AlternateProtocolFromNextProto(kProtoHTTP2), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10482 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10483 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10484 | http_server_properties->SetAlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10485 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10486 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10487 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10488 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10489 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10490 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10491 | int rv = |
| 10492 | trans.Start(&restricted_port_request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10493 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10494 | // Valid change to restricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10495 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10496 | } |
| 10497 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10498 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10499 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 10500 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 10501 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10502 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortUnrestrictedAllowed1) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10503 | HttpRequestInfo unrestricted_port_request; |
| 10504 | unrestricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10505 | unrestricted_port_request.url = GURL("https://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10506 | unrestricted_port_request.load_flags = 0; |
| 10507 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10508 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10509 | StaticSocketDataProvider first_data; |
| 10510 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10511 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10512 | |
| 10513 | MockRead data_reads[] = { |
| 10514 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10515 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10516 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10517 | }; |
| 10518 | StaticSocketDataProvider second_data( |
| 10519 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10520 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10521 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10522 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10523 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10524 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10525 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10526 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10527 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10528 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10529 | const int kRestrictedAlternatePort = 80; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10530 | AlternativeService alternative_service( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 10531 | AlternateProtocolFromNextProto(kProtoHTTP2), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10532 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10533 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10534 | http_server_properties->SetAlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10535 | url::SchemeHostPort(unrestricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10536 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10537 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10538 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10539 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10540 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10541 | int rv = trans.Start(&unrestricted_port_request, callback.callback(), |
| 10542 | BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10543 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10544 | // Valid change to restricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10545 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [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, AlternateProtocolPortUnrestrictedAllowed2) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10553 | HttpRequestInfo unrestricted_port_request; |
| 10554 | unrestricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10555 | unrestricted_port_request.url = GURL("https://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10556 | unrestricted_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); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10571 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10572 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 10573 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 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(); |
bnc | 0bbb0262 | 2015-07-23 10:06:22 | [diff] [blame] | 10579 | const int kUnrestrictedAlternatePort = 1025; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10580 | AlternativeService alternative_service( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 10581 | AlternateProtocolFromNextProto(kProtoHTTP2), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10582 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10583 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10584 | http_server_properties->SetAlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10585 | url::SchemeHostPort(unrestricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10586 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10587 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10588 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10589 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10590 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10591 | int rv = trans.Start(&unrestricted_port_request, callback.callback(), |
| 10592 | BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10593 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10594 | // Valid change to an unrestricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10595 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10596 | } |
| 10597 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10598 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10599 | // to an unsafe port, and that we resume the second HttpStreamFactoryImpl::Job |
| 10600 | // once the alternate protocol request fails. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10601 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolUnsafeBlocked) { |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10602 | HttpRequestInfo request; |
| 10603 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10604 | request.url = GURL("http://www.example.org/"); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10605 | request.load_flags = 0; |
| 10606 | |
| 10607 | // The alternate protocol request will error out before we attempt to connect, |
| 10608 | // so only the standard HTTP request will try to connect. |
| 10609 | MockRead data_reads[] = { |
| 10610 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10611 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10612 | MockRead(ASYNC, OK), |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10613 | }; |
| 10614 | StaticSocketDataProvider data( |
| 10615 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10616 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10617 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10618 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10619 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10620 | HttpServerProperties* http_server_properties = |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10621 | session->http_server_properties(); |
| 10622 | const int kUnsafePort = 7; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10623 | AlternativeService alternative_service( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 10624 | AlternateProtocolFromNextProto(kProtoHTTP2), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10625 | kUnsafePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10626 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10627 | http_server_properties->SetAlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10628 | url::SchemeHostPort(request.url), alternative_service, expiration); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10629 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10630 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10631 | TestCompletionCallback callback; |
| 10632 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10633 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10634 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10635 | // The HTTP request should succeed. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10636 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10637 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10638 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10639 | ASSERT_TRUE(response); |
| 10640 | ASSERT_TRUE(response->headers); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10641 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10642 | |
| 10643 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10644 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10645 | EXPECT_EQ("hello world", response_data); |
| 10646 | } |
| 10647 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10648 | TEST_F(HttpNetworkTransactionTest, UseAlternateProtocolForNpnSpdy) { |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10649 | HttpRequestInfo request; |
| 10650 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10651 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10652 | request.load_flags = 0; |
| 10653 | |
| 10654 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10655 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 10656 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10657 | MockRead("\r\n"), |
| 10658 | MockRead("hello world"), |
| 10659 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 10660 | MockRead(ASYNC, OK)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10661 | |
| 10662 | StaticSocketDataProvider first_transaction( |
| 10663 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10664 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10665 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10666 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10667 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10668 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10669 | SSLSocketDataProvider ssl_http2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10670 | ssl_http2.next_proto = kProtoHTTP2; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10671 | ssl_http2.cert = |
| 10672 | ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 10673 | ASSERT_TRUE(ssl_http2.cert.get()); |
| 10674 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http2); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10675 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10676 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10677 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10678 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10679 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 10680 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10681 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10682 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10683 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10684 | }; |
| 10685 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10686 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 10687 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10688 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10689 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10690 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10691 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 10692 | NULL, 0, NULL, 0); |
| 10693 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 10694 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10695 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10696 | &hanging_non_alternate_protocol_socket); |
| 10697 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10698 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10699 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10700 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10701 | std::unique_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10702 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10703 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10704 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10705 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 10706 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10707 | |
| 10708 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10709 | ASSERT_TRUE(response); |
| 10710 | ASSERT_TRUE(response->headers); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10711 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10712 | |
| 10713 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10714 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10715 | EXPECT_EQ("hello world", response_data); |
| 10716 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10717 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10718 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10719 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10720 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 10721 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10722 | |
| 10723 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10724 | ASSERT_TRUE(response); |
| 10725 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 10726 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10727 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 10728 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10729 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10730 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10731 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10732 | } |
| 10733 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10734 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolWithSpdyLateBinding) { |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10735 | HttpRequestInfo request; |
| 10736 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10737 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10738 | request.load_flags = 0; |
| 10739 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10740 | // First transaction receives Alt-Svc header over HTTP/1.1. |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10741 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10742 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 10743 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10744 | MockRead("\r\n"), |
| 10745 | MockRead("hello world"), |
| 10746 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 10747 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10748 | }; |
| 10749 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10750 | StaticSocketDataProvider http11_data(data_reads, arraysize(data_reads), NULL, |
| 10751 | 0); |
| 10752 | session_deps_.socket_factory->AddSocketDataProvider(&http11_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10753 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10754 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
| 10755 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
| 10756 | |
| 10757 | // Second transaction starts an alternative and a non-alternative Job. |
| 10758 | // Both sockets hang. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10759 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 10760 | StaticSocketDataProvider hanging_socket1(NULL, 0, NULL, 0); |
| 10761 | hanging_socket1.set_connect_data(never_finishing_connect); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 10762 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket1); |
| 10763 | |
| 10764 | StaticSocketDataProvider hanging_socket2(NULL, 0, NULL, 0); |
| 10765 | hanging_socket2.set_connect_data(never_finishing_connect); |
| 10766 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket2); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10767 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10768 | // Third transaction starts an alternative and a non-alternative job. |
| 10769 | // The non-alternative job hangs, but the alternative one succeeds. |
| 10770 | // The second transaction, still pending, binds to this socket. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10771 | SpdySerializedFrame req1( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10772 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10773 | SpdySerializedFrame req2( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10774 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 3, LOWEST)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10775 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10776 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 1), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10777 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 10778 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10779 | SpdySerializedFrame data1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 10780 | SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10781 | SpdySerializedFrame data2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10782 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10783 | CreateMockRead(resp1, 2), CreateMockRead(data1, 3), |
| 10784 | CreateMockRead(resp2, 4), CreateMockRead(data2, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10785 | MockRead(ASYNC, 0, 6), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10786 | }; |
| 10787 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10788 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 10789 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10790 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10791 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10792 | SSLSocketDataProvider ssl_http2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10793 | ssl_http2.next_proto = kProtoHTTP2; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10794 | ssl_http2.cert = |
| 10795 | ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 10796 | ASSERT_TRUE(ssl_http2.cert); |
| 10797 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http2); |
| 10798 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 10799 | StaticSocketDataProvider hanging_socket3(NULL, 0, NULL, 0); |
| 10800 | hanging_socket3.set_connect_data(never_finishing_connect); |
| 10801 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket3); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10802 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10803 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10804 | TestCompletionCallback callback1; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10805 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10806 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10807 | int rv = trans1.Start(&request, callback1.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10808 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 10809 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10810 | |
| 10811 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10812 | ASSERT_TRUE(response); |
| 10813 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10814 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10815 | |
| 10816 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10817 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10818 | EXPECT_EQ("hello world", response_data); |
| 10819 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10820 | TestCompletionCallback callback2; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10821 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10822 | rv = trans2.Start(&request, callback2.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10823 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10824 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10825 | TestCompletionCallback callback3; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10826 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10827 | rv = trans3.Start(&request, callback3.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10828 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10829 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10830 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
| 10831 | EXPECT_THAT(callback3.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10832 | |
| 10833 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10834 | ASSERT_TRUE(response); |
| 10835 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 10836 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10837 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 10838 | EXPECT_TRUE(response->was_npn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10839 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10840 | EXPECT_EQ("hello!", response_data); |
| 10841 | |
| 10842 | response = trans3.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10843 | ASSERT_TRUE(response); |
| 10844 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 10845 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10846 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 10847 | EXPECT_TRUE(response->was_npn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10848 | ASSERT_THAT(ReadTransaction(&trans3, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10849 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10850 | } |
| 10851 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10852 | TEST_F(HttpNetworkTransactionTest, StallAlternativeServiceForNpnSpdy) { |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10853 | HttpRequestInfo request; |
| 10854 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10855 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10856 | request.load_flags = 0; |
| 10857 | |
| 10858 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10859 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 10860 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10861 | MockRead("\r\n"), |
| 10862 | MockRead("hello world"), |
| 10863 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 10864 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10865 | }; |
| 10866 | |
| 10867 | StaticSocketDataProvider first_transaction( |
| 10868 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10869 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10870 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10871 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10872 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10873 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10874 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10875 | StaticSocketDataProvider hanging_alternate_protocol_socket( |
| 10876 | NULL, 0, NULL, 0); |
| 10877 | hanging_alternate_protocol_socket.set_connect_data( |
| 10878 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10879 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10880 | &hanging_alternate_protocol_socket); |
| 10881 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10882 | // 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] | 10883 | StaticSocketDataProvider second_transaction(data_reads, arraysize(data_reads), |
| 10884 | NULL, 0); |
| 10885 | session_deps_.socket_factory->AddSocketDataProvider(&second_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10886 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10887 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10888 | TestCompletionCallback callback; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10889 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10890 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10891 | std::unique_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10892 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10893 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10894 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10895 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 10896 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10897 | |
| 10898 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10899 | ASSERT_TRUE(response); |
| 10900 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10901 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10902 | |
| 10903 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10904 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10905 | EXPECT_EQ("hello world", response_data); |
| 10906 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10907 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10908 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10909 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10910 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 10911 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10912 | |
| 10913 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10914 | ASSERT_TRUE(response); |
| 10915 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10916 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10917 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 10918 | EXPECT_FALSE(response->was_npn_negotiated); |
| 10919 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10920 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10921 | EXPECT_EQ("hello world", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10922 | } |
| 10923 | |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10924 | class CapturingProxyResolver : public ProxyResolver { |
| 10925 | public: |
sammc | e90c921 | 2015-05-27 23:43:35 | [diff] [blame] | 10926 | CapturingProxyResolver() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 10927 | ~CapturingProxyResolver() override {} |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10928 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 10929 | int GetProxyForURL(const GURL& url, |
| 10930 | ProxyInfo* results, |
| 10931 | const CompletionCallback& callback, |
eroman | 9c8f424 | 2016-02-29 21:16:54 | [diff] [blame] | 10932 | RequestHandle* request, |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 10933 | const BoundNetLog& net_log) override { |
[email protected] | fae7669f | 2010-08-02 21:49:40 | [diff] [blame] | 10934 | ProxyServer proxy_server(ProxyServer::SCHEME_HTTP, |
| 10935 | HostPortPair("myproxy", 80)); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 10936 | results->UseProxyServer(proxy_server); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10937 | resolved_.push_back(url); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 10938 | return OK; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10939 | } |
| 10940 | |
eroman | 9c8f424 | 2016-02-29 21:16:54 | [diff] [blame] | 10941 | void CancelRequest(RequestHandle request) override { NOTREACHED(); } |
| 10942 | |
| 10943 | LoadState GetLoadState(RequestHandle request) const override { |
| 10944 | NOTREACHED(); |
| 10945 | return LOAD_STATE_IDLE; |
| 10946 | } |
| 10947 | |
[email protected] | 2447640 | 2010-07-20 20:55:17 | [diff] [blame] | 10948 | const std::vector<GURL>& resolved() const { return resolved_; } |
| 10949 | |
| 10950 | private: |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10951 | std::vector<GURL> resolved_; |
| 10952 | |
| 10953 | DISALLOW_COPY_AND_ASSIGN(CapturingProxyResolver); |
| 10954 | }; |
| 10955 | |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 10956 | class CapturingProxyResolverFactory : public ProxyResolverFactory { |
| 10957 | public: |
| 10958 | explicit CapturingProxyResolverFactory(CapturingProxyResolver* resolver) |
| 10959 | : ProxyResolverFactory(false), resolver_(resolver) {} |
| 10960 | |
| 10961 | int CreateProxyResolver( |
| 10962 | const scoped_refptr<ProxyResolverScriptData>& pac_script, |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10963 | std::unique_ptr<ProxyResolver>* resolver, |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 10964 | const net::CompletionCallback& callback, |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10965 | std::unique_ptr<Request>* request) override { |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 10966 | resolver->reset(new ForwardingProxyResolver(resolver_)); |
| 10967 | return OK; |
| 10968 | } |
| 10969 | |
| 10970 | private: |
| 10971 | ProxyResolver* resolver_; |
| 10972 | }; |
| 10973 | |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 10974 | // Test that proxy is resolved using the origin url, |
| 10975 | // regardless of the alternative server. |
| 10976 | TEST_F(HttpNetworkTransactionTest, UseOriginNotAlternativeForProxy) { |
| 10977 | // Configure proxy to bypass www.example.org, which is the origin URL. |
| 10978 | ProxyConfig proxy_config; |
| 10979 | proxy_config.proxy_rules().ParseFromString("myproxy:70"); |
| 10980 | proxy_config.proxy_rules().bypass_rules.AddRuleFromString("www.example.org"); |
| 10981 | auto proxy_config_service = |
| 10982 | base::MakeUnique<ProxyConfigServiceFixed>(proxy_config); |
| 10983 | |
| 10984 | CapturingProxyResolver capturing_proxy_resolver; |
| 10985 | auto proxy_resolver_factory = base::MakeUnique<CapturingProxyResolverFactory>( |
| 10986 | &capturing_proxy_resolver); |
| 10987 | |
| 10988 | TestNetLog net_log; |
| 10989 | |
| 10990 | session_deps_.proxy_service = base::MakeUnique<ProxyService>( |
| 10991 | std::move(proxy_config_service), std::move(proxy_resolver_factory), |
| 10992 | &net_log); |
| 10993 | |
| 10994 | session_deps_.net_log = &net_log; |
| 10995 | |
| 10996 | // Configure alternative service with a hostname that is not bypassed by the |
| 10997 | // proxy. |
| 10998 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 10999 | HttpServerProperties* http_server_properties = |
| 11000 | session->http_server_properties(); |
| 11001 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 11002 | HostPortPair alternative("www.example.com", 443); |
| 11003 | AlternativeService alternative_service( |
| 11004 | AlternateProtocolFromNextProto(kProtoHTTP2), alternative); |
| 11005 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 11006 | http_server_properties->SetAlternativeService(server, alternative_service, |
| 11007 | expiration); |
| 11008 | |
| 11009 | // Non-alternative job should hang. |
| 11010 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
| 11011 | StaticSocketDataProvider hanging_alternate_protocol_socket(nullptr, 0, |
| 11012 | nullptr, 0); |
| 11013 | hanging_alternate_protocol_socket.set_connect_data(never_finishing_connect); |
| 11014 | session_deps_.socket_factory->AddSocketDataProvider( |
| 11015 | &hanging_alternate_protocol_socket); |
| 11016 | |
| 11017 | SSLSocketDataProvider ssl_http2(ASYNC, OK); |
| 11018 | ssl_http2.next_proto = kProtoHTTP2; |
| 11019 | ssl_http2.cert = |
| 11020 | ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 11021 | ASSERT_TRUE(ssl_http2.cert); |
| 11022 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http2); |
| 11023 | |
| 11024 | HttpRequestInfo request; |
| 11025 | request.method = "GET"; |
| 11026 | request.url = GURL("https://www.example.org/"); |
| 11027 | request.load_flags = 0; |
| 11028 | |
| 11029 | SpdySerializedFrame req( |
| 11030 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
| 11031 | |
| 11032 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
| 11033 | |
| 11034 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 11035 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 11036 | MockRead spdy_reads[] = { |
| 11037 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
| 11038 | }; |
| 11039 | |
| 11040 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 11041 | arraysize(spdy_writes)); |
| 11042 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 11043 | |
| 11044 | TestCompletionCallback callback; |
| 11045 | |
| 11046 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 11047 | |
| 11048 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
| 11049 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 11050 | |
| 11051 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 11052 | ASSERT_TRUE(response); |
| 11053 | ASSERT_TRUE(response->headers); |
| 11054 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 11055 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 11056 | EXPECT_TRUE(response->was_npn_negotiated); |
| 11057 | |
| 11058 | std::string response_data; |
| 11059 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 11060 | EXPECT_EQ("hello!", response_data); |
| 11061 | |
| 11062 | // Origin host bypasses proxy, no resolution should have happened. |
| 11063 | ASSERT_TRUE(capturing_proxy_resolver.resolved().empty()); |
| 11064 | } |
| 11065 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11066 | TEST_F(HttpNetworkTransactionTest, UseAlternativeServiceForTunneledNpnSpdy) { |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11067 | ProxyConfig proxy_config; |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 11068 | proxy_config.set_auto_detect(true); |
| 11069 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 11070 | |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 11071 | CapturingProxyResolver capturing_proxy_resolver; |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 11072 | session_deps_.proxy_service.reset( |
| 11073 | new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), |
| 11074 | base::MakeUnique<CapturingProxyResolverFactory>( |
| 11075 | &capturing_proxy_resolver), |
| 11076 | NULL)); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11077 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11078 | session_deps_.net_log = &net_log; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11079 | |
| 11080 | HttpRequestInfo request; |
| 11081 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11082 | request.url = GURL("https://www.example.org/"); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11083 | request.load_flags = 0; |
| 11084 | |
| 11085 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11086 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11087 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11088 | MockRead("\r\n"), |
| 11089 | MockRead("hello world"), |
| 11090 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 11091 | MockRead(ASYNC, OK), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11092 | }; |
| 11093 | |
| 11094 | StaticSocketDataProvider first_transaction( |
| 11095 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11096 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11097 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11098 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11099 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11100 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11101 | SSLSocketDataProvider ssl_http2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11102 | ssl_http2.next_proto = kProtoHTTP2; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11103 | ssl_http2.cert = |
| 11104 | ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 11105 | ASSERT_TRUE(ssl_http2.cert); |
| 11106 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http2); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11107 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11108 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11109 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11110 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11111 | MockWrite(ASYNC, 0, |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11112 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 11113 | "Host: www.example.org:443\r\n" |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11114 | "Proxy-Connection: keep-alive\r\n\r\n"), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11115 | CreateMockWrite(req, 2), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11116 | }; |
| 11117 | |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 11118 | const char kCONNECTResponse[] = "HTTP/1.1 200 Connected\r\n\r\n"; |
| 11119 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 11120 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11121 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11122 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11123 | MockRead(ASYNC, 1, kCONNECTResponse), CreateMockRead(resp, 3), |
| 11124 | CreateMockRead(data, 4), MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11125 | }; |
| 11126 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11127 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 11128 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11129 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11130 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11131 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11132 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 11133 | NULL, 0, NULL, 0); |
| 11134 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 11135 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11136 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11137 | &hanging_non_alternate_protocol_socket); |
| 11138 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11139 | TestCompletionCallback callback; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11140 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11141 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11142 | std::unique_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11143 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11144 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11145 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 11146 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11147 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 11148 | |
| 11149 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 11150 | ASSERT_TRUE(response); |
| 11151 | ASSERT_TRUE(response->headers); |
| 11152 | EXPECT_EQ("HTTP/0.9 200 OK", response->headers->GetStatusLine()); |
| 11153 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 11154 | EXPECT_TRUE(response->was_npn_negotiated); |
| 11155 | |
| 11156 | std::string response_data; |
| 11157 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 11158 | EXPECT_EQ("hello world", response_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11159 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11160 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11161 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11162 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11163 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11164 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11165 | |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 11166 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11167 | ASSERT_TRUE(response); |
| 11168 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 11169 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11170 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 11171 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11172 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11173 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11174 | EXPECT_EQ("hello!", response_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11175 | ASSERT_EQ(2u, capturing_proxy_resolver.resolved().size()); |
| 11176 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 11177 | capturing_proxy_resolver.resolved()[0].spec()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11178 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 11179 | capturing_proxy_resolver.resolved()[1].spec()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11180 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11181 | LoadTimingInfo load_timing_info; |
| 11182 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 11183 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 11184 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11185 | } |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11186 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11187 | TEST_F(HttpNetworkTransactionTest, |
bnc | 1c196c6e | 2016-05-28 13:51:48 | [diff] [blame] | 11188 | UseAlternativeServiceForNpnSpdyWithExistingSpdySession) { |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11189 | HttpRequestInfo request; |
| 11190 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11191 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11192 | request.load_flags = 0; |
| 11193 | |
| 11194 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11195 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11196 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11197 | MockRead("\r\n"), |
| 11198 | MockRead("hello world"), |
| 11199 | MockRead(ASYNC, OK), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11200 | }; |
| 11201 | |
| 11202 | StaticSocketDataProvider first_transaction( |
| 11203 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11204 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11205 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11206 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11207 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11208 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11209 | SSLSocketDataProvider ssl_http2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11210 | ssl_http2.next_proto = kProtoHTTP2; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11211 | ssl_http2.cert = |
| 11212 | ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 11213 | ASSERT_TRUE(ssl_http2.cert); |
| 11214 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http2); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11215 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11216 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11217 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11218 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11219 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 11220 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11221 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11222 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11223 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11224 | }; |
| 11225 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11226 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 11227 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11228 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11229 | |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 11230 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11231 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11232 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11233 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11234 | std::unique_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11235 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11236 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11237 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11238 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11239 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11240 | |
| 11241 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11242 | ASSERT_TRUE(response); |
| 11243 | ASSERT_TRUE(response->headers); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11244 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11245 | |
| 11246 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11247 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11248 | EXPECT_EQ("hello world", response_data); |
| 11249 | |
| 11250 | // Set up an initial SpdySession in the pool to reuse. |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11251 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 11252 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 11253 | PRIVACY_MODE_DISABLED); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 11254 | base::WeakPtr<SpdySession> spdy_session = |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11255 | CreateSecureSpdySession(session.get(), key, BoundNetLog()); |
[email protected] | 02b0c34 | 2010-09-25 21:09:38 | [diff] [blame] | 11256 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11257 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11258 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11259 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11260 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11261 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11262 | |
| 11263 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11264 | ASSERT_TRUE(response); |
| 11265 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 11266 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11267 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 11268 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11269 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11270 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11271 | EXPECT_EQ("hello!", response_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11272 | } |
| 11273 | |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11274 | // GenerateAuthToken is a mighty big test. |
| 11275 | // It tests all permutation of GenerateAuthToken behavior: |
| 11276 | // - Synchronous and Asynchronous completion. |
| 11277 | // - OK or error on completion. |
| 11278 | // - Direct connection, non-authenticating proxy, and authenticating proxy. |
| 11279 | // - HTTP or HTTPS backend (to include proxy tunneling). |
| 11280 | // - Non-authenticating and authenticating backend. |
| 11281 | // |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 11282 | // In all, there are 44 reasonable permuations (for example, if there are |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11283 | // problems generating an auth token for an authenticating proxy, we don't |
| 11284 | // need to test all permutations of the backend server). |
| 11285 | // |
| 11286 | // The test proceeds by going over each of the configuration cases, and |
| 11287 | // potentially running up to three rounds in each of the tests. The TestConfig |
| 11288 | // specifies both the configuration for the test as well as the expectations |
| 11289 | // for the results. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11290 | TEST_F(HttpNetworkTransactionTest, GenerateAuthToken) { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11291 | static const char kServer[] = "http://www.example.com"; |
| 11292 | static const char kSecureServer[] = "https://www.example.com"; |
| 11293 | static const char kProxy[] = "myproxy:70"; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11294 | const int kAuthErr = ERR_INVALID_AUTH_CREDENTIALS; |
| 11295 | |
| 11296 | enum AuthTiming { |
| 11297 | AUTH_NONE, |
| 11298 | AUTH_SYNC, |
| 11299 | AUTH_ASYNC, |
| 11300 | }; |
| 11301 | |
| 11302 | const MockWrite kGet( |
| 11303 | "GET / HTTP/1.1\r\n" |
| 11304 | "Host: www.example.com\r\n" |
| 11305 | "Connection: keep-alive\r\n\r\n"); |
| 11306 | const MockWrite kGetProxy( |
| 11307 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 11308 | "Host: www.example.com\r\n" |
| 11309 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 11310 | const MockWrite kGetAuth( |
| 11311 | "GET / HTTP/1.1\r\n" |
| 11312 | "Host: www.example.com\r\n" |
| 11313 | "Connection: keep-alive\r\n" |
| 11314 | "Authorization: auth_token\r\n\r\n"); |
| 11315 | const MockWrite kGetProxyAuth( |
| 11316 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 11317 | "Host: www.example.com\r\n" |
| 11318 | "Proxy-Connection: keep-alive\r\n" |
| 11319 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 11320 | const MockWrite kGetAuthThroughProxy( |
| 11321 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 11322 | "Host: www.example.com\r\n" |
| 11323 | "Proxy-Connection: keep-alive\r\n" |
| 11324 | "Authorization: auth_token\r\n\r\n"); |
| 11325 | const MockWrite kGetAuthWithProxyAuth( |
| 11326 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 11327 | "Host: www.example.com\r\n" |
| 11328 | "Proxy-Connection: keep-alive\r\n" |
| 11329 | "Proxy-Authorization: auth_token\r\n" |
| 11330 | "Authorization: auth_token\r\n\r\n"); |
| 11331 | const MockWrite kConnect( |
| 11332 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 11333 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11334 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 11335 | const MockWrite kConnectProxyAuth( |
| 11336 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 11337 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11338 | "Proxy-Connection: keep-alive\r\n" |
| 11339 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 11340 | |
| 11341 | const MockRead kSuccess( |
| 11342 | "HTTP/1.1 200 OK\r\n" |
| 11343 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11344 | "Content-Length: 3\r\n\r\n" |
| 11345 | "Yes"); |
| 11346 | const MockRead kFailure( |
| 11347 | "Should not be called."); |
| 11348 | const MockRead kServerChallenge( |
| 11349 | "HTTP/1.1 401 Unauthorized\r\n" |
| 11350 | "WWW-Authenticate: Mock realm=server\r\n" |
| 11351 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11352 | "Content-Length: 14\r\n\r\n" |
| 11353 | "Unauthorized\r\n"); |
| 11354 | const MockRead kProxyChallenge( |
| 11355 | "HTTP/1.1 407 Unauthorized\r\n" |
| 11356 | "Proxy-Authenticate: Mock realm=proxy\r\n" |
| 11357 | "Proxy-Connection: close\r\n" |
| 11358 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11359 | "Content-Length: 14\r\n\r\n" |
| 11360 | "Unauthorized\r\n"); |
| 11361 | const MockRead kProxyConnected( |
| 11362 | "HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 11363 | |
| 11364 | // NOTE(cbentzel): I wanted TestReadWriteRound to be a simple struct with |
| 11365 | // no constructors, but the C++ compiler on Windows warns about |
| 11366 | // unspecified data in compound literals. So, moved to using constructors, |
| 11367 | // and TestRound's created with the default constructor should not be used. |
| 11368 | struct TestRound { |
| 11369 | TestRound() |
| 11370 | : expected_rv(ERR_UNEXPECTED), |
| 11371 | extra_write(NULL), |
| 11372 | extra_read(NULL) { |
| 11373 | } |
| 11374 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 11375 | int expected_rv_arg) |
| 11376 | : write(write_arg), |
| 11377 | read(read_arg), |
| 11378 | expected_rv(expected_rv_arg), |
| 11379 | extra_write(NULL), |
| 11380 | extra_read(NULL) { |
| 11381 | } |
| 11382 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 11383 | int expected_rv_arg, const MockWrite* extra_write_arg, |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 11384 | const MockRead* extra_read_arg) |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11385 | : write(write_arg), |
| 11386 | read(read_arg), |
| 11387 | expected_rv(expected_rv_arg), |
| 11388 | extra_write(extra_write_arg), |
| 11389 | extra_read(extra_read_arg) { |
| 11390 | } |
| 11391 | MockWrite write; |
| 11392 | MockRead read; |
| 11393 | int expected_rv; |
| 11394 | const MockWrite* extra_write; |
| 11395 | const MockRead* extra_read; |
| 11396 | }; |
| 11397 | |
| 11398 | static const int kNoSSL = 500; |
| 11399 | |
| 11400 | struct TestConfig { |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 11401 | const char* const proxy_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11402 | AuthTiming proxy_auth_timing; |
| 11403 | int proxy_auth_rv; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 11404 | const char* const server_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11405 | AuthTiming server_auth_timing; |
| 11406 | int server_auth_rv; |
| 11407 | int num_auth_rounds; |
| 11408 | int first_ssl_round; |
| 11409 | TestRound rounds[3]; |
| 11410 | } test_configs[] = { |
| 11411 | // Non-authenticating HTTP server with a direct connection. |
| 11412 | { NULL, AUTH_NONE, OK, kServer, AUTH_NONE, OK, 1, kNoSSL, |
| 11413 | { TestRound(kGet, kSuccess, OK)}}, |
| 11414 | // Authenticating HTTP server with a direct connection. |
| 11415 | { NULL, AUTH_NONE, OK, kServer, AUTH_SYNC, OK, 2, kNoSSL, |
| 11416 | { TestRound(kGet, kServerChallenge, OK), |
| 11417 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11418 | { NULL, AUTH_NONE, OK, kServer, AUTH_SYNC, kAuthErr, 2, kNoSSL, |
| 11419 | { TestRound(kGet, kServerChallenge, OK), |
| 11420 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11421 | { NULL, AUTH_NONE, OK, kServer, AUTH_ASYNC, OK, 2, kNoSSL, |
| 11422 | { TestRound(kGet, kServerChallenge, OK), |
| 11423 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11424 | { NULL, AUTH_NONE, OK, kServer, AUTH_ASYNC, kAuthErr, 2, kNoSSL, |
| 11425 | { TestRound(kGet, kServerChallenge, OK), |
| 11426 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11427 | // Non-authenticating HTTP server through a non-authenticating proxy. |
| 11428 | { kProxy, AUTH_NONE, OK, kServer, AUTH_NONE, OK, 1, kNoSSL, |
| 11429 | { TestRound(kGetProxy, kSuccess, OK)}}, |
| 11430 | // Authenticating HTTP server through a non-authenticating proxy. |
| 11431 | { kProxy, AUTH_NONE, OK, kServer, AUTH_SYNC, OK, 2, kNoSSL, |
| 11432 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 11433 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
| 11434 | { kProxy, AUTH_NONE, OK, kServer, AUTH_SYNC, kAuthErr, 2, kNoSSL, |
| 11435 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 11436 | TestRound(kGetAuthThroughProxy, kFailure, kAuthErr)}}, |
| 11437 | { kProxy, AUTH_NONE, OK, kServer, AUTH_ASYNC, OK, 2, kNoSSL, |
| 11438 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 11439 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
| 11440 | { kProxy, AUTH_NONE, OK, kServer, AUTH_ASYNC, kAuthErr, 2, kNoSSL, |
| 11441 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 11442 | TestRound(kGetAuthThroughProxy, kFailure, kAuthErr)}}, |
| 11443 | // Non-authenticating HTTP server through an authenticating proxy. |
| 11444 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 11445 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11446 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
| 11447 | { kProxy, AUTH_SYNC, kAuthErr, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 11448 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11449 | TestRound(kGetProxyAuth, kFailure, kAuthErr)}}, |
| 11450 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 11451 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11452 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
| 11453 | { kProxy, AUTH_ASYNC, kAuthErr, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 11454 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11455 | TestRound(kGetProxyAuth, kFailure, kAuthErr)}}, |
| 11456 | // Authenticating HTTP server through an authenticating proxy. |
| 11457 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_SYNC, OK, 3, kNoSSL, |
| 11458 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11459 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11460 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 11461 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_SYNC, kAuthErr, 3, kNoSSL, |
| 11462 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11463 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11464 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 11465 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_SYNC, OK, 3, kNoSSL, |
| 11466 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11467 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11468 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 11469 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_SYNC, kAuthErr, 3, kNoSSL, |
| 11470 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11471 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11472 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 11473 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_ASYNC, OK, 3, kNoSSL, |
| 11474 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11475 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11476 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 11477 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_ASYNC, kAuthErr, 3, kNoSSL, |
| 11478 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11479 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11480 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 11481 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_ASYNC, OK, 3, kNoSSL, |
| 11482 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11483 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11484 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 11485 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_ASYNC, kAuthErr, 3, kNoSSL, |
| 11486 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11487 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11488 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 11489 | // Non-authenticating HTTPS server with a direct connection. |
| 11490 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_NONE, OK, 1, 0, |
| 11491 | { TestRound(kGet, kSuccess, OK)}}, |
| 11492 | // Authenticating HTTPS server with a direct connection. |
| 11493 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, OK, 2, 0, |
| 11494 | { TestRound(kGet, kServerChallenge, OK), |
| 11495 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11496 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, kAuthErr, 2, 0, |
| 11497 | { TestRound(kGet, kServerChallenge, OK), |
| 11498 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11499 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, OK, 2, 0, |
| 11500 | { TestRound(kGet, kServerChallenge, OK), |
| 11501 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11502 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 2, 0, |
| 11503 | { TestRound(kGet, kServerChallenge, OK), |
| 11504 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11505 | // Non-authenticating HTTPS server with a non-authenticating proxy. |
| 11506 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_NONE, OK, 1, 0, |
| 11507 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 11508 | // Authenticating HTTPS server through a non-authenticating proxy. |
| 11509 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, OK, 2, 0, |
| 11510 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 11511 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11512 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, kAuthErr, 2, 0, |
| 11513 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 11514 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11515 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, OK, 2, 0, |
| 11516 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 11517 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11518 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 2, 0, |
| 11519 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 11520 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11521 | // Non-Authenticating HTTPS server through an authenticating proxy. |
| 11522 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_NONE, OK, 2, 1, |
| 11523 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11524 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 11525 | { kProxy, AUTH_SYNC, kAuthErr, kSecureServer, AUTH_NONE, OK, 2, kNoSSL, |
| 11526 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11527 | TestRound(kConnectProxyAuth, kFailure, kAuthErr)}}, |
| 11528 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_NONE, OK, 2, 1, |
| 11529 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11530 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 11531 | { kProxy, AUTH_ASYNC, kAuthErr, kSecureServer, AUTH_NONE, OK, 2, kNoSSL, |
| 11532 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11533 | TestRound(kConnectProxyAuth, kFailure, kAuthErr)}}, |
| 11534 | // Authenticating HTTPS server through an authenticating proxy. |
| 11535 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_SYNC, OK, 3, 1, |
| 11536 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11537 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 11538 | &kGet, &kServerChallenge), |
| 11539 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11540 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_SYNC, kAuthErr, 3, 1, |
| 11541 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11542 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 11543 | &kGet, &kServerChallenge), |
| 11544 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11545 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_SYNC, OK, 3, 1, |
| 11546 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11547 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 11548 | &kGet, &kServerChallenge), |
| 11549 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11550 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_SYNC, kAuthErr, 3, 1, |
| 11551 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11552 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 11553 | &kGet, &kServerChallenge), |
| 11554 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11555 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_ASYNC, OK, 3, 1, |
| 11556 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11557 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 11558 | &kGet, &kServerChallenge), |
| 11559 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11560 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 3, 1, |
| 11561 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11562 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 11563 | &kGet, &kServerChallenge), |
| 11564 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11565 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_ASYNC, OK, 3, 1, |
| 11566 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11567 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 11568 | &kGet, &kServerChallenge), |
| 11569 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11570 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 3, 1, |
| 11571 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11572 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 11573 | &kGet, &kServerChallenge), |
| 11574 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11575 | }; |
| 11576 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 11577 | for (size_t i = 0; i < arraysize(test_configs); ++i) { |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 11578 | HttpAuthHandlerMock::Factory* auth_factory( |
| 11579 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11580 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 11581 | SSLInfo empty_ssl_info; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11582 | const TestConfig& test_config = test_configs[i]; |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 11583 | |
| 11584 | // Set up authentication handlers as necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11585 | if (test_config.proxy_auth_timing != AUTH_NONE) { |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 11586 | for (int n = 0; n < 2; n++) { |
| 11587 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 11588 | std::string auth_challenge = "Mock realm=proxy"; |
| 11589 | GURL origin(test_config.proxy_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 11590 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 11591 | auth_challenge.end()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 11592 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_PROXY, |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 11593 | empty_ssl_info, origin, BoundNetLog()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 11594 | auth_handler->SetGenerateExpectation( |
| 11595 | test_config.proxy_auth_timing == AUTH_ASYNC, |
| 11596 | test_config.proxy_auth_rv); |
| 11597 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
| 11598 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11599 | } |
| 11600 | if (test_config.server_auth_timing != AUTH_NONE) { |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 11601 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11602 | std::string auth_challenge = "Mock realm=server"; |
| 11603 | GURL origin(test_config.server_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 11604 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 11605 | auth_challenge.end()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11606 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 11607 | empty_ssl_info, origin, BoundNetLog()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11608 | auth_handler->SetGenerateExpectation( |
| 11609 | test_config.server_auth_timing == AUTH_ASYNC, |
| 11610 | test_config.server_auth_rv); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 11611 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11612 | } |
| 11613 | if (test_config.proxy_url) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 11614 | session_deps_.proxy_service = |
| 11615 | ProxyService::CreateFixed(test_config.proxy_url); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11616 | } else { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 11617 | session_deps_.proxy_service = ProxyService::CreateDirect(); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11618 | } |
| 11619 | |
| 11620 | HttpRequestInfo request; |
| 11621 | request.method = "GET"; |
| 11622 | request.url = GURL(test_config.server_url); |
| 11623 | request.load_flags = 0; |
| 11624 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11625 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11626 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11627 | SSLSocketDataProvider ssl_socket_data_provider(SYNCHRONOUS, OK); |
| 11628 | |
| 11629 | std::vector<std::vector<MockRead>> mock_reads(1); |
| 11630 | std::vector<std::vector<MockWrite>> mock_writes(1); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11631 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
| 11632 | const TestRound& read_write_round = test_config.rounds[round]; |
| 11633 | |
| 11634 | // Set up expected reads and writes. |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11635 | mock_reads.back().push_back(read_write_round.read); |
| 11636 | mock_writes.back().push_back(read_write_round.write); |
| 11637 | |
| 11638 | // kProxyChallenge uses Proxy-Connection: close which means that the |
| 11639 | // socket is closed and a new one will be created for the next request. |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 11640 | if (read_write_round.read.data == kProxyChallenge.data) { |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11641 | mock_reads.push_back(std::vector<MockRead>()); |
| 11642 | mock_writes.push_back(std::vector<MockWrite>()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11643 | } |
| 11644 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11645 | if (read_write_round.extra_read) { |
| 11646 | mock_reads.back().push_back(*read_write_round.extra_read); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11647 | } |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11648 | if (read_write_round.extra_write) { |
| 11649 | mock_writes.back().push_back(*read_write_round.extra_write); |
| 11650 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11651 | |
| 11652 | // Add an SSL sequence if necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11653 | if (round >= test_config.first_ssl_round) |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11654 | session_deps_.socket_factory->AddSSLSocketDataProvider( |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11655 | &ssl_socket_data_provider); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11656 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11657 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11658 | std::vector<std::unique_ptr<StaticSocketDataProvider>> data_providers; |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11659 | for (size_t i = 0; i < mock_reads.size(); ++i) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11660 | data_providers.push_back(base::WrapUnique(new StaticSocketDataProvider( |
davidben | 5f8b6bc | 2015-11-25 03:19:54 | [diff] [blame] | 11661 | mock_reads[i].data(), mock_reads[i].size(), mock_writes[i].data(), |
olli.raula | 525048c | 2015-12-10 07:38:32 | [diff] [blame] | 11662 | mock_writes[i].size()))); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11663 | session_deps_.socket_factory->AddSocketDataProvider( |
olli.raula | 525048c | 2015-12-10 07:38:32 | [diff] [blame] | 11664 | data_providers.back().get()); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11665 | } |
| 11666 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 11667 | // Transaction must be created after DataProviders, so it's destroyed before |
| 11668 | // they are as well. |
| 11669 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 11670 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11671 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
| 11672 | const TestRound& read_write_round = test_config.rounds[round]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11673 | // Start or restart the transaction. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11674 | TestCompletionCallback callback; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11675 | int rv; |
| 11676 | if (round == 0) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11677 | rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11678 | } else { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11679 | rv = trans.RestartWithAuth( |
| 11680 | AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11681 | } |
| 11682 | if (rv == ERR_IO_PENDING) |
| 11683 | rv = callback.WaitForResult(); |
| 11684 | |
| 11685 | // Compare results with expected data. |
| 11686 | EXPECT_EQ(read_write_round.expected_rv, rv); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11687 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | c0c82849 | 2015-05-15 01:25:55 | [diff] [blame] | 11688 | if (read_write_round.expected_rv != OK) { |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11689 | EXPECT_EQ(round + 1, test_config.num_auth_rounds); |
| 11690 | continue; |
| 11691 | } |
| 11692 | if (round + 1 < test_config.num_auth_rounds) { |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11693 | EXPECT_TRUE(response->auth_challenge); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11694 | } else { |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11695 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11696 | } |
| 11697 | } |
[email protected] | e5ae96a | 2010-04-14 20:12:45 | [diff] [blame] | 11698 | } |
| 11699 | } |
| 11700 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11701 | TEST_F(HttpNetworkTransactionTest, MultiRoundAuth) { |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11702 | // Do multi-round authentication and make sure it works correctly. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11703 | HttpAuthHandlerMock::Factory* auth_factory( |
| 11704 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11705 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 11706 | session_deps_.proxy_service = ProxyService::CreateDirect(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11707 | session_deps_.host_resolver->rules()->AddRule("www.example.com", "10.0.0.1"); |
| 11708 | session_deps_.host_resolver->set_synchronous_mode(true); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11709 | |
| 11710 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 11711 | auth_handler->set_connection_based(true); |
| 11712 | std::string auth_challenge = "Mock realm=server"; |
| 11713 | GURL origin("http://www.example.com"); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 11714 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 11715 | auth_challenge.end()); |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 11716 | SSLInfo empty_ssl_info; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11717 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 11718 | empty_ssl_info, origin, BoundNetLog()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 11719 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11720 | |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11721 | int rv = OK; |
| 11722 | const HttpResponseInfo* response = NULL; |
| 11723 | HttpRequestInfo request; |
| 11724 | request.method = "GET"; |
| 11725 | request.url = origin; |
| 11726 | request.load_flags = 0; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11727 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11728 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11729 | |
| 11730 | // Use a TCP Socket Pool with only one connection per group. This is used |
| 11731 | // to validate that the TCP socket is not released to the pool between |
| 11732 | // each round of multi-round authentication. |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11733 | HttpNetworkSessionPeer session_peer(session.get()); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 11734 | TransportClientSocketPool* transport_pool = new TransportClientSocketPool( |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11735 | 50, // Max sockets for pool |
| 11736 | 1, // Max sockets per group |
tbansal | 7b403bcc | 2016-04-13 22:33:21 | [diff] [blame] | 11737 | session_deps_.host_resolver.get(), session_deps_.socket_factory.get(), |
| 11738 | NULL, session_deps_.net_log); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11739 | std::unique_ptr<MockClientSocketPoolManager> mock_pool_manager( |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 11740 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 11741 | mock_pool_manager->SetTransportSocketPool(transport_pool); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 11742 | session_peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11743 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11744 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11745 | TestCompletionCallback callback; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11746 | |
| 11747 | const MockWrite kGet( |
| 11748 | "GET / HTTP/1.1\r\n" |
| 11749 | "Host: www.example.com\r\n" |
| 11750 | "Connection: keep-alive\r\n\r\n"); |
| 11751 | const MockWrite kGetAuth( |
| 11752 | "GET / HTTP/1.1\r\n" |
| 11753 | "Host: www.example.com\r\n" |
| 11754 | "Connection: keep-alive\r\n" |
| 11755 | "Authorization: auth_token\r\n\r\n"); |
| 11756 | |
| 11757 | const MockRead kServerChallenge( |
| 11758 | "HTTP/1.1 401 Unauthorized\r\n" |
| 11759 | "WWW-Authenticate: Mock realm=server\r\n" |
| 11760 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11761 | "Content-Length: 14\r\n\r\n" |
| 11762 | "Unauthorized\r\n"); |
| 11763 | const MockRead kSuccess( |
| 11764 | "HTTP/1.1 200 OK\r\n" |
| 11765 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11766 | "Content-Length: 3\r\n\r\n" |
| 11767 | "Yes"); |
| 11768 | |
| 11769 | MockWrite writes[] = { |
| 11770 | // First round |
| 11771 | kGet, |
| 11772 | // Second round |
| 11773 | kGetAuth, |
| 11774 | // Third round |
| 11775 | kGetAuth, |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 11776 | // Fourth round |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11777 | kGetAuth, |
| 11778 | // Competing request |
| 11779 | kGet, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11780 | }; |
| 11781 | MockRead reads[] = { |
| 11782 | // First round |
| 11783 | kServerChallenge, |
| 11784 | // Second round |
| 11785 | kServerChallenge, |
| 11786 | // Third round |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 11787 | kServerChallenge, |
| 11788 | // Fourth round |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11789 | kSuccess, |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11790 | // Competing response |
| 11791 | kSuccess, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11792 | }; |
| 11793 | StaticSocketDataProvider data_provider(reads, arraysize(reads), |
| 11794 | writes, arraysize(writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11795 | session_deps_.socket_factory->AddSocketDataProvider(&data_provider); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11796 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 11797 | const char kSocketGroup[] = "www.example.com:80"; |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11798 | |
| 11799 | // First round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11800 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11801 | rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11802 | if (rv == ERR_IO_PENDING) |
| 11803 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11804 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11805 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11806 | ASSERT_TRUE(response); |
| 11807 | EXPECT_TRUE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 11808 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11809 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11810 | // In between rounds, another request comes in for the same domain. |
| 11811 | // It should not be able to grab the TCP socket that trans has already |
| 11812 | // claimed. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11813 | HttpNetworkTransaction trans_compete(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11814 | TestCompletionCallback callback_compete; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11815 | rv = |
| 11816 | trans_compete.Start(&request, callback_compete.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11817 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11818 | // callback_compete.WaitForResult at this point would stall forever, |
| 11819 | // since the HttpNetworkTransaction does not release the request back to |
| 11820 | // the pool until after authentication completes. |
| 11821 | |
| 11822 | // Second round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11823 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11824 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11825 | if (rv == ERR_IO_PENDING) |
| 11826 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11827 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11828 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11829 | ASSERT_TRUE(response); |
| 11830 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 11831 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11832 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11833 | // Third round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11834 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11835 | rv = trans.RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11836 | if (rv == ERR_IO_PENDING) |
| 11837 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11838 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11839 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11840 | ASSERT_TRUE(response); |
| 11841 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 11842 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 11843 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11844 | // Fourth round of authentication, which completes successfully. |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 11845 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11846 | rv = trans.RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 11847 | if (rv == ERR_IO_PENDING) |
| 11848 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11849 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11850 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11851 | ASSERT_TRUE(response); |
| 11852 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 11853 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11854 | |
| 11855 | // Read the body since the fourth round was successful. This will also |
| 11856 | // release the socket back to the pool. |
| 11857 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(50)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11858 | rv = trans.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11859 | if (rv == ERR_IO_PENDING) |
| 11860 | rv = callback.WaitForResult(); |
| 11861 | EXPECT_EQ(3, rv); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11862 | rv = trans.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11863 | EXPECT_EQ(0, rv); |
| 11864 | // There are still 0 idle sockets, since the trans_compete transaction |
| 11865 | // will be handed it immediately after trans releases it to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 11866 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11867 | |
| 11868 | // The competing request can now finish. Wait for the headers and then |
| 11869 | // read the body. |
| 11870 | rv = callback_compete.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11871 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11872 | rv = trans_compete.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11873 | if (rv == ERR_IO_PENDING) |
| 11874 | rv = callback.WaitForResult(); |
| 11875 | EXPECT_EQ(3, rv); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11876 | rv = trans_compete.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11877 | EXPECT_EQ(0, rv); |
| 11878 | |
| 11879 | // Finally, the socket is released to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 11880 | EXPECT_EQ(1, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11881 | } |
| 11882 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11883 | // This tests the case that a request is issued via http instead of spdy after |
| 11884 | // npn is negotiated. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11885 | TEST_F(HttpNetworkTransactionTest, NpnWithHttpOverSSL) { |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11886 | HttpRequestInfo request; |
| 11887 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11888 | request.url = GURL("https://www.example.org/"); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11889 | request.load_flags = 0; |
| 11890 | |
| 11891 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11892 | MockWrite( |
| 11893 | "GET / HTTP/1.1\r\n" |
| 11894 | "Host: www.example.org\r\n" |
| 11895 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11896 | }; |
| 11897 | |
| 11898 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11899 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11900 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11901 | MockRead("\r\n"), |
| 11902 | MockRead("hello world"), |
| 11903 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11904 | }; |
| 11905 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11906 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11907 | ssl.next_proto = kProtoHTTP11; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11908 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11909 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11910 | |
| 11911 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 11912 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11913 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11914 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11915 | TestCompletionCallback callback; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11916 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11917 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11918 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11919 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11920 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11921 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11922 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11923 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11924 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11925 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11926 | ASSERT_TRUE(response); |
| 11927 | ASSERT_TRUE(response->headers); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11928 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11929 | |
| 11930 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11931 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11932 | EXPECT_EQ("hello world", response_data); |
| 11933 | |
| 11934 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 11935 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11936 | } |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11937 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11938 | // Simulate the SSL handshake completing with an NPN negotiation followed by an |
| 11939 | // immediate server closing of the socket. |
| 11940 | // Regression test for https://crbug.com/46369. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11941 | TEST_F(HttpNetworkTransactionTest, SpdyPostNPNServerHangup) { |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11942 | HttpRequestInfo request; |
| 11943 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11944 | request.url = GURL("https://www.example.org/"); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11945 | request.load_flags = 0; |
| 11946 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11947 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11948 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11949 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11950 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11951 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 11952 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11953 | MockWrite spdy_writes[] = {CreateMockWrite(req, 1)}; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11954 | |
| 11955 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11956 | MockRead(SYNCHRONOUS, 0, 0) // Not async - return 0 immediately. |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11957 | }; |
| 11958 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11959 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 11960 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11961 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11962 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11963 | TestCompletionCallback callback; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11964 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11965 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11966 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11967 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11968 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11969 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11970 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_CLOSED)); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11971 | } |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 11972 | |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 11973 | // A subclass of HttpAuthHandlerMock that records the request URL when |
| 11974 | // it gets it. This is needed since the auth handler may get destroyed |
| 11975 | // before we get a chance to query it. |
| 11976 | class UrlRecordingHttpAuthHandlerMock : public HttpAuthHandlerMock { |
| 11977 | public: |
| 11978 | explicit UrlRecordingHttpAuthHandlerMock(GURL* url) : url_(url) {} |
| 11979 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11980 | ~UrlRecordingHttpAuthHandlerMock() override {} |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 11981 | |
| 11982 | protected: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11983 | int GenerateAuthTokenImpl(const AuthCredentials* credentials, |
| 11984 | const HttpRequestInfo* request, |
| 11985 | const CompletionCallback& callback, |
| 11986 | std::string* auth_token) override { |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 11987 | *url_ = request->url; |
| 11988 | return HttpAuthHandlerMock::GenerateAuthTokenImpl( |
| 11989 | credentials, request, callback, auth_token); |
| 11990 | } |
| 11991 | |
| 11992 | private: |
| 11993 | GURL* url_; |
| 11994 | }; |
| 11995 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 11996 | // Test that if we cancel the transaction as the connection is completing, that |
| 11997 | // everything tears down correctly. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11998 | TEST_F(HttpNetworkTransactionTest, SimpleCancel) { |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 11999 | // Setup everything about the connection to complete synchronously, so that |
| 12000 | // after calling HttpNetworkTransaction::Start, the only thing we're waiting |
| 12001 | // for is the callback from the HttpStreamRequest. |
| 12002 | // Then cancel the transaction. |
| 12003 | // Verify that we don't crash. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12004 | MockConnect mock_connect(SYNCHRONOUS, OK); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12005 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12006 | MockRead(SYNCHRONOUS, "HTTP/1.0 200 OK\r\n\r\n"), |
| 12007 | MockRead(SYNCHRONOUS, "hello world"), |
| 12008 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12009 | }; |
| 12010 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12011 | HttpRequestInfo request; |
| 12012 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12013 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12014 | request.load_flags = 0; |
| 12015 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12016 | session_deps_.host_resolver->set_synchronous_mode(true); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12017 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12018 | std::unique_ptr<HttpNetworkTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12019 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12020 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12021 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 12022 | data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12023 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12024 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12025 | TestCompletionCallback callback; |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12026 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12027 | BoundTestNetLog log; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12028 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12029 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12030 | trans.reset(); // Cancel the transaction here. |
| 12031 | |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 12032 | base::RunLoop().RunUntilIdle(); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 12033 | } |
| 12034 | |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12035 | // Test that if a transaction is cancelled after receiving the headers, the |
| 12036 | // stream is drained properly and added back to the socket pool. The main |
| 12037 | // purpose of this test is to make sure that an HttpStreamParser can be read |
| 12038 | // from after the HttpNetworkTransaction and the objects it owns have been |
| 12039 | // deleted. |
| 12040 | // See http://crbug.com/368418 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12041 | TEST_F(HttpNetworkTransactionTest, CancelAfterHeaders) { |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12042 | MockRead data_reads[] = { |
| 12043 | MockRead(ASYNC, "HTTP/1.1 200 OK\r\n"), |
| 12044 | MockRead(ASYNC, "Content-Length: 2\r\n"), |
| 12045 | MockRead(ASYNC, "Connection: Keep-Alive\r\n\r\n"), |
| 12046 | MockRead(ASYNC, "1"), |
| 12047 | // 2 async reads are necessary to trigger a ReadResponseBody call after the |
| 12048 | // HttpNetworkTransaction has been deleted. |
| 12049 | MockRead(ASYNC, "2"), |
| 12050 | MockRead(SYNCHRONOUS, ERR_IO_PENDING), // Should never read this. |
| 12051 | }; |
| 12052 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 12053 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12054 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12055 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12056 | |
| 12057 | { |
| 12058 | HttpRequestInfo request; |
| 12059 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12060 | request.url = GURL("http://www.example.org/"); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12061 | request.load_flags = 0; |
| 12062 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12063 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12064 | TestCompletionCallback callback; |
| 12065 | |
| 12066 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12067 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12068 | callback.WaitForResult(); |
| 12069 | |
| 12070 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12071 | ASSERT_TRUE(response); |
| 12072 | EXPECT_TRUE(response->headers); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12073 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12074 | |
| 12075 | // The transaction and HttpRequestInfo are deleted. |
| 12076 | } |
| 12077 | |
| 12078 | // Let the HttpResponseBodyDrainer drain the socket. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 12079 | base::RunLoop().RunUntilIdle(); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12080 | |
| 12081 | // Socket should now be idle, waiting to be reused. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12082 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12083 | } |
| 12084 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12085 | // Test a basic GET request through a proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12086 | TEST_F(HttpNetworkTransactionTest, ProxyGet) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12087 | session_deps_.proxy_service = |
| 12088 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12089 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12090 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12091 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12092 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12093 | HttpRequestInfo request; |
| 12094 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12095 | request.url = GURL("http://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12096 | |
| 12097 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12098 | MockWrite( |
| 12099 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 12100 | "Host: www.example.org\r\n" |
| 12101 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12102 | }; |
| 12103 | |
| 12104 | MockRead data_reads1[] = { |
| 12105 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12106 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 12107 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12108 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12109 | }; |
| 12110 | |
| 12111 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 12112 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12113 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12114 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12115 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12116 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12117 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 12118 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12119 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 12120 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 12121 | base::Unretained(&headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 12122 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12123 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12124 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12125 | |
| 12126 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12127 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12128 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12129 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12130 | ASSERT_TRUE(response); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12131 | |
| 12132 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 12133 | EXPECT_EQ(200, response->headers->response_code()); |
| 12134 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 12135 | EXPECT_TRUE(response->was_fetched_via_proxy); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 12136 | EXPECT_TRUE( |
| 12137 | response->proxy_server.Equals(HostPortPair::FromString("myproxy:70"))); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 12138 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 12139 | EXPECT_TRUE(headers_handler.observed_before_headers_sent_with_proxy()); |
| 12140 | EXPECT_EQ("myproxy:70", headers_handler.observed_proxy_server_uri()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12141 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 12142 | |
| 12143 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12144 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 12145 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 12146 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12147 | } |
| 12148 | |
| 12149 | // Test a basic HTTPS GET request through a proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12150 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGet) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12151 | session_deps_.proxy_service = |
| 12152 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12153 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12154 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12155 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12156 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12157 | HttpRequestInfo request; |
| 12158 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12159 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12160 | |
| 12161 | // Since we have proxy, should try to establish tunnel. |
| 12162 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12163 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 12164 | "Host: www.example.org:443\r\n" |
| 12165 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12166 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12167 | MockWrite("GET / HTTP/1.1\r\n" |
| 12168 | "Host: www.example.org\r\n" |
| 12169 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12170 | }; |
| 12171 | |
| 12172 | MockRead data_reads1[] = { |
| 12173 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 12174 | |
| 12175 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12176 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 12177 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12178 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12179 | }; |
| 12180 | |
| 12181 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 12182 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12183 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12184 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12185 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12186 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12187 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12188 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12189 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 12190 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12191 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 12192 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 12193 | base::Unretained(&headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 12194 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12195 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12196 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12197 | |
| 12198 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12199 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 12200 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 12201 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12202 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 12203 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 12204 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12205 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 12206 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 12207 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 12208 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12209 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12210 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12211 | ASSERT_TRUE(response); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12212 | |
| 12213 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 12214 | EXPECT_EQ(200, response->headers->response_code()); |
| 12215 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 12216 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 12217 | EXPECT_TRUE(response->was_fetched_via_proxy); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 12218 | EXPECT_TRUE( |
| 12219 | response->proxy_server.Equals(HostPortPair::FromString("myproxy:70"))); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 12220 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 12221 | EXPECT_TRUE(headers_handler.observed_before_headers_sent_with_proxy()); |
| 12222 | EXPECT_EQ("myproxy:70", headers_handler.observed_proxy_server_uri()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 12223 | |
| 12224 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12225 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 12226 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 12227 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12228 | } |
| 12229 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12230 | // Test a basic HTTPS GET request through a proxy, connecting to an IPv6 |
| 12231 | // literal host. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12232 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGetIPv6) { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12233 | session_deps_.proxy_service = |
| 12234 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 12235 | BoundTestNetLog log; |
| 12236 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12237 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12238 | |
| 12239 | HttpRequestInfo request; |
| 12240 | request.method = "GET"; |
| 12241 | request.url = GURL("https://[::1]:443/"); |
| 12242 | |
| 12243 | // Since we have proxy, should try to establish tunnel. |
| 12244 | MockWrite data_writes1[] = { |
| 12245 | MockWrite("CONNECT [::1]:443 HTTP/1.1\r\n" |
| 12246 | "Host: [::1]:443\r\n" |
| 12247 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 12248 | |
| 12249 | MockWrite("GET / HTTP/1.1\r\n" |
| 12250 | "Host: [::1]\r\n" |
| 12251 | "Connection: keep-alive\r\n\r\n"), |
| 12252 | }; |
| 12253 | |
| 12254 | MockRead data_reads1[] = { |
| 12255 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 12256 | |
| 12257 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12258 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 12259 | MockRead("Content-Length: 100\r\n\r\n"), |
| 12260 | MockRead(SYNCHRONOUS, OK), |
| 12261 | }; |
| 12262 | |
| 12263 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 12264 | data_writes1, arraysize(data_writes1)); |
| 12265 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 12266 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 12267 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12268 | |
| 12269 | TestCompletionCallback callback1; |
| 12270 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12271 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12272 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12273 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12274 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12275 | |
| 12276 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12277 | EXPECT_THAT(rv, IsOk()); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12278 | TestNetLogEntry::List entries; |
| 12279 | log.GetEntries(&entries); |
| 12280 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 12281 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 12282 | NetLogEventPhase::NONE); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12283 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 12284 | entries, pos, |
| 12285 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 12286 | NetLogEventPhase::NONE); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12287 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12288 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12289 | ASSERT_TRUE(response); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12290 | |
| 12291 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 12292 | EXPECT_EQ(200, response->headers->response_code()); |
| 12293 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 12294 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 12295 | EXPECT_TRUE(response->was_fetched_via_proxy); |
| 12296 | EXPECT_TRUE( |
| 12297 | response->proxy_server.Equals(HostPortPair::FromString("myproxy:70"))); |
| 12298 | |
| 12299 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12300 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12301 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 12302 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 12303 | } |
| 12304 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12305 | // Test a basic HTTPS GET request through a proxy, but the server hangs up |
| 12306 | // while establishing the tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12307 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGetHangup) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12308 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12309 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12310 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12311 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12312 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12313 | HttpRequestInfo request; |
| 12314 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12315 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12316 | |
| 12317 | // Since we have proxy, should try to establish tunnel. |
| 12318 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12319 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 12320 | "Host: www.example.org:443\r\n" |
| 12321 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12322 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12323 | MockWrite("GET / HTTP/1.1\r\n" |
| 12324 | "Host: www.example.org\r\n" |
| 12325 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12326 | }; |
| 12327 | |
| 12328 | MockRead data_reads1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12329 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12330 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12331 | MockRead(ASYNC, 0, 0), // EOF |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12332 | }; |
| 12333 | |
| 12334 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 12335 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12336 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12337 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12338 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12339 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12340 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12341 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12342 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 12343 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12344 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12345 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12346 | |
| 12347 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12348 | EXPECT_THAT(rv, IsError(ERR_EMPTY_RESPONSE)); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 12349 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 12350 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12351 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 12352 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 12353 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12354 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 12355 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 12356 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 12357 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12358 | } |
| 12359 | |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12360 | // Test for crbug.com/55424. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12361 | TEST_F(HttpNetworkTransactionTest, PreconnectWithExistingSpdySession) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12362 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 12363 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12364 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12365 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 12366 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12367 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12368 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12369 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12370 | }; |
| 12371 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12372 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 12373 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12374 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12375 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12376 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12377 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12378 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12379 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12380 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12381 | |
| 12382 | // Set up an initial SpdySession in the pool to reuse. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12383 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 12384 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 12385 | PRIVACY_MODE_DISABLED); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 12386 | base::WeakPtr<SpdySession> spdy_session = |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12387 | CreateInsecureSpdySession(session.get(), key, BoundNetLog()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12388 | |
| 12389 | HttpRequestInfo request; |
| 12390 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12391 | request.url = GURL("https://www.example.org/"); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12392 | request.load_flags = 0; |
| 12393 | |
| 12394 | // This is the important line that marks this as a preconnect. |
| 12395 | request.motivation = HttpRequestInfo::PRECONNECT_MOTIVATED; |
| 12396 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12397 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12398 | |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 12399 | TestCompletionCallback callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12400 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12401 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12402 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12403 | } |
| 12404 | |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 12405 | // Given a net error, cause that error to be returned from the first Write() |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12406 | // call and verify that the HttpNetworkTransaction fails with that error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12407 | void HttpNetworkTransactionTest::CheckErrorIsPassedBack( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12408 | int error, IoMode mode) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12409 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12410 | request_info.url = GURL("https://www.example.com/"); |
| 12411 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12412 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12413 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12414 | SSLSocketDataProvider ssl_data(mode, OK); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12415 | MockWrite data_writes[] = { |
| 12416 | MockWrite(mode, error), |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 12417 | }; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12418 | StaticSocketDataProvider data(NULL, 0, data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12419 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12420 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 12421 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12422 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12423 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 12424 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12425 | TestCompletionCallback callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12426 | int rv = trans.Start(&request_info, callback.callback(), BoundNetLog()); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12427 | if (rv == ERR_IO_PENDING) |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 12428 | rv = callback.WaitForResult(); |
| 12429 | ASSERT_EQ(error, rv); |
| 12430 | } |
| 12431 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12432 | TEST_F(HttpNetworkTransactionTest, SSLWriteCertError) { |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 12433 | // Just check a grab bag of cert errors. |
| 12434 | static const int kErrors[] = { |
| 12435 | ERR_CERT_COMMON_NAME_INVALID, |
| 12436 | ERR_CERT_AUTHORITY_INVALID, |
| 12437 | ERR_CERT_DATE_INVALID, |
| 12438 | }; |
| 12439 | for (size_t i = 0; i < arraysize(kErrors); i++) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12440 | CheckErrorIsPassedBack(kErrors[i], ASYNC); |
| 12441 | CheckErrorIsPassedBack(kErrors[i], SYNCHRONOUS); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 12442 | } |
| 12443 | } |
| 12444 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12445 | // Ensure that a client certificate is removed from the SSL client auth |
| 12446 | // cache when: |
| 12447 | // 1) No proxy is involved. |
| 12448 | // 2) TLS False Start is disabled. |
| 12449 | // 3) The initial TLS handshake requests a client certificate. |
| 12450 | // 4) The client supplies an invalid/unacceptable certificate. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12451 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_NoFalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12452 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12453 | request_info.url = GURL("https://www.example.com/"); |
| 12454 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12455 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12456 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12457 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12458 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12459 | |
| 12460 | // [ssl_]data1 contains the data for the first SSL handshake. When a |
| 12461 | // CertificateRequest is received for the first time, the handshake will |
| 12462 | // be aborted to allow the caller to provide a certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12463 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12464 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12465 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12466 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12467 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12468 | |
| 12469 | // [ssl_]data2 contains the data for the second SSL handshake. When TLS |
| 12470 | // False Start is not being used, the result of the SSL handshake will be |
| 12471 | // returned as part of the SSLClientSocket::Connect() call. This test |
| 12472 | // matches the result of a server sending a handshake_failure alert, |
| 12473 | // rather than a Finished message, because it requires a client |
| 12474 | // certificate and none was supplied. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12475 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12476 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12477 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12478 | StaticSocketDataProvider data2(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12479 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12480 | |
| 12481 | // [ssl_]data3 contains the data for the third SSL handshake. When a |
| 12482 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 12483 | // HttpNetworkTransaction will attempt to fallback to TLSv1.1 if the previous |
| 12484 | // connection was attempted with TLSv1.2. This is transparent to the caller |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12485 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 12486 | // requiring a client certificate, this fallback handshake should also |
| 12487 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12488 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12489 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12490 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12491 | StaticSocketDataProvider data3(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12492 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12493 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12494 | // [ssl_]data4 contains the data for the fourth SSL handshake. When a |
| 12495 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 12496 | // HttpNetworkTransaction will attempt to fallback to TLSv1 if the previous |
| 12497 | // connection was attempted with TLSv1.1. This is transparent to the caller |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12498 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 12499 | // requiring a client certificate, this fallback handshake should also |
| 12500 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12501 | SSLSocketDataProvider ssl_data4(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12502 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12503 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12504 | StaticSocketDataProvider data4(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12505 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12506 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12507 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12508 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12509 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12510 | // Begin the SSL handshake with the peer. This consumes ssl_data1. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12511 | TestCompletionCallback callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12512 | int rv = trans.Start(&request_info, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12513 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12514 | |
| 12515 | // Complete the SSL handshake, which should abort due to requiring a |
| 12516 | // client certificate. |
| 12517 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12518 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12519 | |
| 12520 | // Indicate that no certificate should be supplied. From the perspective |
| 12521 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 12522 | // certificate, so this is the same as supply a |
| 12523 | // legitimate-but-unacceptable certificate. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12524 | rv = trans.RestartWithCertificate(NULL, NULL, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12525 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12526 | |
| 12527 | // Ensure the certificate was added to the client auth cache before |
| 12528 | // allowing the connection to continue restarting. |
| 12529 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12530 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12531 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12532 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12533 | ASSERT_FALSE(client_cert); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12534 | |
| 12535 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12536 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 12537 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12538 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12539 | ASSERT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12540 | |
| 12541 | // Ensure that the client certificate is removed from the cache on a |
| 12542 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12543 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12544 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12545 | } |
| 12546 | |
| 12547 | // Ensure that a client certificate is removed from the SSL client auth |
| 12548 | // cache when: |
| 12549 | // 1) No proxy is involved. |
| 12550 | // 2) TLS False Start is enabled. |
| 12551 | // 3) The initial TLS handshake requests a client certificate. |
| 12552 | // 4) The client supplies an invalid/unacceptable certificate. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12553 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_FalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12554 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12555 | request_info.url = GURL("https://www.example.com/"); |
| 12556 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12557 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12558 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12559 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12560 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12561 | |
| 12562 | // When TLS False Start is used, SSLClientSocket::Connect() calls will |
| 12563 | // return successfully after reading up to the peer's Certificate message. |
| 12564 | // This is to allow the caller to call SSLClientSocket::Write(), which can |
| 12565 | // enqueue application data to be sent in the same packet as the |
| 12566 | // ChangeCipherSpec and Finished messages. |
| 12567 | // The actual handshake will be finished when SSLClientSocket::Read() is |
| 12568 | // called, which expects to process the peer's ChangeCipherSpec and |
| 12569 | // Finished messages. If there was an error negotiating with the peer, |
| 12570 | // such as due to the peer requiring a client certificate when none was |
| 12571 | // supplied, the alert sent by the peer won't be processed until Read() is |
| 12572 | // called. |
| 12573 | |
| 12574 | // Like the non-False Start case, when a client certificate is requested by |
| 12575 | // the peer, the handshake is aborted during the Connect() call. |
| 12576 | // [ssl_]data1 represents the initial SSL handshake with the peer. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12577 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12578 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12579 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12580 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12581 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12582 | |
| 12583 | // When a client certificate is supplied, Connect() will not be aborted |
| 12584 | // when the peer requests the certificate. Instead, the handshake will |
| 12585 | // artificially succeed, allowing the caller to write the HTTP request to |
| 12586 | // the socket. The handshake messages are not processed until Read() is |
| 12587 | // called, which then detects that the handshake was aborted, due to the |
| 12588 | // peer sending a handshake_failure because it requires a client |
| 12589 | // certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12590 | SSLSocketDataProvider ssl_data2(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12591 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12592 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12593 | MockRead data2_reads[] = { |
| 12594 | MockRead(ASYNC /* async */, ERR_SSL_PROTOCOL_ERROR), |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12595 | }; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12596 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12597 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12598 | |
| 12599 | // As described in ClientAuthCertCache_Direct_NoFalseStart, [ssl_]data3 is |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12600 | // the data for the SSL handshake once the TLSv1.1 connection falls back to |
| 12601 | // TLSv1. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12602 | SSLSocketDataProvider ssl_data3(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12603 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12604 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12605 | StaticSocketDataProvider data3(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12606 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12607 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12608 | // [ssl_]data4 is the data for the SSL handshake once the TLSv1 connection |
| 12609 | // falls back to SSLv3. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12610 | SSLSocketDataProvider ssl_data4(ASYNC, OK); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12611 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12612 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12613 | StaticSocketDataProvider data4(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12614 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12615 | |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 12616 | // Need one more if TLSv1.2 is enabled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12617 | SSLSocketDataProvider ssl_data5(ASYNC, OK); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 12618 | ssl_data5.cert_request_info = cert_request.get(); |
| 12619 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data5); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12620 | StaticSocketDataProvider data5(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 12621 | session_deps_.socket_factory->AddSocketDataProvider(&data5); |
| 12622 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12623 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12624 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12625 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12626 | // Begin the initial SSL handshake. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12627 | TestCompletionCallback callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12628 | int rv = trans.Start(&request_info, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12629 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12630 | |
| 12631 | // Complete the SSL handshake, which should abort due to requiring a |
| 12632 | // client certificate. |
| 12633 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12634 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12635 | |
| 12636 | // Indicate that no certificate should be supplied. From the perspective |
| 12637 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 12638 | // certificate, so this is the same as supply a |
| 12639 | // legitimate-but-unacceptable certificate. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12640 | rv = trans.RestartWithCertificate(NULL, NULL, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12641 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12642 | |
| 12643 | // Ensure the certificate was added to the client auth cache before |
| 12644 | // allowing the connection to continue restarting. |
| 12645 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12646 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12647 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12648 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12649 | ASSERT_FALSE(client_cert); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12650 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12651 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12652 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 12653 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12654 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12655 | ASSERT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12656 | |
| 12657 | // Ensure that the client certificate is removed from the cache on a |
| 12658 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12659 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12660 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12661 | } |
| 12662 | |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12663 | // Ensure that a client certificate is removed from the SSL client auth |
| 12664 | // cache when: |
| 12665 | // 1) An HTTPS proxy is involved. |
| 12666 | // 3) The HTTPS proxy requests a client certificate. |
| 12667 | // 4) The client supplies an invalid/unacceptable certificate for the |
| 12668 | // proxy. |
| 12669 | // The test is repeated twice, first for connecting to an HTTPS endpoint, |
| 12670 | // then for connecting to an HTTP endpoint. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12671 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Proxy_Fail) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12672 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12673 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12674 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12675 | |
| 12676 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12677 | cert_request->host_and_port = HostPortPair("proxy", 70); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12678 | |
| 12679 | // See ClientAuthCertCache_Direct_NoFalseStart for the explanation of |
| 12680 | // [ssl_]data[1-3]. Rather than represending the endpoint |
| 12681 | // (www.example.com:443), they represent failures with the HTTPS proxy |
| 12682 | // (proxy:70). |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12683 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12684 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12685 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12686 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12687 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12688 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12689 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12690 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12691 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12692 | StaticSocketDataProvider data2(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12693 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12694 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12695 | // TODO(wtc): find out why this unit test doesn't need [ssl_]data3. |
| 12696 | #if 0 |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12697 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12698 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12699 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12700 | StaticSocketDataProvider data3(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12701 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12702 | #endif |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12703 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12704 | HttpRequestInfo requests[2]; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12705 | requests[0].url = GURL("https://www.example.com/"); |
| 12706 | requests[0].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12707 | requests[0].load_flags = LOAD_NORMAL; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12708 | |
| 12709 | requests[1].url = GURL("http://www.example.com/"); |
| 12710 | requests[1].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12711 | requests[1].load_flags = LOAD_NORMAL; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12712 | |
| 12713 | for (size_t i = 0; i < arraysize(requests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12714 | session_deps_.socket_factory->ResetNextMockIndexes(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12715 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12716 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12717 | |
| 12718 | // Begin the SSL handshake with the proxy. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12719 | TestCompletionCallback callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12720 | int rv = trans.Start(&requests[i], callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12721 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12722 | |
| 12723 | // Complete the SSL handshake, which should abort due to requiring a |
| 12724 | // client certificate. |
| 12725 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12726 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12727 | |
| 12728 | // Indicate that no certificate should be supplied. From the perspective |
| 12729 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 12730 | // certificate, so this is the same as supply a |
| 12731 | // legitimate-but-unacceptable certificate. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12732 | rv = trans.RestartWithCertificate(NULL, NULL, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12733 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12734 | |
| 12735 | // Ensure the certificate was added to the client auth cache before |
| 12736 | // allowing the connection to continue restarting. |
| 12737 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12738 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12739 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12740 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12741 | ASSERT_FALSE(client_cert); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12742 | // Ensure the certificate was NOT cached for the endpoint. This only |
| 12743 | // applies to HTTPS requests, but is fine to check for HTTP requests. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12744 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12745 | HostPortPair("www.example.com", 443), &client_cert, |
| 12746 | &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12747 | |
| 12748 | // Restart the handshake. This will consume ssl_data2, which fails, and |
| 12749 | // then consume ssl_data3, which should also fail. The result code is |
| 12750 | // checked against what ssl_data3 should return. |
| 12751 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12752 | ASSERT_THAT(rv, IsError(ERR_PROXY_CONNECTION_FAILED)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12753 | |
| 12754 | // Now that the new handshake has failed, ensure that the client |
| 12755 | // certificate was removed from the client auth cache. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12756 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12757 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12758 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12759 | HostPortPair("www.example.com", 443), &client_cert, |
| 12760 | &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12761 | } |
| 12762 | } |
| 12763 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12764 | TEST_F(HttpNetworkTransactionTest, UseIPConnectionPooling) { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12765 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12766 | session_deps_.host_resolver.reset(new MockCachingHostResolver()); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12767 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | b9ec688 | 2011-07-01 07:40:26 | [diff] [blame] | 12768 | SpdySessionPoolPeer pool_peer(session->spdy_session_pool()); |
| 12769 | pool_peer.DisableDomainAuthenticationVerification(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12770 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12771 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12772 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12773 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12774 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12775 | SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 12776 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 12777 | spdy_util_.UpdateWithStreamDestruction(1); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12778 | SpdySerializedFrame host2_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 12779 | spdy_util_.ConstructSpdyGet("https://www.gmail.com", 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12780 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12781 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12782 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 12783 | SpdySerializedFrame host1_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12784 | SpdySerializedFrame host1_resp_body( |
| 12785 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 12786 | SpdySerializedFrame host2_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12787 | SpdySerializedFrame host2_resp_body( |
| 12788 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12789 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12790 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 12791 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12792 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12793 | }; |
| 12794 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 12795 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12796 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12797 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 12798 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12799 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12800 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 12801 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12802 | HttpRequestInfo request1; |
| 12803 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12804 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12805 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12806 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12807 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12808 | int rv = trans1.Start(&request1, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12809 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12810 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12811 | |
| 12812 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12813 | ASSERT_TRUE(response); |
| 12814 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12815 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12816 | |
| 12817 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12818 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12819 | EXPECT_EQ("hello!", response_data); |
| 12820 | |
| 12821 | // Preload www.gmail.com into HostCache. |
| 12822 | HostPortPair host_port("www.gmail.com", 443); |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 12823 | HostResolver::RequestInfo resolve_info(host_port); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12824 | AddressList ignored; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 12825 | std::unique_ptr<HostResolver::Request> request; |
| 12826 | rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 12827 | &ignored, callback.callback(), |
| 12828 | &request, BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12829 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 12830 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12831 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12832 | |
| 12833 | HttpRequestInfo request2; |
| 12834 | request2.method = "GET"; |
| 12835 | request2.url = GURL("https://www.gmail.com/"); |
| 12836 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12837 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12838 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12839 | rv = trans2.Start(&request2, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12840 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12841 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12842 | |
| 12843 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12844 | ASSERT_TRUE(response); |
| 12845 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12846 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12847 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 12848 | EXPECT_TRUE(response->was_npn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12849 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12850 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12851 | } |
| 12852 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12853 | TEST_F(HttpNetworkTransactionTest, UseIPConnectionPoolingAfterResolution) { |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12854 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12855 | session_deps_.host_resolver.reset(new MockCachingHostResolver()); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12856 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12857 | SpdySessionPoolPeer pool_peer(session->spdy_session_pool()); |
| 12858 | pool_peer.DisableDomainAuthenticationVerification(); |
| 12859 | |
| 12860 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12861 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12862 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12863 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12864 | SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 12865 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 12866 | spdy_util_.UpdateWithStreamDestruction(1); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12867 | SpdySerializedFrame host2_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 12868 | spdy_util_.ConstructSpdyGet("https://www.gmail.com", 3, LOWEST)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12869 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12870 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12871 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 12872 | SpdySerializedFrame host1_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12873 | SpdySerializedFrame host1_resp_body( |
| 12874 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 12875 | SpdySerializedFrame host2_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12876 | SpdySerializedFrame host2_resp_body( |
| 12877 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12878 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12879 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 12880 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12881 | MockRead(ASYNC, 0, 6), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12882 | }; |
| 12883 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 12884 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12885 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12886 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 12887 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12888 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12889 | |
| 12890 | TestCompletionCallback callback; |
| 12891 | HttpRequestInfo request1; |
| 12892 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12893 | request1.url = GURL("https://www.example.org/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12894 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12895 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12896 | |
| 12897 | int rv = trans1.Start(&request1, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12898 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12899 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12900 | |
| 12901 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12902 | ASSERT_TRUE(response); |
| 12903 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12904 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12905 | |
| 12906 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12907 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12908 | EXPECT_EQ("hello!", response_data); |
| 12909 | |
| 12910 | HttpRequestInfo request2; |
| 12911 | request2.method = "GET"; |
| 12912 | request2.url = GURL("https://www.gmail.com/"); |
| 12913 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12914 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12915 | |
| 12916 | rv = trans2.Start(&request2, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12917 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12918 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12919 | |
| 12920 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12921 | ASSERT_TRUE(response); |
| 12922 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12923 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12924 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 12925 | EXPECT_TRUE(response->was_npn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12926 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12927 | EXPECT_EQ("hello!", response_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12928 | } |
| 12929 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12930 | class OneTimeCachingHostResolver : public HostResolver { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12931 | public: |
| 12932 | explicit OneTimeCachingHostResolver(const HostPortPair& host_port) |
| 12933 | : host_port_(host_port) {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12934 | ~OneTimeCachingHostResolver() override {} |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12935 | |
| 12936 | RuleBasedHostResolverProc* rules() { return host_resolver_.rules(); } |
| 12937 | |
| 12938 | // HostResolver methods: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12939 | int Resolve(const RequestInfo& info, |
| 12940 | RequestPriority priority, |
| 12941 | AddressList* addresses, |
| 12942 | const CompletionCallback& callback, |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 12943 | std::unique_ptr<Request>* out_req, |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12944 | const BoundNetLog& net_log) override { |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 12945 | return host_resolver_.Resolve( |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 12946 | info, priority, addresses, callback, out_req, net_log); |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 12947 | } |
| 12948 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12949 | int ResolveFromCache(const RequestInfo& info, |
| 12950 | AddressList* addresses, |
| 12951 | const BoundNetLog& net_log) override { |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 12952 | int rv = host_resolver_.ResolveFromCache(info, addresses, net_log); |
| 12953 | if (rv == OK && info.host_port_pair().Equals(host_port_)) |
[email protected] | 98e1cd01 | 2011-11-08 15:33:09 | [diff] [blame] | 12954 | host_resolver_.GetHostCache()->clear(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12955 | return rv; |
| 12956 | } |
| 12957 | |
[email protected] | 46da33be | 2011-07-19 21:58:04 | [diff] [blame] | 12958 | MockCachingHostResolver* GetMockHostResolver() { |
| 12959 | return &host_resolver_; |
| 12960 | } |
| 12961 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12962 | private: |
| 12963 | MockCachingHostResolver host_resolver_; |
| 12964 | const HostPortPair host_port_; |
| 12965 | }; |
| 12966 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12967 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 5c64213 | 2015-06-02 16:05:13 | [diff] [blame] | 12968 | UseIPConnectionPoolingWithHostCacheExpiration) { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12969 | // Set up a special HttpNetworkSession with a OneTimeCachingHostResolver. |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12970 | OneTimeCachingHostResolver host_resolver(HostPortPair("www.gmail.com", 443)); |
[email protected] | c6bf815 | 2012-12-02 07:43:34 | [diff] [blame] | 12971 | HttpNetworkSession::Params params = |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12972 | SpdySessionDependencies::CreateSessionParams(&session_deps_); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12973 | params.host_resolver = &host_resolver; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12974 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | b9ec688 | 2011-07-01 07:40:26 | [diff] [blame] | 12975 | SpdySessionPoolPeer pool_peer(session->spdy_session_pool()); |
| 12976 | pool_peer.DisableDomainAuthenticationVerification(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12977 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12978 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12979 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12980 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12981 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12982 | SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 12983 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 12984 | spdy_util_.UpdateWithStreamDestruction(1); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12985 | SpdySerializedFrame host2_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 12986 | spdy_util_.ConstructSpdyGet("https://www.gmail.com", 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12987 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12988 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12989 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 12990 | SpdySerializedFrame host1_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12991 | SpdySerializedFrame host1_resp_body( |
| 12992 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 12993 | SpdySerializedFrame host2_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12994 | SpdySerializedFrame host2_resp_body( |
| 12995 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12996 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12997 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 12998 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12999 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13000 | }; |
| 13001 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 13002 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13003 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13004 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 13005 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13006 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13007 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 13008 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13009 | HttpRequestInfo request1; |
| 13010 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13011 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13012 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13013 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13014 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13015 | int rv = trans1.Start(&request1, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13016 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13017 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13018 | |
| 13019 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13020 | ASSERT_TRUE(response); |
| 13021 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13022 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13023 | |
| 13024 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13025 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13026 | EXPECT_EQ("hello!", response_data); |
| 13027 | |
| 13028 | // Preload cache entries into HostCache. |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 13029 | HostResolver::RequestInfo resolve_info(HostPortPair("www.gmail.com", 443)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13030 | AddressList ignored; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 13031 | std::unique_ptr<HostResolver::Request> request; |
| 13032 | rv = host_resolver.Resolve(resolve_info, DEFAULT_PRIORITY, &ignored, |
| 13033 | callback.callback(), &request, BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13034 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 13035 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13036 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13037 | |
| 13038 | HttpRequestInfo request2; |
| 13039 | request2.method = "GET"; |
| 13040 | request2.url = GURL("https://www.gmail.com/"); |
| 13041 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13042 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13043 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13044 | rv = trans2.Start(&request2, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13045 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13046 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13047 | |
| 13048 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13049 | ASSERT_TRUE(response); |
| 13050 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13051 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13052 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 13053 | EXPECT_TRUE(response->was_npn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13054 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13055 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13056 | } |
| 13057 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13058 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttp) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13059 | const std::string https_url = "https://www.example.org:8080/"; |
| 13060 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13061 | |
| 13062 | // SPDY GET for HTTPS URL |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13063 | SpdySerializedFrame req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13064 | spdy_util_.ConstructSpdyGet(https_url.c_str(), 1, LOWEST)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13065 | |
| 13066 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13067 | CreateMockWrite(req1, 0), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13068 | }; |
| 13069 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13070 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13071 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 13072 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 13073 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3)}; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13074 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13075 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 13076 | arraysize(writes1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13077 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 13078 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13079 | |
| 13080 | // HTTP GET for the HTTP URL |
| 13081 | MockWrite writes2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13082 | MockWrite(ASYNC, 0, |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 13083 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13084 | "Host: www.example.org:8080\r\n" |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 13085 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13086 | }; |
| 13087 | |
| 13088 | MockRead reads2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13089 | MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 13090 | MockRead(ASYNC, 2, "hello"), |
| 13091 | MockRead(ASYNC, OK, 3), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13092 | }; |
| 13093 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13094 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 13095 | arraysize(writes2)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13096 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13097 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13098 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13099 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13100 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 13101 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13102 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13103 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13104 | |
| 13105 | // Start the first transaction to set up the SpdySession |
| 13106 | HttpRequestInfo request1; |
| 13107 | request1.method = "GET"; |
| 13108 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13109 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13110 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13111 | TestCompletionCallback callback1; |
| 13112 | EXPECT_EQ(ERR_IO_PENDING, |
| 13113 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 13114 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13115 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13116 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13117 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 13118 | |
| 13119 | // Now, start the HTTP request |
| 13120 | HttpRequestInfo request2; |
| 13121 | request2.method = "GET"; |
| 13122 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13123 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13124 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13125 | TestCompletionCallback callback2; |
| 13126 | EXPECT_EQ(ERR_IO_PENDING, |
| 13127 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 13128 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13129 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13130 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13131 | EXPECT_FALSE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 13132 | } |
| 13133 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13134 | // Alternative service requires HTTP/2 (or SPDY), but HTTP/1.1 is negotiated |
| 13135 | // with the alternative server. That connection should not be used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13136 | TEST_F(HttpNetworkTransactionTest, AlternativeServiceNotOnHttp11) { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13137 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 13138 | HostPortPair alternative("www.example.org", 444); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13139 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13140 | // Negotiate HTTP/1.1 with alternative. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13141 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13142 | ssl.next_proto = kProtoHTTP11; |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13143 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13144 | |
| 13145 | // No data should be read from the alternative, because HTTP/1.1 is |
| 13146 | // negotiated. |
| 13147 | StaticSocketDataProvider data; |
| 13148 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13149 | |
| 13150 | // 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] | 13151 | // negotiated. In order to test this, a failed connection to the server is |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13152 | // mocked. This way the request relies on the alternate Job. |
| 13153 | StaticSocketDataProvider data_refused; |
| 13154 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 13155 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 13156 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 13157 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13158 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 13159 | HttpServerProperties* http_server_properties = |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13160 | session->http_server_properties(); |
| 13161 | AlternativeService alternative_service( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 13162 | AlternateProtocolFromNextProto(kProtoHTTP2), alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 13163 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 13164 | http_server_properties->SetAlternativeService(server, alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 13165 | expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13166 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13167 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13168 | HttpRequestInfo request; |
| 13169 | request.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13170 | request.url = GURL("https://www.example.org:443"); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13171 | request.load_flags = 0; |
| 13172 | TestCompletionCallback callback; |
| 13173 | |
| 13174 | // HTTP/2 (or SPDY) is required for alternative service, if HTTP/1.1 is |
| 13175 | // negotiated, the alternate Job should fail with ERR_NPN_NEGOTIATION_FAILED. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13176 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13177 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_NPN_NEGOTIATION_FAILED)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13178 | } |
| 13179 | |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13180 | // 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] | 13181 | // server, and an alternate one to the alternative server. If the former |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13182 | // succeeds, the request should succeed, even if the latter fails because |
| 13183 | // HTTP/1.1 is negotiated which is insufficient for alternative service. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13184 | TEST_F(HttpNetworkTransactionTest, FailedAlternativeServiceIsNotUserVisible) { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13185 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 13186 | HostPortPair alternative("www.example.org", 444); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13187 | |
| 13188 | // Negotiate HTTP/1.1 with alternative. |
| 13189 | SSLSocketDataProvider alternative_ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13190 | alternative_ssl.next_proto = kProtoHTTP11; |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13191 | session_deps_.socket_factory->AddSSLSocketDataProvider(&alternative_ssl); |
| 13192 | |
| 13193 | // No data should be read from the alternative, because HTTP/1.1 is |
| 13194 | // negotiated. |
| 13195 | StaticSocketDataProvider data; |
| 13196 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13197 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 13198 | // Negotiate HTTP/1.1 with server. |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13199 | SSLSocketDataProvider origin_ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13200 | origin_ssl.next_proto = kProtoHTTP11; |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13201 | session_deps_.socket_factory->AddSSLSocketDataProvider(&origin_ssl); |
| 13202 | |
| 13203 | MockWrite http_writes[] = { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13204 | MockWrite("GET / HTTP/1.1\r\n" |
| 13205 | "Host: www.example.org\r\n" |
| 13206 | "Connection: keep-alive\r\n\r\n"), |
| 13207 | MockWrite("GET /second HTTP/1.1\r\n" |
| 13208 | "Host: www.example.org\r\n" |
| 13209 | "Connection: keep-alive\r\n\r\n"), |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13210 | }; |
| 13211 | |
| 13212 | MockRead http_reads[] = { |
| 13213 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13214 | MockRead("Content-Type: text/html\r\n"), |
| 13215 | MockRead("Content-Length: 6\r\n\r\n"), |
| 13216 | MockRead("foobar"), |
| 13217 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13218 | MockRead("Content-Type: text/html\r\n"), |
| 13219 | MockRead("Content-Length: 7\r\n\r\n"), |
| 13220 | MockRead("another"), |
| 13221 | }; |
| 13222 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 13223 | http_writes, arraysize(http_writes)); |
| 13224 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 13225 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 13226 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13227 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 13228 | HttpServerProperties* http_server_properties = |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13229 | session->http_server_properties(); |
| 13230 | AlternativeService alternative_service( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 13231 | AlternateProtocolFromNextProto(kProtoHTTP2), alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 13232 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 13233 | http_server_properties->SetAlternativeService(server, alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 13234 | expiration); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13235 | |
| 13236 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 13237 | HttpRequestInfo request1; |
| 13238 | request1.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13239 | request1.url = GURL("https://www.example.org:443"); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13240 | request1.load_flags = 0; |
| 13241 | TestCompletionCallback callback1; |
| 13242 | |
| 13243 | int rv = trans1.Start(&request1, callback1.callback(), BoundNetLog()); |
| 13244 | rv = callback1.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13245 | EXPECT_THAT(rv, IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13246 | |
| 13247 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13248 | ASSERT_TRUE(response1); |
| 13249 | ASSERT_TRUE(response1->headers); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13250 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
| 13251 | |
| 13252 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13253 | ASSERT_THAT(ReadTransaction(&trans1, &response_data1), IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13254 | EXPECT_EQ("foobar", response_data1); |
| 13255 | |
| 13256 | // Alternative should be marked as broken, because HTTP/1.1 is not sufficient |
| 13257 | // for alternative service. |
| 13258 | EXPECT_TRUE( |
| 13259 | http_server_properties->IsAlternativeServiceBroken(alternative_service)); |
| 13260 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 13261 | // Since |alternative_service| is broken, a second transaction to server |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13262 | // should not start an alternate Job. It should pool to existing connection |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 13263 | // to server. |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13264 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 13265 | HttpRequestInfo request2; |
| 13266 | request2.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13267 | request2.url = GURL("https://www.example.org:443/second"); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13268 | request2.load_flags = 0; |
| 13269 | TestCompletionCallback callback2; |
| 13270 | |
| 13271 | rv = trans2.Start(&request2, callback2.callback(), BoundNetLog()); |
| 13272 | rv = callback2.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13273 | EXPECT_THAT(rv, IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13274 | |
| 13275 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13276 | ASSERT_TRUE(response2); |
| 13277 | ASSERT_TRUE(response2->headers); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13278 | EXPECT_EQ("HTTP/1.1 200 OK", response2->headers->GetStatusLine()); |
| 13279 | |
| 13280 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13281 | ASSERT_THAT(ReadTransaction(&trans2, &response_data2), IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13282 | EXPECT_EQ("another", response_data2); |
| 13283 | } |
| 13284 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13285 | // Alternative service requires HTTP/2 (or SPDY), but there is already a |
| 13286 | // HTTP/1.1 socket open to the alternative server. That socket should not be |
| 13287 | // used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13288 | TEST_F(HttpNetworkTransactionTest, AlternativeServiceShouldNotPoolToHttp11) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 13289 | url::SchemeHostPort server("https", "origin.example.org", 443); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13290 | HostPortPair alternative("alternative.example.org", 443); |
| 13291 | std::string origin_url = "https://origin.example.org:443"; |
| 13292 | std::string alternative_url = "https://alternative.example.org:443"; |
| 13293 | |
| 13294 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 13295 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13296 | ssl.next_proto = kProtoHTTP11; |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13297 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13298 | |
| 13299 | // HTTP/1.1 data for |request1| and |request2|. |
| 13300 | MockWrite http_writes[] = { |
| 13301 | MockWrite( |
| 13302 | "GET / HTTP/1.1\r\n" |
| 13303 | "Host: alternative.example.org\r\n" |
| 13304 | "Connection: keep-alive\r\n\r\n"), |
| 13305 | MockWrite( |
| 13306 | "GET / HTTP/1.1\r\n" |
| 13307 | "Host: alternative.example.org\r\n" |
| 13308 | "Connection: keep-alive\r\n\r\n"), |
| 13309 | }; |
| 13310 | |
| 13311 | MockRead http_reads[] = { |
| 13312 | MockRead( |
| 13313 | "HTTP/1.1 200 OK\r\n" |
| 13314 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13315 | "Content-Length: 40\r\n\r\n" |
| 13316 | "first HTTP/1.1 response from alternative"), |
| 13317 | MockRead( |
| 13318 | "HTTP/1.1 200 OK\r\n" |
| 13319 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13320 | "Content-Length: 41\r\n\r\n" |
| 13321 | "second HTTP/1.1 response from alternative"), |
| 13322 | }; |
| 13323 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 13324 | http_writes, arraysize(http_writes)); |
| 13325 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 13326 | |
| 13327 | // This test documents that an alternate Job should not pool to an already |
| 13328 | // existing HTTP/1.1 connection. In order to test this, a failed connection |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 13329 | // to the server is mocked. This way |request2| relies on the alternate Job. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13330 | StaticSocketDataProvider data_refused; |
| 13331 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 13332 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 13333 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 13334 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13335 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 13336 | HttpServerProperties* http_server_properties = |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13337 | session->http_server_properties(); |
| 13338 | AlternativeService alternative_service( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 13339 | AlternateProtocolFromNextProto(kProtoHTTP2), alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 13340 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 13341 | http_server_properties->SetAlternativeService(server, alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 13342 | expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13343 | |
| 13344 | // First transaction to alternative to open an HTTP/1.1 socket. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13345 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13346 | HttpRequestInfo request1; |
| 13347 | request1.method = "GET"; |
| 13348 | request1.url = GURL(alternative_url); |
| 13349 | request1.load_flags = 0; |
| 13350 | TestCompletionCallback callback1; |
| 13351 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13352 | int rv = trans1.Start(&request1, callback1.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13353 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13354 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13355 | ASSERT_TRUE(response1); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13356 | ASSERT_TRUE(response1->headers); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13357 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
| 13358 | EXPECT_TRUE(response1->was_npn_negotiated); |
| 13359 | EXPECT_FALSE(response1->was_fetched_via_spdy); |
| 13360 | std::string response_data1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13361 | ASSERT_THAT(ReadTransaction(&trans1, &response_data1), IsOk()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13362 | EXPECT_EQ("first HTTP/1.1 response from alternative", response_data1); |
| 13363 | |
| 13364 | // Request for origin.example.org, which has an alternative service. This |
| 13365 | // will start two Jobs: the alternative looks for connections to pool to, |
| 13366 | // 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] | 13367 | // open other connections to alternative server. The Job to server fails, so |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13368 | // this request fails. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13369 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13370 | HttpRequestInfo request2; |
| 13371 | request2.method = "GET"; |
| 13372 | request2.url = GURL(origin_url); |
| 13373 | request2.load_flags = 0; |
| 13374 | TestCompletionCallback callback2; |
| 13375 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13376 | rv = trans2.Start(&request2, callback2.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13377 | EXPECT_THAT(callback2.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13378 | |
| 13379 | // Another transaction to alternative. This is to test that the HTTP/1.1 |
| 13380 | // socket is still open and in the pool. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13381 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13382 | HttpRequestInfo request3; |
| 13383 | request3.method = "GET"; |
| 13384 | request3.url = GURL(alternative_url); |
| 13385 | request3.load_flags = 0; |
| 13386 | TestCompletionCallback callback3; |
| 13387 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13388 | rv = trans3.Start(&request3, callback3.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13389 | EXPECT_THAT(callback3.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13390 | const HttpResponseInfo* response3 = trans3.GetResponseInfo(); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13391 | ASSERT_TRUE(response3); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13392 | ASSERT_TRUE(response3->headers); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13393 | EXPECT_EQ("HTTP/1.1 200 OK", response3->headers->GetStatusLine()); |
| 13394 | EXPECT_TRUE(response3->was_npn_negotiated); |
| 13395 | EXPECT_FALSE(response3->was_fetched_via_spdy); |
| 13396 | std::string response_data3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13397 | ASSERT_THAT(ReadTransaction(&trans3, &response_data3), IsOk()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13398 | EXPECT_EQ("second HTTP/1.1 response from alternative", response_data3); |
| 13399 | } |
| 13400 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13401 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttpOverTunnel) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13402 | const std::string https_url = "https://www.example.org:8080/"; |
| 13403 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13404 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13405 | // Separate SPDY util instance for naked and wrapped requests. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13406 | SpdyTestUtil spdy_util_wrapped; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13407 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13408 | // SPDY GET for HTTPS URL (through CONNECT tunnel) |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13409 | const HostPortPair host_port_pair("www.example.org", 8080); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13410 | SpdySerializedFrame connect( |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 13411 | spdy_util_.ConstructSpdyConnect(NULL, 0, 1, LOWEST, host_port_pair)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13412 | SpdySerializedFrame req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13413 | spdy_util_wrapped.ConstructSpdyGet(https_url.c_str(), 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13414 | SpdySerializedFrame wrapped_req1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13415 | spdy_util_.ConstructWrappedSpdyFrame(req1, 1)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 13416 | |
| 13417 | // SPDY GET for HTTP URL (through the proxy, but not the tunnel). |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 13418 | SpdyHeaderBlock req2_block; |
| 13419 | req2_block[spdy_util_.GetMethodKey()] = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13420 | req2_block[spdy_util_.GetHostKey()] = "www.example.org:8080"; |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 13421 | req2_block[spdy_util_.GetSchemeKey()] = "http"; |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 13422 | req2_block[spdy_util_.GetPathKey()] = "/"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13423 | SpdySerializedFrame req2( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13424 | spdy_util_.ConstructSpdyHeaders(3, std::move(req2_block), MEDIUM, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13425 | |
| 13426 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13427 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_req1, 2), |
| 13428 | CreateMockWrite(req2, 6), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13429 | }; |
| 13430 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13431 | SpdySerializedFrame conn_resp( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13432 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13433 | SpdySerializedFrame resp1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13434 | spdy_util_wrapped.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13435 | SpdySerializedFrame body1(spdy_util_wrapped.ConstructSpdyDataFrame(1, true)); |
| 13436 | SpdySerializedFrame wrapped_resp1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13437 | spdy_util_wrapped.ConstructWrappedSpdyFrame(resp1, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13438 | SpdySerializedFrame wrapped_body1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13439 | spdy_util_wrapped.ConstructWrappedSpdyFrame(body1, 1)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13440 | SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13441 | SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13442 | MockRead reads1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13443 | CreateMockRead(conn_resp, 1), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13444 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13445 | CreateMockRead(wrapped_resp1, 4), |
| 13446 | CreateMockRead(wrapped_body1, 5), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13447 | MockRead(ASYNC, ERR_IO_PENDING, 7), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13448 | CreateMockRead(resp2, 8), |
| 13449 | CreateMockRead(body2, 9), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13450 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 10), |
| 13451 | }; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13452 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13453 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 13454 | arraysize(writes1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13455 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 13456 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13457 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 13458 | session_deps_.proxy_service = |
| 13459 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 13460 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13461 | session_deps_.net_log = &log; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13462 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13463 | ssl1.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13464 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13465 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13466 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13467 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 13468 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13469 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13470 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13471 | |
| 13472 | // Start the first transaction to set up the SpdySession |
| 13473 | HttpRequestInfo request1; |
| 13474 | request1.method = "GET"; |
| 13475 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13476 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13477 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13478 | TestCompletionCallback callback1; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13479 | int rv = trans1.Start(&request1, callback1.callback(), BoundNetLog()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13480 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13481 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 13482 | data1.RunUntilPaused(); |
| 13483 | base::RunLoop().RunUntilIdle(); |
| 13484 | data1.Resume(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13485 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13486 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 13487 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 13488 | LoadTimingInfo load_timing_info1; |
| 13489 | EXPECT_TRUE(trans1.GetLoadTimingInfo(&load_timing_info1)); |
| 13490 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 13491 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 13492 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13493 | // Now, start the HTTP request. |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13494 | HttpRequestInfo request2; |
| 13495 | request2.method = "GET"; |
| 13496 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13497 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13498 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13499 | TestCompletionCallback callback2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13500 | rv = trans2.Start(&request2, callback2.callback(), BoundNetLog()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13501 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13502 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 13503 | data1.RunUntilPaused(); |
| 13504 | base::RunLoop().RunUntilIdle(); |
| 13505 | data1.Resume(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13506 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13507 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13508 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 13509 | |
| 13510 | LoadTimingInfo load_timing_info2; |
| 13511 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
| 13512 | // The established SPDY sessions is considered reused by the HTTP request. |
| 13513 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 13514 | // HTTP requests over a SPDY session should have a different connection |
| 13515 | // socket_log_id than requests over a tunnel. |
| 13516 | 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] | 13517 | } |
| 13518 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13519 | // Test that in the case where we have a SPDY session to a SPDY proxy |
| 13520 | // that we do not pool other origins that resolve to the same IP when |
| 13521 | // the certificate does not match the new origin. |
| 13522 | // http://crbug.com/134690 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13523 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionIfCertDoesNotMatch) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13524 | const std::string url1 = "http://www.example.org/"; |
| 13525 | const std::string url2 = "https://news.example.org/"; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13526 | const std::string ip_addr = "1.2.3.4"; |
| 13527 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13528 | // Second SpdyTestUtil instance for the second socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13529 | SpdyTestUtil spdy_util_secure; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13530 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13531 | // SPDY GET for HTTP URL (through SPDY proxy) |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 13532 | SpdyHeaderBlock headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13533 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13534 | SpdySerializedFrame req1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13535 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13536 | |
| 13537 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13538 | CreateMockWrite(req1, 0), |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13539 | }; |
| 13540 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13541 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13542 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13543 | MockRead reads1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13544 | MockRead(ASYNC, ERR_IO_PENDING, 1), CreateMockRead(resp1, 2), |
| 13545 | CreateMockRead(body1, 3), MockRead(ASYNC, OK, 4), // EOF |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13546 | }; |
| 13547 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13548 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 13549 | arraysize(writes1)); |
martijn | fe9636e | 2016-02-06 14:33:32 | [diff] [blame] | 13550 | IPAddress ip; |
martijn | 654c8c4 | 2016-02-10 22:10:59 | [diff] [blame] | 13551 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13552 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 13553 | MockConnect connect_data1(ASYNC, OK, peer_addr); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13554 | data1.set_connect_data(connect_data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13555 | |
| 13556 | // SPDY GET for HTTPS URL (direct) |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13557 | SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13558 | spdy_util_secure.ConstructSpdyGet(url2.c_str(), 1, MEDIUM)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13559 | |
| 13560 | MockWrite writes2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13561 | CreateMockWrite(req2, 0), |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13562 | }; |
| 13563 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13564 | SpdySerializedFrame resp2(spdy_util_secure.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13565 | SpdySerializedFrame body2(spdy_util_secure.ConstructSpdyDataFrame(1, true)); |
| 13566 | MockRead reads2[] = {CreateMockRead(resp2, 1), CreateMockRead(body2, 2), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13567 | MockRead(ASYNC, OK, 3)}; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13568 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13569 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 13570 | arraysize(writes2)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13571 | MockConnect connect_data2(ASYNC, OK); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13572 | data2.set_connect_data(connect_data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13573 | |
| 13574 | // Set up a proxy config that sends HTTP requests to a proxy, and |
| 13575 | // all others direct. |
| 13576 | ProxyConfig proxy_config; |
| 13577 | proxy_config.proxy_rules().ParseFromString("http=https://proxy:443"); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13578 | session_deps_.proxy_service.reset(new ProxyService( |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13579 | base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), nullptr, |
csharrison | b7e3a08 | 2015-09-22 19:13:04 | [diff] [blame] | 13580 | NULL)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13581 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13582 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13583 | ssl1.next_proto = kProtoHTTP2; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13584 | // Load a valid cert. Note, that this does not need to |
| 13585 | // be valid for proxy because the MockSSLClientSocket does |
| 13586 | // not actually verify it. But SpdySession will use this |
| 13587 | // to see if it is valid for the new origin |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13588 | ssl1.cert = ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem"); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13589 | ASSERT_TRUE(ssl1.cert); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13590 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 13591 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13592 | |
| 13593 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13594 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13595 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 13596 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13597 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13598 | session_deps_.host_resolver.reset(new MockCachingHostResolver()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13599 | session_deps_.host_resolver->rules()->AddRule("news.example.org", ip_addr); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13600 | session_deps_.host_resolver->rules()->AddRule("proxy", ip_addr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13601 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13602 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13603 | |
| 13604 | // Start the first transaction to set up the SpdySession |
| 13605 | HttpRequestInfo request1; |
| 13606 | request1.method = "GET"; |
| 13607 | request1.url = GURL(url1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13608 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13609 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13610 | TestCompletionCallback callback1; |
| 13611 | ASSERT_EQ(ERR_IO_PENDING, |
| 13612 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13613 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 13614 | data1.RunUntilPaused(); |
| 13615 | base::RunLoop().RunUntilIdle(); |
| 13616 | data1.Resume(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13617 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13618 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13619 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 13620 | |
| 13621 | // Now, start the HTTP request |
| 13622 | HttpRequestInfo request2; |
| 13623 | request2.method = "GET"; |
| 13624 | request2.url = GURL(url2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13625 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13626 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13627 | TestCompletionCallback callback2; |
| 13628 | EXPECT_EQ(ERR_IO_PENDING, |
| 13629 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 13630 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13631 | |
| 13632 | ASSERT_TRUE(callback2.have_result()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13633 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13634 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 13635 | } |
| 13636 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13637 | // Test to verify that a failed socket read (due to an ERR_CONNECTION_CLOSED |
| 13638 | // error) in SPDY session, removes the socket from pool and closes the SPDY |
| 13639 | // session. Verify that new url's from the same HttpNetworkSession (and a new |
| 13640 | // SpdySession) do work. http://crbug.com/224701 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13641 | TEST_F(HttpNetworkTransactionTest, ErrorSocketNotConnected) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13642 | const std::string https_url = "https://www.example.org/"; |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13643 | |
| 13644 | MockRead reads1[] = { |
| 13645 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED, 0) |
| 13646 | }; |
| 13647 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 13648 | SequencedSocketData data1(reads1, arraysize(reads1), NULL, 0); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13649 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13650 | SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13651 | spdy_util_.ConstructSpdyGet(https_url.c_str(), 1, MEDIUM)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13652 | MockWrite writes2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13653 | CreateMockWrite(req2, 0), |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13654 | }; |
| 13655 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13656 | SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13657 | SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13658 | MockRead reads2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13659 | CreateMockRead(resp2, 1), CreateMockRead(body2, 2), |
| 13660 | MockRead(ASYNC, OK, 3) // EOF |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13661 | }; |
| 13662 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 13663 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 13664 | arraysize(writes2)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13665 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13666 | SSLSocketDataProvider ssl1(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13667 | ssl1.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 13668 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 13669 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13670 | |
| 13671 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13672 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 13673 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 13674 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13675 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13676 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 13677 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13678 | |
| 13679 | // Start the first transaction to set up the SpdySession and verify that |
| 13680 | // connection was closed. |
| 13681 | HttpRequestInfo request1; |
| 13682 | request1.method = "GET"; |
| 13683 | request1.url = GURL(https_url); |
| 13684 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13685 | HttpNetworkTransaction trans1(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13686 | TestCompletionCallback callback1; |
| 13687 | EXPECT_EQ(ERR_IO_PENDING, |
| 13688 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13689 | EXPECT_THAT(callback1.WaitForResult(), IsError(ERR_CONNECTION_CLOSED)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13690 | |
| 13691 | // Now, start the second request and make sure it succeeds. |
| 13692 | HttpRequestInfo request2; |
| 13693 | request2.method = "GET"; |
| 13694 | request2.url = GURL(https_url); |
| 13695 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13696 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13697 | TestCompletionCallback callback2; |
| 13698 | EXPECT_EQ(ERR_IO_PENDING, |
| 13699 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13700 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13701 | ASSERT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13702 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 13703 | } |
| 13704 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13705 | TEST_F(HttpNetworkTransactionTest, CloseIdleSpdySessionToOpenNewOne) { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13706 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 13707 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 13708 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 13709 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 13710 | |
| 13711 | // Use two different hosts with different IPs so they don't get pooled. |
| 13712 | session_deps_.host_resolver->rules()->AddRule("www.a.com", "10.0.0.1"); |
| 13713 | session_deps_.host_resolver->rules()->AddRule("www.b.com", "10.0.0.2"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13714 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13715 | |
| 13716 | SSLSocketDataProvider ssl1(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13717 | ssl1.next_proto = kProtoHTTP2; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13718 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13719 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13720 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 13721 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 13722 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13723 | SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13724 | spdy_util_.ConstructSpdyGet("https://www.a.com", 1, DEFAULT_PRIORITY)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13725 | MockWrite spdy1_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13726 | CreateMockWrite(host1_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13727 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13728 | SpdySerializedFrame host1_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13729 | SpdySerializedFrame host1_resp_body( |
| 13730 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13731 | MockRead spdy1_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13732 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 13733 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13734 | }; |
| 13735 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13736 | // Use a separate test instance for the separate SpdySession that will be |
| 13737 | // created. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13738 | SpdyTestUtil spdy_util_2; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13739 | std::unique_ptr<SequencedSocketData> spdy1_data( |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13740 | new SequencedSocketData(spdy1_reads, arraysize(spdy1_reads), spdy1_writes, |
| 13741 | arraysize(spdy1_writes))); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13742 | session_deps_.socket_factory->AddSocketDataProvider(spdy1_data.get()); |
| 13743 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13744 | SpdySerializedFrame host2_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13745 | spdy_util_2.ConstructSpdyGet("https://www.b.com", 1, DEFAULT_PRIORITY)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13746 | MockWrite spdy2_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13747 | CreateMockWrite(host2_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13748 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13749 | SpdySerializedFrame host2_resp(spdy_util_2.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13750 | SpdySerializedFrame host2_resp_body( |
| 13751 | spdy_util_2.ConstructSpdyDataFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13752 | MockRead spdy2_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13753 | CreateMockRead(host2_resp, 1), CreateMockRead(host2_resp_body, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 13754 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13755 | }; |
| 13756 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13757 | std::unique_ptr<SequencedSocketData> spdy2_data( |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13758 | new SequencedSocketData(spdy2_reads, arraysize(spdy2_reads), spdy2_writes, |
| 13759 | arraysize(spdy2_writes))); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13760 | session_deps_.socket_factory->AddSocketDataProvider(spdy2_data.get()); |
| 13761 | |
| 13762 | MockWrite http_write[] = { |
| 13763 | MockWrite("GET / HTTP/1.1\r\n" |
| 13764 | "Host: www.a.com\r\n" |
| 13765 | "Connection: keep-alive\r\n\r\n"), |
| 13766 | }; |
| 13767 | |
| 13768 | MockRead http_read[] = { |
| 13769 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13770 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 13771 | MockRead("Content-Length: 6\r\n\r\n"), |
| 13772 | MockRead("hello!"), |
| 13773 | }; |
| 13774 | StaticSocketDataProvider http_data(http_read, arraysize(http_read), |
| 13775 | http_write, arraysize(http_write)); |
| 13776 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 13777 | |
| 13778 | HostPortPair host_port_pair_a("www.a.com", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 13779 | SpdySessionKey spdy_session_key_a( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 13780 | host_port_pair_a, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13781 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13782 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13783 | |
| 13784 | TestCompletionCallback callback; |
| 13785 | HttpRequestInfo request1; |
| 13786 | request1.method = "GET"; |
| 13787 | request1.url = GURL("https://www.a.com/"); |
| 13788 | request1.load_flags = 0; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13789 | std::unique_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13790 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13791 | |
| 13792 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13793 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13794 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13795 | |
| 13796 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13797 | ASSERT_TRUE(response); |
| 13798 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13799 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13800 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 13801 | EXPECT_TRUE(response->was_npn_negotiated); |
| 13802 | |
| 13803 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13804 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13805 | EXPECT_EQ("hello!", response_data); |
| 13806 | trans.reset(); |
| 13807 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13808 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13809 | |
| 13810 | HostPortPair host_port_pair_b("www.b.com", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 13811 | SpdySessionKey spdy_session_key_b( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 13812 | host_port_pair_b, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13813 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13814 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13815 | HttpRequestInfo request2; |
| 13816 | request2.method = "GET"; |
| 13817 | request2.url = GURL("https://www.b.com/"); |
| 13818 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13819 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13820 | |
| 13821 | rv = trans->Start(&request2, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13822 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13823 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13824 | |
| 13825 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13826 | ASSERT_TRUE(response); |
| 13827 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13828 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13829 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 13830 | EXPECT_TRUE(response->was_npn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13831 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13832 | EXPECT_EQ("hello!", response_data); |
| 13833 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13834 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13835 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13836 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13837 | |
| 13838 | HostPortPair host_port_pair_a1("www.a.com", 80); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 13839 | SpdySessionKey spdy_session_key_a1( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 13840 | host_port_pair_a1, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13841 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13842 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a1)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13843 | HttpRequestInfo request3; |
| 13844 | request3.method = "GET"; |
| 13845 | request3.url = GURL("http://www.a.com/"); |
| 13846 | request3.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13847 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13848 | |
| 13849 | rv = trans->Start(&request3, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13850 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13851 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13852 | |
| 13853 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13854 | ASSERT_TRUE(response); |
| 13855 | ASSERT_TRUE(response->headers); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13856 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13857 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 13858 | EXPECT_FALSE(response->was_npn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13859 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13860 | EXPECT_EQ("hello!", response_data); |
| 13861 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13862 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13863 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13864 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13865 | } |
| 13866 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13867 | TEST_F(HttpNetworkTransactionTest, HttpSyncConnectError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13868 | HttpRequestInfo request; |
| 13869 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13870 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13871 | request.load_flags = 0; |
| 13872 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13873 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13874 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13875 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 13876 | MockConnect mock_connect(SYNCHRONOUS, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13877 | StaticSocketDataProvider data; |
| 13878 | data.set_connect_data(mock_connect); |
| 13879 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13880 | |
| 13881 | TestCompletionCallback callback; |
| 13882 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13883 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13884 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13885 | |
| 13886 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13887 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13888 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13889 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 13890 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13891 | trans.GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 13892 | |
| 13893 | ConnectionAttempts attempts; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13894 | trans.GetConnectionAttempts(&attempts); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 13895 | ASSERT_EQ(1u, attempts.size()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13896 | EXPECT_THAT(attempts[0].result, IsError(ERR_NAME_NOT_RESOLVED)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 13897 | |
| 13898 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13899 | EXPECT_FALSE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 13900 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13901 | } |
| 13902 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13903 | TEST_F(HttpNetworkTransactionTest, HttpAsyncConnectError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13904 | HttpRequestInfo request; |
| 13905 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13906 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13907 | request.load_flags = 0; |
| 13908 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13909 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13910 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13911 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 13912 | MockConnect mock_connect(ASYNC, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13913 | StaticSocketDataProvider data; |
| 13914 | data.set_connect_data(mock_connect); |
| 13915 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13916 | |
| 13917 | TestCompletionCallback callback; |
| 13918 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13919 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13920 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13921 | |
| 13922 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13923 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13924 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13925 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 13926 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13927 | trans.GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 13928 | |
| 13929 | ConnectionAttempts attempts; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13930 | trans.GetConnectionAttempts(&attempts); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 13931 | ASSERT_EQ(1u, attempts.size()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13932 | EXPECT_THAT(attempts[0].result, IsError(ERR_NAME_NOT_RESOLVED)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 13933 | |
| 13934 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13935 | EXPECT_FALSE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 13936 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13937 | } |
| 13938 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13939 | TEST_F(HttpNetworkTransactionTest, HttpSyncWriteError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13940 | HttpRequestInfo request; |
| 13941 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13942 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13943 | request.load_flags = 0; |
| 13944 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13945 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13946 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13947 | |
| 13948 | MockWrite data_writes[] = { |
| 13949 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 13950 | }; |
| 13951 | MockRead data_reads[] = { |
| 13952 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 13953 | }; |
| 13954 | |
| 13955 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 13956 | data_writes, arraysize(data_writes)); |
| 13957 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13958 | |
| 13959 | TestCompletionCallback callback; |
| 13960 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13961 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13962 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13963 | |
| 13964 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13965 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13966 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13967 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13968 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13969 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 13970 | } |
| 13971 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13972 | TEST_F(HttpNetworkTransactionTest, HttpAsyncWriteError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13973 | HttpRequestInfo request; |
| 13974 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13975 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13976 | request.load_flags = 0; |
| 13977 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13978 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13979 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13980 | |
| 13981 | MockWrite data_writes[] = { |
| 13982 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
| 13983 | }; |
| 13984 | MockRead data_reads[] = { |
| 13985 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 13986 | }; |
| 13987 | |
| 13988 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 13989 | data_writes, arraysize(data_writes)); |
| 13990 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13991 | |
| 13992 | TestCompletionCallback callback; |
| 13993 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13994 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13995 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13996 | |
| 13997 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13998 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13999 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14000 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14001 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14002 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 14003 | } |
| 14004 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14005 | TEST_F(HttpNetworkTransactionTest, HttpSyncReadError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14006 | HttpRequestInfo request; |
| 14007 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14008 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14009 | request.load_flags = 0; |
| 14010 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14011 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14012 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14013 | |
| 14014 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14015 | MockWrite( |
| 14016 | "GET / HTTP/1.1\r\n" |
| 14017 | "Host: www.example.org\r\n" |
| 14018 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14019 | }; |
| 14020 | MockRead data_reads[] = { |
| 14021 | MockRead(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14022 | }; |
| 14023 | |
| 14024 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 14025 | data_writes, arraysize(data_writes)); |
| 14026 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14027 | |
| 14028 | TestCompletionCallback callback; |
| 14029 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14030 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14031 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14032 | |
| 14033 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14034 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14035 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14036 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14037 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14038 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 14039 | } |
| 14040 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14041 | TEST_F(HttpNetworkTransactionTest, HttpAsyncReadError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14042 | HttpRequestInfo request; |
| 14043 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14044 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14045 | request.load_flags = 0; |
| 14046 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14047 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14048 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14049 | |
| 14050 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14051 | MockWrite( |
| 14052 | "GET / HTTP/1.1\r\n" |
| 14053 | "Host: www.example.org\r\n" |
| 14054 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14055 | }; |
| 14056 | MockRead data_reads[] = { |
| 14057 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
| 14058 | }; |
| 14059 | |
| 14060 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 14061 | data_writes, arraysize(data_writes)); |
| 14062 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14063 | |
| 14064 | TestCompletionCallback callback; |
| 14065 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14066 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14067 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14068 | |
| 14069 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14070 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14071 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14072 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14073 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14074 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 14075 | } |
| 14076 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14077 | TEST_F(HttpNetworkTransactionTest, GetFullRequestHeadersIncludesExtraHeader) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14078 | HttpRequestInfo request; |
| 14079 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14080 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14081 | request.load_flags = 0; |
| 14082 | request.extra_headers.SetHeader("X-Foo", "bar"); |
| 14083 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14084 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14085 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14086 | |
| 14087 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14088 | MockWrite( |
| 14089 | "GET / HTTP/1.1\r\n" |
| 14090 | "Host: www.example.org\r\n" |
| 14091 | "Connection: keep-alive\r\n" |
| 14092 | "X-Foo: bar\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14093 | }; |
| 14094 | MockRead data_reads[] = { |
| 14095 | MockRead("HTTP/1.1 200 OK\r\n" |
| 14096 | "Content-Length: 5\r\n\r\n" |
| 14097 | "hello"), |
| 14098 | MockRead(ASYNC, ERR_UNEXPECTED), |
| 14099 | }; |
| 14100 | |
| 14101 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 14102 | data_writes, arraysize(data_writes)); |
| 14103 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14104 | |
| 14105 | TestCompletionCallback callback; |
| 14106 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14107 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14108 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14109 | |
| 14110 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14111 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14112 | |
| 14113 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14114 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14115 | std::string foo; |
| 14116 | EXPECT_TRUE(request_headers.GetHeader("X-Foo", &foo)); |
| 14117 | EXPECT_EQ("bar", foo); |
| 14118 | } |
| 14119 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14120 | namespace { |
| 14121 | |
yhirano | a7e05bb | 2014-11-06 05:40:39 | [diff] [blame] | 14122 | // Fake HttpStream that simply records calls to SetPriority(). |
| 14123 | class FakeStream : public HttpStream, |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14124 | public base::SupportsWeakPtr<FakeStream> { |
| 14125 | public: |
| 14126 | explicit FakeStream(RequestPriority priority) : priority_(priority) {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14127 | ~FakeStream() override {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14128 | |
| 14129 | RequestPriority priority() const { return priority_; } |
| 14130 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14131 | int InitializeStream(const HttpRequestInfo* request_info, |
| 14132 | RequestPriority priority, |
| 14133 | const BoundNetLog& net_log, |
| 14134 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14135 | return ERR_IO_PENDING; |
| 14136 | } |
| 14137 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14138 | int SendRequest(const HttpRequestHeaders& request_headers, |
| 14139 | HttpResponseInfo* response, |
| 14140 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14141 | ADD_FAILURE(); |
| 14142 | return ERR_UNEXPECTED; |
| 14143 | } |
| 14144 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14145 | int ReadResponseHeaders(const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14146 | ADD_FAILURE(); |
| 14147 | return ERR_UNEXPECTED; |
| 14148 | } |
| 14149 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14150 | int ReadResponseBody(IOBuffer* buf, |
| 14151 | int buf_len, |
| 14152 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14153 | ADD_FAILURE(); |
| 14154 | return ERR_UNEXPECTED; |
| 14155 | } |
| 14156 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14157 | void Close(bool not_reusable) override {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14158 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14159 | bool IsResponseBodyComplete() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14160 | ADD_FAILURE(); |
| 14161 | return false; |
| 14162 | } |
| 14163 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14164 | bool IsConnectionReused() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14165 | ADD_FAILURE(); |
| 14166 | return false; |
| 14167 | } |
| 14168 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14169 | void SetConnectionReused() override { ADD_FAILURE(); } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14170 | |
mmenke | bd84c39 | 2015-09-02 14:12:34 | [diff] [blame] | 14171 | bool CanReuseConnection() const override { return false; } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14172 | |
sclittle | 4de1bab9 | 2015-09-22 21:28:24 | [diff] [blame] | 14173 | int64_t GetTotalReceivedBytes() const override { |
[email protected] | bc92bc97 | 2013-12-13 08:32:59 | [diff] [blame] | 14174 | ADD_FAILURE(); |
| 14175 | return 0; |
| 14176 | } |
| 14177 | |
sclittle | be1ccf6 | 2015-09-02 19:40:36 | [diff] [blame] | 14178 | int64_t GetTotalSentBytes() const override { |
| 14179 | ADD_FAILURE(); |
| 14180 | return 0; |
| 14181 | } |
| 14182 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14183 | bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14184 | ADD_FAILURE(); |
| 14185 | return false; |
| 14186 | } |
| 14187 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14188 | void GetSSLInfo(SSLInfo* ssl_info) override { ADD_FAILURE(); } |
| 14189 | |
| 14190 | void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14191 | ADD_FAILURE(); |
| 14192 | } |
| 14193 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14194 | bool GetRemoteEndpoint(IPEndPoint* endpoint) override { return false; } |
| 14195 | |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 14196 | Error GetSignedEKMForTokenBinding(crypto::ECPrivateKey* key, |
| 14197 | std::vector<uint8_t>* out) override { |
| 14198 | ADD_FAILURE(); |
| 14199 | return ERR_NOT_IMPLEMENTED; |
| 14200 | } |
| 14201 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14202 | void Drain(HttpNetworkSession* session) override { ADD_FAILURE(); } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14203 | |
zhongyi | ca364fbb | 2015-12-12 03:39:12 | [diff] [blame] | 14204 | void PopulateNetErrorDetails(NetErrorDetails* details) override { return; } |
| 14205 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14206 | void SetPriority(RequestPriority priority) override { priority_ = priority; } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14207 | |
yhirano | a7e05bb | 2014-11-06 05:40:39 | [diff] [blame] | 14208 | HttpStream* RenewStreamForAuth() override { return NULL; } |
| 14209 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14210 | private: |
| 14211 | RequestPriority priority_; |
| 14212 | |
| 14213 | DISALLOW_COPY_AND_ASSIGN(FakeStream); |
| 14214 | }; |
| 14215 | |
| 14216 | // Fake HttpStreamRequest that simply records calls to SetPriority() |
| 14217 | // and vends FakeStreams with its current priority. |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14218 | class FakeStreamRequest : public HttpStreamRequest, |
| 14219 | public base::SupportsWeakPtr<FakeStreamRequest> { |
| 14220 | public: |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14221 | FakeStreamRequest(RequestPriority priority, |
| 14222 | HttpStreamRequest::Delegate* delegate) |
| 14223 | : priority_(priority), |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14224 | delegate_(delegate), |
| 14225 | websocket_stream_create_helper_(NULL) {} |
| 14226 | |
| 14227 | FakeStreamRequest(RequestPriority priority, |
| 14228 | HttpStreamRequest::Delegate* delegate, |
| 14229 | WebSocketHandshakeStreamBase::CreateHelper* create_helper) |
| 14230 | : priority_(priority), |
| 14231 | delegate_(delegate), |
| 14232 | websocket_stream_create_helper_(create_helper) {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14233 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14234 | ~FakeStreamRequest() override {} |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14235 | |
| 14236 | RequestPriority priority() const { return priority_; } |
| 14237 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14238 | const WebSocketHandshakeStreamBase::CreateHelper* |
| 14239 | websocket_stream_create_helper() const { |
| 14240 | return websocket_stream_create_helper_; |
| 14241 | } |
| 14242 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14243 | // Create a new FakeStream and pass it to the request's |
| 14244 | // delegate. Returns a weak pointer to the FakeStream. |
| 14245 | base::WeakPtr<FakeStream> FinishStreamRequest() { |
| 14246 | FakeStream* fake_stream = new FakeStream(priority_); |
| 14247 | // Do this before calling OnStreamReady() as OnStreamReady() may |
| 14248 | // immediately delete |fake_stream|. |
| 14249 | base::WeakPtr<FakeStream> weak_stream = fake_stream->AsWeakPtr(); |
| 14250 | delegate_->OnStreamReady(SSLConfig(), ProxyInfo(), fake_stream); |
| 14251 | return weak_stream; |
| 14252 | } |
| 14253 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14254 | int RestartTunnelWithProxyAuth(const AuthCredentials& credentials) override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14255 | ADD_FAILURE(); |
| 14256 | return ERR_UNEXPECTED; |
| 14257 | } |
| 14258 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14259 | LoadState GetLoadState() const override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14260 | ADD_FAILURE(); |
| 14261 | return LoadState(); |
| 14262 | } |
| 14263 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14264 | void SetPriority(RequestPriority priority) override { priority_ = priority; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14265 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14266 | bool was_npn_negotiated() const override { return false; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14267 | |
bnc | 6227b26e | 2016-08-12 02:00:43 | [diff] [blame] | 14268 | NextProto negotiated_protocol() const override { return kProtoUnknown; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14269 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14270 | bool using_spdy() const override { return false; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14271 | |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 14272 | const ConnectionAttempts& connection_attempts() const override { |
| 14273 | static ConnectionAttempts no_attempts; |
| 14274 | return no_attempts; |
| 14275 | } |
| 14276 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14277 | private: |
| 14278 | RequestPriority priority_; |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14279 | HttpStreamRequest::Delegate* const delegate_; |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14280 | WebSocketHandshakeStreamBase::CreateHelper* websocket_stream_create_helper_; |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14281 | |
| 14282 | DISALLOW_COPY_AND_ASSIGN(FakeStreamRequest); |
| 14283 | }; |
| 14284 | |
| 14285 | // Fake HttpStreamFactory that vends FakeStreamRequests. |
| 14286 | class FakeStreamFactory : public HttpStreamFactory { |
| 14287 | public: |
| 14288 | FakeStreamFactory() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14289 | ~FakeStreamFactory() override {} |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14290 | |
| 14291 | // Returns a WeakPtr<> to the last HttpStreamRequest returned by |
| 14292 | // RequestStream() (which may be NULL if it was destroyed already). |
| 14293 | base::WeakPtr<FakeStreamRequest> last_stream_request() { |
| 14294 | return last_stream_request_; |
| 14295 | } |
| 14296 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14297 | HttpStreamRequest* RequestStream(const HttpRequestInfo& info, |
| 14298 | RequestPriority priority, |
| 14299 | const SSLConfig& server_ssl_config, |
| 14300 | const SSLConfig& proxy_ssl_config, |
| 14301 | HttpStreamRequest::Delegate* delegate, |
| 14302 | const BoundNetLog& net_log) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14303 | FakeStreamRequest* fake_request = new FakeStreamRequest(priority, delegate); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14304 | last_stream_request_ = fake_request->AsWeakPtr(); |
| 14305 | return fake_request; |
| 14306 | } |
| 14307 | |
xunjieli | 5749218c | 2016-03-22 16:43:06 | [diff] [blame] | 14308 | HttpStreamRequest* RequestBidirectionalStreamImpl( |
xunjieli | 11834f0 | 2015-12-22 04:27:08 | [diff] [blame] | 14309 | const HttpRequestInfo& info, |
| 14310 | RequestPriority priority, |
| 14311 | const SSLConfig& server_ssl_config, |
| 14312 | const SSLConfig& proxy_ssl_config, |
| 14313 | HttpStreamRequest::Delegate* delegate, |
| 14314 | const BoundNetLog& net_log) override { |
| 14315 | NOTREACHED(); |
| 14316 | return nullptr; |
| 14317 | } |
| 14318 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14319 | HttpStreamRequest* RequestWebSocketHandshakeStream( |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14320 | const HttpRequestInfo& info, |
| 14321 | RequestPriority priority, |
| 14322 | const SSLConfig& server_ssl_config, |
| 14323 | const SSLConfig& proxy_ssl_config, |
| 14324 | HttpStreamRequest::Delegate* delegate, |
[email protected] | 467086b | 2013-11-12 08:19:46 | [diff] [blame] | 14325 | WebSocketHandshakeStreamBase::CreateHelper* create_helper, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 14326 | const BoundNetLog& net_log) override { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14327 | FakeStreamRequest* fake_request = |
| 14328 | new FakeStreamRequest(priority, delegate, create_helper); |
| 14329 | last_stream_request_ = fake_request->AsWeakPtr(); |
| 14330 | return fake_request; |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14331 | } |
| 14332 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14333 | void PreconnectStreams(int num_streams, |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 14334 | const HttpRequestInfo& info) override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14335 | ADD_FAILURE(); |
| 14336 | } |
| 14337 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14338 | const HostMappingRules* GetHostMappingRules() const override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14339 | ADD_FAILURE(); |
| 14340 | return NULL; |
| 14341 | } |
| 14342 | |
| 14343 | private: |
| 14344 | base::WeakPtr<FakeStreamRequest> last_stream_request_; |
| 14345 | |
| 14346 | DISALLOW_COPY_AND_ASSIGN(FakeStreamFactory); |
| 14347 | }; |
| 14348 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14349 | // TODO(ricea): Maybe unify this with the one in |
| 14350 | // url_request_http_job_unittest.cc ? |
| 14351 | class FakeWebSocketBasicHandshakeStream : public WebSocketHandshakeStreamBase { |
| 14352 | public: |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14353 | FakeWebSocketBasicHandshakeStream( |
| 14354 | std::unique_ptr<ClientSocketHandle> connection, |
| 14355 | bool using_proxy) |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 14356 | : state_(std::move(connection), using_proxy, false) {} |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14357 | |
| 14358 | // Fake implementation of HttpStreamBase methods. |
| 14359 | // This ends up being quite "real" because this object has to really send data |
| 14360 | // on the mock socket. It might be easier to use the real implementation, but |
| 14361 | // the fact that the WebSocket code is not compiled on iOS makes that |
| 14362 | // difficult. |
| 14363 | int InitializeStream(const HttpRequestInfo* request_info, |
| 14364 | RequestPriority priority, |
| 14365 | const BoundNetLog& net_log, |
| 14366 | const CompletionCallback& callback) override { |
| 14367 | state_.Initialize(request_info, priority, net_log, callback); |
| 14368 | return OK; |
| 14369 | } |
| 14370 | |
| 14371 | int SendRequest(const HttpRequestHeaders& request_headers, |
| 14372 | HttpResponseInfo* response, |
| 14373 | const CompletionCallback& callback) override { |
| 14374 | return parser()->SendRequest(state_.GenerateRequestLine(), request_headers, |
| 14375 | response, callback); |
| 14376 | } |
| 14377 | |
| 14378 | int ReadResponseHeaders(const CompletionCallback& callback) override { |
| 14379 | return parser()->ReadResponseHeaders(callback); |
| 14380 | } |
| 14381 | |
| 14382 | int ReadResponseBody(IOBuffer* buf, |
| 14383 | int buf_len, |
| 14384 | const CompletionCallback& callback) override { |
| 14385 | NOTREACHED(); |
| 14386 | return ERR_IO_PENDING; |
| 14387 | } |
| 14388 | |
| 14389 | void Close(bool not_reusable) override { |
| 14390 | if (parser()) |
| 14391 | parser()->Close(true); |
| 14392 | } |
| 14393 | |
| 14394 | bool IsResponseBodyComplete() const override { |
| 14395 | NOTREACHED(); |
| 14396 | return false; |
| 14397 | } |
| 14398 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14399 | bool IsConnectionReused() const override { |
| 14400 | NOTREACHED(); |
| 14401 | return false; |
| 14402 | } |
| 14403 | void SetConnectionReused() override { NOTREACHED(); } |
| 14404 | |
mmenke | bd84c39 | 2015-09-02 14:12:34 | [diff] [blame] | 14405 | bool CanReuseConnection() const override { return false; } |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14406 | |
sclittle | 4de1bab9 | 2015-09-22 21:28:24 | [diff] [blame] | 14407 | int64_t GetTotalReceivedBytes() const override { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14408 | NOTREACHED(); |
| 14409 | return 0; |
| 14410 | } |
| 14411 | |
sclittle | be1ccf6 | 2015-09-02 19:40:36 | [diff] [blame] | 14412 | int64_t GetTotalSentBytes() const override { |
| 14413 | NOTREACHED(); |
| 14414 | return 0; |
| 14415 | } |
| 14416 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14417 | bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override { |
| 14418 | NOTREACHED(); |
| 14419 | return false; |
| 14420 | } |
| 14421 | |
Adam Rice | cb76ac6 | 2015-02-20 05:33:25 | [diff] [blame] | 14422 | void GetSSLInfo(SSLInfo* ssl_info) override {} |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14423 | |
| 14424 | void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override { |
| 14425 | NOTREACHED(); |
| 14426 | } |
| 14427 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14428 | bool GetRemoteEndpoint(IPEndPoint* endpoint) override { return false; } |
| 14429 | |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 14430 | Error GetSignedEKMForTokenBinding(crypto::ECPrivateKey* key, |
| 14431 | std::vector<uint8_t>* out) override { |
| 14432 | ADD_FAILURE(); |
| 14433 | return ERR_NOT_IMPLEMENTED; |
| 14434 | } |
| 14435 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14436 | void Drain(HttpNetworkSession* session) override { NOTREACHED(); } |
| 14437 | |
zhongyi | ca364fbb | 2015-12-12 03:39:12 | [diff] [blame] | 14438 | void PopulateNetErrorDetails(NetErrorDetails* details) override { return; } |
| 14439 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14440 | void SetPriority(RequestPriority priority) override { NOTREACHED(); } |
| 14441 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14442 | HttpStream* RenewStreamForAuth() override { |
| 14443 | NOTREACHED(); |
| 14444 | return nullptr; |
| 14445 | } |
| 14446 | |
| 14447 | // Fake implementation of WebSocketHandshakeStreamBase method(s) |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14448 | std::unique_ptr<WebSocketStream> Upgrade() override { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14449 | NOTREACHED(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14450 | return std::unique_ptr<WebSocketStream>(); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14451 | } |
| 14452 | |
| 14453 | private: |
| 14454 | HttpStreamParser* parser() const { return state_.parser(); } |
| 14455 | HttpBasicState state_; |
| 14456 | |
| 14457 | DISALLOW_COPY_AND_ASSIGN(FakeWebSocketBasicHandshakeStream); |
| 14458 | }; |
| 14459 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14460 | // TODO(yhirano): Split this class out into a net/websockets file, if it is |
| 14461 | // worth doing. |
| 14462 | class FakeWebSocketStreamCreateHelper : |
| 14463 | public WebSocketHandshakeStreamBase::CreateHelper { |
| 14464 | public: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14465 | WebSocketHandshakeStreamBase* CreateBasicStream( |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14466 | std::unique_ptr<ClientSocketHandle> connection, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 14467 | bool using_proxy) override { |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 14468 | return new FakeWebSocketBasicHandshakeStream(std::move(connection), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14469 | using_proxy); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14470 | } |
| 14471 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14472 | WebSocketHandshakeStreamBase* CreateSpdyStream( |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14473 | const base::WeakPtr<SpdySession>& session, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 14474 | bool use_relative_url) override { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14475 | NOTREACHED(); |
| 14476 | return NULL; |
| 14477 | }; |
| 14478 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14479 | ~FakeWebSocketStreamCreateHelper() override {} |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14480 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14481 | virtual std::unique_ptr<WebSocketStream> Upgrade() { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14482 | NOTREACHED(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14483 | return std::unique_ptr<WebSocketStream>(); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14484 | } |
| 14485 | }; |
| 14486 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14487 | } // namespace |
| 14488 | |
| 14489 | // Make sure that HttpNetworkTransaction passes on its priority to its |
| 14490 | // stream request on start. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14491 | TEST_F(HttpNetworkTransactionTest, SetStreamRequestPriorityOnStart) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14492 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14493 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14494 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14495 | peer.SetHttpStreamFactory(std::unique_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14496 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14497 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14498 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14499 | ASSERT_FALSE(fake_factory->last_stream_request()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14500 | |
| 14501 | HttpRequestInfo request; |
| 14502 | TestCompletionCallback callback; |
| 14503 | EXPECT_EQ(ERR_IO_PENDING, |
| 14504 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 14505 | |
| 14506 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 14507 | fake_factory->last_stream_request(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14508 | ASSERT_TRUE(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14509 | EXPECT_EQ(LOW, fake_request->priority()); |
| 14510 | } |
| 14511 | |
| 14512 | // Make sure that HttpNetworkTransaction passes on its priority |
| 14513 | // updates to its stream request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14514 | TEST_F(HttpNetworkTransactionTest, SetStreamRequestPriority) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14515 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14516 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14517 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14518 | peer.SetHttpStreamFactory(std::unique_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14519 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14520 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14521 | |
| 14522 | HttpRequestInfo request; |
| 14523 | TestCompletionCallback callback; |
| 14524 | EXPECT_EQ(ERR_IO_PENDING, |
| 14525 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 14526 | |
| 14527 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 14528 | fake_factory->last_stream_request(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14529 | ASSERT_TRUE(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14530 | EXPECT_EQ(LOW, fake_request->priority()); |
| 14531 | |
| 14532 | trans.SetPriority(LOWEST); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14533 | ASSERT_TRUE(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14534 | EXPECT_EQ(LOWEST, fake_request->priority()); |
| 14535 | } |
| 14536 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14537 | // Make sure that HttpNetworkTransaction passes on its priority |
| 14538 | // updates to its stream. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14539 | TEST_F(HttpNetworkTransactionTest, SetStreamPriority) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14540 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14541 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14542 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14543 | peer.SetHttpStreamFactory(std::unique_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14544 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14545 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14546 | |
| 14547 | HttpRequestInfo request; |
| 14548 | TestCompletionCallback callback; |
| 14549 | EXPECT_EQ(ERR_IO_PENDING, |
| 14550 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 14551 | |
| 14552 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 14553 | fake_factory->last_stream_request(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14554 | ASSERT_TRUE(fake_request); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14555 | base::WeakPtr<FakeStream> fake_stream = fake_request->FinishStreamRequest(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14556 | ASSERT_TRUE(fake_stream); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14557 | EXPECT_EQ(LOW, fake_stream->priority()); |
| 14558 | |
| 14559 | trans.SetPriority(LOWEST); |
| 14560 | EXPECT_EQ(LOWEST, fake_stream->priority()); |
| 14561 | } |
| 14562 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14563 | TEST_F(HttpNetworkTransactionTest, CreateWebSocketHandshakeStream) { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14564 | // The same logic needs to be tested for both ws: and wss: schemes, but this |
| 14565 | // test is already parameterised on NextProto, so it uses a loop to verify |
| 14566 | // that the different schemes work. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14567 | std::string test_cases[] = {"ws://www.example.org/", |
| 14568 | "wss://www.example.org/"}; |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14569 | for (size_t i = 0; i < arraysize(test_cases); ++i) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14570 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14571 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14572 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
| 14573 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
[email protected] | 0191b51c | 2013-11-18 10:55:23 | [diff] [blame] | 14574 | peer.SetHttpStreamFactoryForWebSocket( |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14575 | std::unique_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14576 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14577 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14578 | trans.SetWebSocketHandshakeStreamCreateHelper( |
| 14579 | &websocket_stream_create_helper); |
| 14580 | |
| 14581 | HttpRequestInfo request; |
| 14582 | TestCompletionCallback callback; |
| 14583 | request.method = "GET"; |
| 14584 | request.url = GURL(test_cases[i]); |
| 14585 | |
| 14586 | EXPECT_EQ(ERR_IO_PENDING, |
| 14587 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 14588 | |
| 14589 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 14590 | fake_factory->last_stream_request(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14591 | ASSERT_TRUE(fake_request); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14592 | EXPECT_EQ(&websocket_stream_create_helper, |
| 14593 | fake_request->websocket_stream_create_helper()); |
| 14594 | } |
| 14595 | } |
| 14596 | |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14597 | // Tests that when a used socket is returned to the SSL socket pool, it's closed |
| 14598 | // if the transport socket pool is stalled on the global socket limit. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14599 | TEST_F(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest) { |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14600 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 14601 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 14602 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 14603 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 14604 | |
| 14605 | // Set up SSL request. |
| 14606 | |
| 14607 | HttpRequestInfo ssl_request; |
| 14608 | ssl_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14609 | ssl_request.url = GURL("https://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14610 | |
| 14611 | MockWrite ssl_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14612 | MockWrite( |
| 14613 | "GET / HTTP/1.1\r\n" |
| 14614 | "Host: www.example.org\r\n" |
| 14615 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14616 | }; |
| 14617 | MockRead ssl_reads[] = { |
| 14618 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14619 | MockRead("Content-Length: 11\r\n\r\n"), |
| 14620 | MockRead("hello world"), |
| 14621 | MockRead(SYNCHRONOUS, OK), |
| 14622 | }; |
| 14623 | StaticSocketDataProvider ssl_data(ssl_reads, arraysize(ssl_reads), |
| 14624 | ssl_writes, arraysize(ssl_writes)); |
| 14625 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 14626 | |
| 14627 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 14628 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 14629 | |
| 14630 | // Set up HTTP request. |
| 14631 | |
| 14632 | HttpRequestInfo http_request; |
| 14633 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14634 | http_request.url = GURL("http://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14635 | |
| 14636 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14637 | MockWrite( |
| 14638 | "GET / HTTP/1.1\r\n" |
| 14639 | "Host: www.example.org\r\n" |
| 14640 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14641 | }; |
| 14642 | MockRead http_reads[] = { |
| 14643 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14644 | MockRead("Content-Length: 7\r\n\r\n"), |
| 14645 | MockRead("falafel"), |
| 14646 | MockRead(SYNCHRONOUS, OK), |
| 14647 | }; |
| 14648 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 14649 | http_writes, arraysize(http_writes)); |
| 14650 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 14651 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14652 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14653 | |
| 14654 | // Start the SSL request. |
| 14655 | TestCompletionCallback ssl_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14656 | HttpNetworkTransaction ssl_trans(DEFAULT_PRIORITY, session.get()); |
| 14657 | ASSERT_EQ( |
| 14658 | ERR_IO_PENDING, |
| 14659 | ssl_trans.Start(&ssl_request, ssl_callback.callback(), BoundNetLog())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14660 | |
| 14661 | // Start the HTTP request. Pool should stall. |
| 14662 | TestCompletionCallback http_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14663 | HttpNetworkTransaction http_trans(DEFAULT_PRIORITY, session.get()); |
| 14664 | ASSERT_EQ( |
| 14665 | ERR_IO_PENDING, |
| 14666 | http_trans.Start(&http_request, http_callback.callback(), BoundNetLog())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14667 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14668 | |
| 14669 | // Wait for response from SSL request. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14670 | ASSERT_THAT(ssl_callback.WaitForResult(), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14671 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14672 | ASSERT_THAT(ReadTransaction(&ssl_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14673 | EXPECT_EQ("hello world", response_data); |
| 14674 | |
| 14675 | // The SSL socket should automatically be closed, so the HTTP request can |
| 14676 | // start. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14677 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 14678 | ASSERT_FALSE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14679 | |
| 14680 | // The HTTP request can now complete. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14681 | ASSERT_THAT(http_callback.WaitForResult(), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14682 | ASSERT_THAT(ReadTransaction(&http_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14683 | EXPECT_EQ("falafel", response_data); |
| 14684 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14685 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14686 | } |
| 14687 | |
| 14688 | // Tests that when a SSL connection is established but there's no corresponding |
| 14689 | // request that needs it, the new socket is closed if the transport socket pool |
| 14690 | // is stalled on the global socket limit. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14691 | TEST_F(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest2) { |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14692 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 14693 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 14694 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 14695 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 14696 | |
| 14697 | // Set up an ssl request. |
| 14698 | |
| 14699 | HttpRequestInfo ssl_request; |
| 14700 | ssl_request.method = "GET"; |
| 14701 | ssl_request.url = GURL("https://www.foopy.com/"); |
| 14702 | |
| 14703 | // No data will be sent on the SSL socket. |
| 14704 | StaticSocketDataProvider ssl_data; |
| 14705 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 14706 | |
| 14707 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 14708 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 14709 | |
| 14710 | // Set up HTTP request. |
| 14711 | |
| 14712 | HttpRequestInfo http_request; |
| 14713 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14714 | http_request.url = GURL("http://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14715 | |
| 14716 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14717 | MockWrite( |
| 14718 | "GET / HTTP/1.1\r\n" |
| 14719 | "Host: www.example.org\r\n" |
| 14720 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14721 | }; |
| 14722 | MockRead http_reads[] = { |
| 14723 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14724 | MockRead("Content-Length: 7\r\n\r\n"), |
| 14725 | MockRead("falafel"), |
| 14726 | MockRead(SYNCHRONOUS, OK), |
| 14727 | }; |
| 14728 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 14729 | http_writes, arraysize(http_writes)); |
| 14730 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 14731 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14732 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14733 | |
| 14734 | // Preconnect an SSL socket. A preconnect is needed because connect jobs are |
| 14735 | // cancelled when a normal transaction is cancelled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14736 | HttpStreamFactory* http_stream_factory = session->http_stream_factory(); |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 14737 | http_stream_factory->PreconnectStreams(1, ssl_request); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14738 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14739 | |
| 14740 | // Start the HTTP request. Pool should stall. |
| 14741 | TestCompletionCallback http_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14742 | HttpNetworkTransaction http_trans(DEFAULT_PRIORITY, session.get()); |
| 14743 | ASSERT_EQ( |
| 14744 | ERR_IO_PENDING, |
| 14745 | http_trans.Start(&http_request, http_callback.callback(), BoundNetLog())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14746 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14747 | |
| 14748 | // The SSL connection will automatically be closed once the connection is |
| 14749 | // established, to let the HTTP request start. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14750 | ASSERT_THAT(http_callback.WaitForResult(), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14751 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14752 | ASSERT_THAT(ReadTransaction(&http_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14753 | EXPECT_EQ("falafel", response_data); |
| 14754 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14755 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14756 | } |
| 14757 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14758 | TEST_F(HttpNetworkTransactionTest, PostReadsErrorResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14759 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 14760 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 14761 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 14762 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14763 | |
| 14764 | HttpRequestInfo request; |
| 14765 | request.method = "POST"; |
| 14766 | request.url = GURL("http://www.foo.com/"); |
| 14767 | request.upload_data_stream = &upload_data_stream; |
| 14768 | request.load_flags = 0; |
| 14769 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14770 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14771 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14772 | // Send headers successfully, but get an error while sending the body. |
| 14773 | MockWrite data_writes[] = { |
| 14774 | MockWrite("POST / HTTP/1.1\r\n" |
| 14775 | "Host: www.foo.com\r\n" |
| 14776 | "Connection: keep-alive\r\n" |
| 14777 | "Content-Length: 3\r\n\r\n"), |
| 14778 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14779 | }; |
| 14780 | |
| 14781 | MockRead data_reads[] = { |
| 14782 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 14783 | MockRead("hello world"), |
| 14784 | MockRead(SYNCHRONOUS, OK), |
| 14785 | }; |
| 14786 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14787 | arraysize(data_writes)); |
| 14788 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14789 | |
| 14790 | TestCompletionCallback callback; |
| 14791 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14792 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14793 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14794 | |
| 14795 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14796 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14797 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14798 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14799 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14800 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14801 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14802 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 14803 | |
| 14804 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14805 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14806 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14807 | EXPECT_EQ("hello world", response_data); |
| 14808 | } |
| 14809 | |
| 14810 | // This test makes sure the retry logic doesn't trigger when reading an error |
| 14811 | // response from a server that rejected a POST with a CONNECTION_RESET. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14812 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14813 | PostReadsErrorResponseAfterResetOnReusedSocket) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14814 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14815 | MockWrite data_writes[] = { |
| 14816 | MockWrite("GET / HTTP/1.1\r\n" |
| 14817 | "Host: www.foo.com\r\n" |
| 14818 | "Connection: keep-alive\r\n\r\n"), |
| 14819 | MockWrite("POST / HTTP/1.1\r\n" |
| 14820 | "Host: www.foo.com\r\n" |
| 14821 | "Connection: keep-alive\r\n" |
| 14822 | "Content-Length: 3\r\n\r\n"), |
| 14823 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14824 | }; |
| 14825 | |
| 14826 | MockRead data_reads[] = { |
| 14827 | MockRead("HTTP/1.1 200 Peachy\r\n" |
| 14828 | "Content-Length: 14\r\n\r\n"), |
| 14829 | MockRead("first response"), |
| 14830 | MockRead("HTTP/1.1 400 Not OK\r\n" |
| 14831 | "Content-Length: 15\r\n\r\n"), |
| 14832 | MockRead("second response"), |
| 14833 | MockRead(SYNCHRONOUS, OK), |
| 14834 | }; |
| 14835 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14836 | arraysize(data_writes)); |
| 14837 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14838 | |
| 14839 | TestCompletionCallback callback; |
| 14840 | HttpRequestInfo request1; |
| 14841 | request1.method = "GET"; |
| 14842 | request1.url = GURL("http://www.foo.com/"); |
| 14843 | request1.load_flags = 0; |
| 14844 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14845 | std::unique_ptr<HttpNetworkTransaction> trans1( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14846 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14847 | int rv = trans1->Start(&request1, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14848 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14849 | |
| 14850 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14851 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14852 | |
| 14853 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14854 | ASSERT_TRUE(response1); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14855 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14856 | EXPECT_TRUE(response1->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14857 | EXPECT_EQ("HTTP/1.1 200 Peachy", response1->headers->GetStatusLine()); |
| 14858 | |
| 14859 | std::string response_data1; |
| 14860 | rv = ReadTransaction(trans1.get(), &response_data1); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14861 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14862 | EXPECT_EQ("first response", response_data1); |
| 14863 | // Delete the transaction to release the socket back into the socket pool. |
| 14864 | trans1.reset(); |
| 14865 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14866 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 14867 | element_readers.push_back( |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14868 | base::WrapUnique(new UploadBytesElementReader("foo", 3))); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 14869 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14870 | |
| 14871 | HttpRequestInfo request2; |
| 14872 | request2.method = "POST"; |
| 14873 | request2.url = GURL("http://www.foo.com/"); |
| 14874 | request2.upload_data_stream = &upload_data_stream; |
| 14875 | request2.load_flags = 0; |
| 14876 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14877 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 14878 | rv = trans2.Start(&request2, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14879 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14880 | |
| 14881 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14882 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14883 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14884 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14885 | ASSERT_TRUE(response2); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14886 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14887 | EXPECT_TRUE(response2->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14888 | EXPECT_EQ("HTTP/1.1 400 Not OK", response2->headers->GetStatusLine()); |
| 14889 | |
| 14890 | std::string response_data2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14891 | rv = ReadTransaction(&trans2, &response_data2); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14892 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14893 | EXPECT_EQ("second response", response_data2); |
| 14894 | } |
| 14895 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14896 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14897 | PostReadsErrorResponseAfterResetPartialBodySent) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14898 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 14899 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 14900 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 14901 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14902 | |
| 14903 | HttpRequestInfo request; |
| 14904 | request.method = "POST"; |
| 14905 | request.url = GURL("http://www.foo.com/"); |
| 14906 | request.upload_data_stream = &upload_data_stream; |
| 14907 | request.load_flags = 0; |
| 14908 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14909 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14910 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14911 | // Send headers successfully, but get an error while sending the body. |
| 14912 | MockWrite data_writes[] = { |
| 14913 | MockWrite("POST / HTTP/1.1\r\n" |
| 14914 | "Host: www.foo.com\r\n" |
| 14915 | "Connection: keep-alive\r\n" |
| 14916 | "Content-Length: 3\r\n\r\n" |
| 14917 | "fo"), |
| 14918 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14919 | }; |
| 14920 | |
| 14921 | MockRead data_reads[] = { |
| 14922 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 14923 | MockRead("hello world"), |
| 14924 | MockRead(SYNCHRONOUS, OK), |
| 14925 | }; |
| 14926 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14927 | arraysize(data_writes)); |
| 14928 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14929 | |
| 14930 | TestCompletionCallback callback; |
| 14931 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14932 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14933 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14934 | |
| 14935 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14936 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14937 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14938 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14939 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14940 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14941 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14942 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 14943 | |
| 14944 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14945 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14946 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14947 | EXPECT_EQ("hello world", response_data); |
| 14948 | } |
| 14949 | |
| 14950 | // This tests the more common case than the previous test, where headers and |
| 14951 | // body are not merged into a single request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14952 | TEST_F(HttpNetworkTransactionTest, ChunkedPostReadsErrorResponseAfterReset) { |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 14953 | ChunkedUploadDataStream upload_data_stream(0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14954 | |
| 14955 | HttpRequestInfo request; |
| 14956 | request.method = "POST"; |
| 14957 | request.url = GURL("http://www.foo.com/"); |
| 14958 | request.upload_data_stream = &upload_data_stream; |
| 14959 | request.load_flags = 0; |
| 14960 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14961 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14962 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14963 | // Send headers successfully, but get an error while sending the body. |
| 14964 | MockWrite data_writes[] = { |
| 14965 | MockWrite("POST / HTTP/1.1\r\n" |
| 14966 | "Host: www.foo.com\r\n" |
| 14967 | "Connection: keep-alive\r\n" |
| 14968 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 14969 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14970 | }; |
| 14971 | |
| 14972 | MockRead data_reads[] = { |
| 14973 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 14974 | MockRead("hello world"), |
| 14975 | MockRead(SYNCHRONOUS, OK), |
| 14976 | }; |
| 14977 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14978 | arraysize(data_writes)); |
| 14979 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14980 | |
| 14981 | TestCompletionCallback callback; |
| 14982 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14983 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14984 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14985 | // Make sure the headers are sent before adding a chunk. This ensures that |
| 14986 | // they can't be merged with the body in a single send. Not currently |
| 14987 | // necessary since a chunked body is never merged with headers, but this makes |
| 14988 | // the test more future proof. |
| 14989 | base::RunLoop().RunUntilIdle(); |
| 14990 | |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 14991 | upload_data_stream.AppendData("last chunk", 10, true); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14992 | |
| 14993 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14994 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14995 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14996 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14997 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14998 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14999 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15000 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 15001 | |
| 15002 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15003 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15004 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15005 | EXPECT_EQ("hello world", response_data); |
| 15006 | } |
| 15007 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15008 | TEST_F(HttpNetworkTransactionTest, PostReadsErrorResponseAfterResetAnd100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15009 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15010 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 15011 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15012 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15013 | |
| 15014 | HttpRequestInfo request; |
| 15015 | request.method = "POST"; |
| 15016 | request.url = GURL("http://www.foo.com/"); |
| 15017 | request.upload_data_stream = &upload_data_stream; |
| 15018 | request.load_flags = 0; |
| 15019 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15020 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15021 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15022 | |
| 15023 | MockWrite data_writes[] = { |
| 15024 | MockWrite("POST / HTTP/1.1\r\n" |
| 15025 | "Host: www.foo.com\r\n" |
| 15026 | "Connection: keep-alive\r\n" |
| 15027 | "Content-Length: 3\r\n\r\n"), |
| 15028 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15029 | }; |
| 15030 | |
| 15031 | MockRead data_reads[] = { |
| 15032 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 15033 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 15034 | MockRead("hello world"), |
| 15035 | MockRead(SYNCHRONOUS, OK), |
| 15036 | }; |
| 15037 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15038 | arraysize(data_writes)); |
| 15039 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15040 | |
| 15041 | TestCompletionCallback callback; |
| 15042 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15043 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15044 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15045 | |
| 15046 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15047 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15048 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15049 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15050 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15051 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15052 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15053 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 15054 | |
| 15055 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15056 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15057 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15058 | EXPECT_EQ("hello world", response_data); |
| 15059 | } |
| 15060 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15061 | TEST_F(HttpNetworkTransactionTest, PostIgnoresNonErrorResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15062 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15063 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 15064 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15065 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15066 | |
| 15067 | HttpRequestInfo request; |
| 15068 | request.method = "POST"; |
| 15069 | request.url = GURL("http://www.foo.com/"); |
| 15070 | request.upload_data_stream = &upload_data_stream; |
| 15071 | request.load_flags = 0; |
| 15072 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15073 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15074 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15075 | // Send headers successfully, but get an error while sending the body. |
| 15076 | MockWrite data_writes[] = { |
| 15077 | MockWrite("POST / HTTP/1.1\r\n" |
| 15078 | "Host: www.foo.com\r\n" |
| 15079 | "Connection: keep-alive\r\n" |
| 15080 | "Content-Length: 3\r\n\r\n"), |
| 15081 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15082 | }; |
| 15083 | |
| 15084 | MockRead data_reads[] = { |
| 15085 | MockRead("HTTP/1.0 200 Just Dandy\r\n\r\n"), |
| 15086 | MockRead("hello world"), |
| 15087 | MockRead(SYNCHRONOUS, OK), |
| 15088 | }; |
| 15089 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15090 | arraysize(data_writes)); |
| 15091 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15092 | |
| 15093 | TestCompletionCallback callback; |
| 15094 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15095 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15096 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15097 | |
| 15098 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15099 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15100 | } |
| 15101 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15102 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15103 | PostIgnoresNonErrorResponseAfterResetAnd100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15104 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15105 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 15106 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15107 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15108 | |
| 15109 | HttpRequestInfo request; |
| 15110 | request.method = "POST"; |
| 15111 | request.url = GURL("http://www.foo.com/"); |
| 15112 | request.upload_data_stream = &upload_data_stream; |
| 15113 | request.load_flags = 0; |
| 15114 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15115 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15116 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15117 | // Send headers successfully, but get an error while sending the body. |
| 15118 | MockWrite data_writes[] = { |
| 15119 | MockWrite("POST / HTTP/1.1\r\n" |
| 15120 | "Host: www.foo.com\r\n" |
| 15121 | "Connection: keep-alive\r\n" |
| 15122 | "Content-Length: 3\r\n\r\n"), |
| 15123 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15124 | }; |
| 15125 | |
| 15126 | MockRead data_reads[] = { |
| 15127 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 15128 | MockRead("HTTP/1.0 302 Redirect\r\n"), |
| 15129 | MockRead("Location: http://somewhere-else.com/\r\n"), |
| 15130 | MockRead("Content-Length: 0\r\n\r\n"), |
| 15131 | MockRead(SYNCHRONOUS, OK), |
| 15132 | }; |
| 15133 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15134 | arraysize(data_writes)); |
| 15135 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15136 | |
| 15137 | TestCompletionCallback callback; |
| 15138 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15139 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15140 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15141 | |
| 15142 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15143 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15144 | } |
| 15145 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15146 | TEST_F(HttpNetworkTransactionTest, PostIgnoresHttp09ResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15147 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15148 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 15149 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15150 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15151 | |
| 15152 | HttpRequestInfo request; |
| 15153 | request.method = "POST"; |
| 15154 | request.url = GURL("http://www.foo.com/"); |
| 15155 | request.upload_data_stream = &upload_data_stream; |
| 15156 | request.load_flags = 0; |
| 15157 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15158 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15159 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15160 | // Send headers successfully, but get an error while sending the body. |
| 15161 | MockWrite data_writes[] = { |
| 15162 | MockWrite("POST / HTTP/1.1\r\n" |
| 15163 | "Host: www.foo.com\r\n" |
| 15164 | "Connection: keep-alive\r\n" |
| 15165 | "Content-Length: 3\r\n\r\n"), |
| 15166 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15167 | }; |
| 15168 | |
| 15169 | MockRead data_reads[] = { |
| 15170 | MockRead("HTTP 0.9 rocks!"), |
| 15171 | MockRead(SYNCHRONOUS, OK), |
| 15172 | }; |
| 15173 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15174 | arraysize(data_writes)); |
| 15175 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15176 | |
| 15177 | TestCompletionCallback callback; |
| 15178 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15179 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15180 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15181 | |
| 15182 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15183 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15184 | } |
| 15185 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15186 | TEST_F(HttpNetworkTransactionTest, PostIgnoresPartial400HeadersAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15187 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15188 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 15189 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15190 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15191 | |
| 15192 | HttpRequestInfo request; |
| 15193 | request.method = "POST"; |
| 15194 | request.url = GURL("http://www.foo.com/"); |
| 15195 | request.upload_data_stream = &upload_data_stream; |
| 15196 | request.load_flags = 0; |
| 15197 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15198 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15199 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15200 | // Send headers successfully, but get an error while sending the body. |
| 15201 | MockWrite data_writes[] = { |
| 15202 | MockWrite("POST / HTTP/1.1\r\n" |
| 15203 | "Host: www.foo.com\r\n" |
| 15204 | "Connection: keep-alive\r\n" |
| 15205 | "Content-Length: 3\r\n\r\n"), |
| 15206 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15207 | }; |
| 15208 | |
| 15209 | MockRead data_reads[] = { |
| 15210 | MockRead("HTTP/1.0 400 Not a Full Response\r\n"), |
| 15211 | MockRead(SYNCHRONOUS, OK), |
| 15212 | }; |
| 15213 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15214 | arraysize(data_writes)); |
| 15215 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15216 | |
| 15217 | TestCompletionCallback callback; |
| 15218 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15219 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15220 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15221 | |
| 15222 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15223 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15224 | } |
| 15225 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15226 | // Verify that proxy headers are not sent to the destination server when |
| 15227 | // establishing a tunnel for a secure WebSocket connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15228 | TEST_F(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWssTunnel) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15229 | HttpRequestInfo request; |
| 15230 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15231 | request.url = GURL("wss://www.example.org/"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15232 | AddWebSocketHeaders(&request.extra_headers); |
| 15233 | |
| 15234 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 15235 | session_deps_.proxy_service = |
| 15236 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15237 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15238 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15239 | |
| 15240 | // Since a proxy is configured, try to establish a tunnel. |
| 15241 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15242 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 15243 | "Host: www.example.org:443\r\n" |
| 15244 | "Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15245 | |
| 15246 | // After calling trans->RestartWithAuth(), this is the request we should |
| 15247 | // be issuing -- the final header line contains the credentials. |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15248 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 15249 | "Host: www.example.org:443\r\n" |
| 15250 | "Proxy-Connection: keep-alive\r\n" |
| 15251 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15252 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15253 | MockWrite("GET / HTTP/1.1\r\n" |
| 15254 | "Host: www.example.org\r\n" |
| 15255 | "Connection: Upgrade\r\n" |
| 15256 | "Upgrade: websocket\r\n" |
| 15257 | "Origin: http://www.example.org\r\n" |
| 15258 | "Sec-WebSocket-Version: 13\r\n" |
| 15259 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15260 | }; |
| 15261 | |
| 15262 | // The proxy responds to the connect with a 407, using a persistent |
| 15263 | // connection. |
| 15264 | MockRead data_reads[] = { |
| 15265 | // No credentials. |
| 15266 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 15267 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 15268 | MockRead("Content-Length: 0\r\n"), |
| 15269 | MockRead("Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15270 | |
| 15271 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 15272 | |
| 15273 | MockRead("HTTP/1.1 101 Switching Protocols\r\n"), |
| 15274 | MockRead("Upgrade: websocket\r\n"), |
| 15275 | MockRead("Connection: Upgrade\r\n"), |
| 15276 | MockRead("Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n"), |
| 15277 | }; |
| 15278 | |
| 15279 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15280 | arraysize(data_writes)); |
| 15281 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15282 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 15283 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 15284 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15285 | std::unique_ptr<HttpNetworkTransaction> trans( |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15286 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 15287 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
| 15288 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 15289 | &websocket_stream_create_helper); |
| 15290 | |
| 15291 | { |
| 15292 | TestCompletionCallback callback; |
| 15293 | |
| 15294 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15295 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15296 | |
| 15297 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15298 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15299 | } |
| 15300 | |
| 15301 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 15302 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15303 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15304 | EXPECT_EQ(407, response->headers->response_code()); |
| 15305 | |
| 15306 | { |
| 15307 | TestCompletionCallback callback; |
| 15308 | |
| 15309 | int rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 15310 | callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15311 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15312 | |
| 15313 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15314 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15315 | } |
| 15316 | |
| 15317 | response = trans->GetResponseInfo(); |
| 15318 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15319 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15320 | |
| 15321 | EXPECT_EQ(101, response->headers->response_code()); |
| 15322 | |
| 15323 | trans.reset(); |
| 15324 | session->CloseAllConnections(); |
| 15325 | } |
| 15326 | |
| 15327 | // Verify that proxy headers are not sent to the destination server when |
| 15328 | // establishing a tunnel for an insecure WebSocket connection. |
| 15329 | // This requires the authentication info to be injected into the auth cache |
| 15330 | // due to crbug.com/395064 |
| 15331 | // TODO(ricea): Change to use a 407 response once issue 395064 is fixed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15332 | TEST_F(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWsTunnel) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15333 | HttpRequestInfo request; |
| 15334 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15335 | request.url = GURL("ws://www.example.org/"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15336 | AddWebSocketHeaders(&request.extra_headers); |
| 15337 | |
| 15338 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 15339 | session_deps_.proxy_service = |
| 15340 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15341 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15342 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15343 | |
| 15344 | MockWrite data_writes[] = { |
| 15345 | // Try to establish a tunnel for the WebSocket connection, with |
| 15346 | // credentials. Because WebSockets have a separate set of socket pools, |
| 15347 | // they cannot and will not use the same TCP/IP connection as the |
| 15348 | // preflight HTTP request. |
| 15349 | MockWrite( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15350 | "CONNECT www.example.org:80 HTTP/1.1\r\n" |
| 15351 | "Host: www.example.org:80\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15352 | "Proxy-Connection: keep-alive\r\n" |
| 15353 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 15354 | |
| 15355 | MockWrite( |
| 15356 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15357 | "Host: www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15358 | "Connection: Upgrade\r\n" |
| 15359 | "Upgrade: websocket\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15360 | "Origin: http://www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15361 | "Sec-WebSocket-Version: 13\r\n" |
| 15362 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n\r\n"), |
| 15363 | }; |
| 15364 | |
| 15365 | MockRead data_reads[] = { |
| 15366 | // HTTP CONNECT with credentials. |
| 15367 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 15368 | |
| 15369 | // WebSocket connection established inside tunnel. |
| 15370 | MockRead("HTTP/1.1 101 Switching Protocols\r\n"), |
| 15371 | MockRead("Upgrade: websocket\r\n"), |
| 15372 | MockRead("Connection: Upgrade\r\n"), |
| 15373 | MockRead("Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n"), |
| 15374 | }; |
| 15375 | |
| 15376 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15377 | arraysize(data_writes)); |
| 15378 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15379 | |
| 15380 | session->http_auth_cache()->Add( |
| 15381 | GURL("http://myproxy:70/"), "MyRealm1", HttpAuth::AUTH_SCHEME_BASIC, |
| 15382 | "Basic realm=MyRealm1", AuthCredentials(kFoo, kBar), "/"); |
| 15383 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15384 | std::unique_ptr<HttpNetworkTransaction> trans( |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15385 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 15386 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
| 15387 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 15388 | &websocket_stream_create_helper); |
| 15389 | |
| 15390 | TestCompletionCallback callback; |
| 15391 | |
| 15392 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15393 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15394 | |
| 15395 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15396 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15397 | |
| 15398 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 15399 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15400 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15401 | |
| 15402 | EXPECT_EQ(101, response->headers->response_code()); |
| 15403 | |
| 15404 | trans.reset(); |
| 15405 | session->CloseAllConnections(); |
| 15406 | } |
| 15407 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15408 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesPost) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15409 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15410 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 15411 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15412 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15413 | |
| 15414 | HttpRequestInfo request; |
| 15415 | request.method = "POST"; |
| 15416 | request.url = GURL("http://www.foo.com/"); |
| 15417 | request.upload_data_stream = &upload_data_stream; |
| 15418 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15419 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15420 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15421 | MockWrite data_writes[] = { |
| 15422 | MockWrite("POST / HTTP/1.1\r\n" |
| 15423 | "Host: www.foo.com\r\n" |
| 15424 | "Connection: keep-alive\r\n" |
| 15425 | "Content-Length: 3\r\n\r\n"), |
| 15426 | MockWrite("foo"), |
| 15427 | }; |
| 15428 | |
| 15429 | MockRead data_reads[] = { |
| 15430 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 15431 | MockRead(SYNCHRONOUS, OK), |
| 15432 | }; |
| 15433 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15434 | arraysize(data_writes)); |
| 15435 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15436 | |
| 15437 | TestCompletionCallback callback; |
| 15438 | |
| 15439 | EXPECT_EQ(ERR_IO_PENDING, |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15440 | trans.Start(&request, callback.callback(), BoundNetLog())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15441 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15442 | |
| 15443 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15444 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15445 | |
| 15446 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15447 | trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15448 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15449 | trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15450 | } |
| 15451 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15452 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesPost100Continue) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15453 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15454 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 15455 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15456 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15457 | |
| 15458 | HttpRequestInfo request; |
| 15459 | request.method = "POST"; |
| 15460 | request.url = GURL("http://www.foo.com/"); |
| 15461 | request.upload_data_stream = &upload_data_stream; |
| 15462 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15463 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15464 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15465 | MockWrite data_writes[] = { |
| 15466 | MockWrite("POST / HTTP/1.1\r\n" |
| 15467 | "Host: www.foo.com\r\n" |
| 15468 | "Connection: keep-alive\r\n" |
| 15469 | "Content-Length: 3\r\n\r\n"), |
| 15470 | MockWrite("foo"), |
| 15471 | }; |
| 15472 | |
| 15473 | MockRead data_reads[] = { |
| 15474 | MockRead("HTTP/1.1 100 Continue\r\n\r\n"), |
| 15475 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 15476 | MockRead(SYNCHRONOUS, OK), |
| 15477 | }; |
| 15478 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15479 | arraysize(data_writes)); |
| 15480 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15481 | |
| 15482 | TestCompletionCallback callback; |
| 15483 | |
| 15484 | EXPECT_EQ(ERR_IO_PENDING, |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15485 | trans.Start(&request, callback.callback(), BoundNetLog())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15486 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15487 | |
| 15488 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15489 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15490 | |
| 15491 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15492 | trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15493 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15494 | trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15495 | } |
| 15496 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15497 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesChunkedPost) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15498 | ChunkedUploadDataStream upload_data_stream(0); |
| 15499 | |
| 15500 | HttpRequestInfo request; |
| 15501 | request.method = "POST"; |
| 15502 | request.url = GURL("http://www.foo.com/"); |
| 15503 | request.upload_data_stream = &upload_data_stream; |
| 15504 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15505 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15506 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15507 | // Send headers successfully, but get an error while sending the body. |
| 15508 | MockWrite data_writes[] = { |
| 15509 | MockWrite("POST / HTTP/1.1\r\n" |
| 15510 | "Host: www.foo.com\r\n" |
| 15511 | "Connection: keep-alive\r\n" |
| 15512 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 15513 | MockWrite("1\r\nf\r\n"), MockWrite("2\r\noo\r\n"), MockWrite("0\r\n\r\n"), |
| 15514 | }; |
| 15515 | |
| 15516 | MockRead data_reads[] = { |
| 15517 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 15518 | MockRead(SYNCHRONOUS, OK), |
| 15519 | }; |
| 15520 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15521 | arraysize(data_writes)); |
| 15522 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15523 | |
| 15524 | TestCompletionCallback callback; |
| 15525 | |
| 15526 | EXPECT_EQ(ERR_IO_PENDING, |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15527 | trans.Start(&request, callback.callback(), BoundNetLog())); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15528 | |
| 15529 | base::RunLoop().RunUntilIdle(); |
| 15530 | upload_data_stream.AppendData("f", 1, false); |
| 15531 | |
| 15532 | base::RunLoop().RunUntilIdle(); |
| 15533 | upload_data_stream.AppendData("oo", 2, true); |
| 15534 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15535 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15536 | |
| 15537 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15538 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15539 | |
| 15540 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15541 | trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15542 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15543 | trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15544 | } |
| 15545 | |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 15546 | #if !defined(OS_IOS) |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15547 | TEST_F(HttpNetworkTransactionTest, TokenBindingSpdy) { |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 15548 | const std::string https_url = "https://www.example.com"; |
| 15549 | HttpRequestInfo request; |
| 15550 | request.url = GURL(https_url); |
| 15551 | request.method = "GET"; |
| 15552 | |
| 15553 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 15554 | ssl.token_binding_negotiated = true; |
| 15555 | ssl.token_binding_key_param = TB_PARAM_ECDSAP256; |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15556 | ssl.next_proto = kProtoHTTP2; |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 15557 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 15558 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15559 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15560 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 15561 | MockRead reads[] = {CreateMockRead(resp), CreateMockRead(body), |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 15562 | MockRead(ASYNC, ERR_IO_PENDING)}; |
| 15563 | StaticSocketDataProvider data(reads, arraysize(reads), nullptr, 0); |
| 15564 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15565 | session_deps_.channel_id_service.reset(new ChannelIDService( |
| 15566 | new DefaultChannelIDStore(nullptr), base::ThreadTaskRunnerHandle::Get())); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15567 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 15568 | |
| 15569 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 15570 | TestCompletionCallback callback; |
| 15571 | EXPECT_EQ(ERR_IO_PENDING, |
| 15572 | trans.Start(&request, callback.callback(), BoundNetLog())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 15573 | base::RunLoop().RunUntilIdle(); |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 15574 | |
| 15575 | EXPECT_TRUE(trans.GetResponseInfo()->was_fetched_via_spdy); |
| 15576 | HttpRequestHeaders headers; |
| 15577 | ASSERT_TRUE(trans.GetFullRequestHeaders(&headers)); |
| 15578 | EXPECT_TRUE(headers.HasHeader(HttpRequestHeaders::kTokenBinding)); |
| 15579 | } |
| 15580 | #endif // !defined(OS_IOS) |
| 15581 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 15582 | } // namespace net |