[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" |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 63 | #include "net/log/test_net_log.h" |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 64 | #include "net/log/test_net_log_entry.h" |
| 65 | #include "net/log/test_net_log_util.h" |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 66 | #include "net/proxy/mock_proxy_resolver.h" |
[email protected] | 51fff29d | 2008-12-19 22:17:53 | [diff] [blame] | 67 | #include "net/proxy/proxy_config_service_fixed.h" |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 68 | #include "net/proxy/proxy_info.h" |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 69 | #include "net/proxy/proxy_resolver.h" |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 70 | #include "net/proxy/proxy_server.h" |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 71 | #include "net/proxy/proxy_service.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 72 | #include "net/socket/client_socket_factory.h" |
mmenke | d3641e1 | 2016-01-28 16:06:15 | [diff] [blame] | 73 | #include "net/socket/client_socket_pool.h" |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 74 | #include "net/socket/client_socket_pool_manager.h" |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 75 | #include "net/socket/connection_attempts.h" |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 76 | #include "net/socket/mock_client_socket_pool_manager.h" |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 77 | #include "net/socket/next_proto.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 78 | #include "net/socket/socket_test_util.h" |
| 79 | #include "net/socket/ssl_client_socket.h" |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 80 | #include "net/spdy/spdy_framer.h" |
| 81 | #include "net/spdy/spdy_session.h" |
| 82 | #include "net/spdy/spdy_session_pool.h" |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 83 | #include "net/spdy/spdy_test_util_common.h" |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 84 | #include "net/ssl/default_channel_id_store.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 85 | #include "net/ssl/ssl_cert_request_info.h" |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 86 | #include "net/ssl/ssl_config_service.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 87 | #include "net/ssl/ssl_config_service_defaults.h" |
| 88 | #include "net/ssl/ssl_info.h" |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 89 | #include "net/ssl/ssl_private_key.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 90 | #include "net/test/cert_test_util.h" |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 91 | #include "net/test/gtest_util.h" |
rsleevi | a69c79a | 2016-06-22 03:28:43 | [diff] [blame] | 92 | #include "net/test/test_data_directory.h" |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 93 | #include "net/websockets/websocket_handshake_stream_base.h" |
bnc | f458840 | 2015-11-24 13:33:18 | [diff] [blame] | 94 | #include "testing/gmock/include/gmock/gmock.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 95 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | 23887f04f | 2008-12-02 19:20:15 | [diff] [blame] | 96 | #include "testing/platform_test.h" |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 97 | #include "url/gurl.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 98 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 99 | using net::test::IsError; |
| 100 | using net::test::IsOk; |
| 101 | |
[email protected] | ad65a3e | 2013-12-25 18:18:01 | [diff] [blame] | 102 | using base::ASCIIToUTF16; |
| 103 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 104 | //----------------------------------------------------------------------------- |
| 105 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 106 | namespace net { |
| 107 | |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 108 | namespace { |
| 109 | |
[email protected] | 42cba2fb | 2013-03-29 19:58:57 | [diff] [blame] | 110 | const base::string16 kBar(ASCIIToUTF16("bar")); |
| 111 | const base::string16 kBar2(ASCIIToUTF16("bar2")); |
| 112 | const base::string16 kBar3(ASCIIToUTF16("bar3")); |
| 113 | const base::string16 kBaz(ASCIIToUTF16("baz")); |
| 114 | const base::string16 kFirst(ASCIIToUTF16("first")); |
| 115 | const base::string16 kFoo(ASCIIToUTF16("foo")); |
| 116 | const base::string16 kFoo2(ASCIIToUTF16("foo2")); |
| 117 | const base::string16 kFoo3(ASCIIToUTF16("foo3")); |
| 118 | const base::string16 kFou(ASCIIToUTF16("fou")); |
| 119 | const base::string16 kSecond(ASCIIToUTF16("second")); |
| 120 | const base::string16 kTestingNTLM(ASCIIToUTF16("testing-ntlm")); |
| 121 | const base::string16 kWrongPassword(ASCIIToUTF16("wrongpassword")); |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 122 | |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 123 | const char kAlternativeServiceHttpHeader[] = |
| 124 | "Alt-Svc: h2=\"mail.example.org:443\"\r\n"; |
| 125 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 126 | int GetIdleSocketCountInTransportSocketPool(HttpNetworkSession* session) { |
| 127 | return session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 128 | ->IdleSocketCount(); |
[email protected] | e5c02664 | 2012-03-17 00:14:02 | [diff] [blame] | 129 | } |
| 130 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 131 | int GetIdleSocketCountInSSLSocketPool(HttpNetworkSession* session) { |
| 132 | return session->GetSSLSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 133 | ->IdleSocketCount(); |
[email protected] | e5c02664 | 2012-03-17 00:14:02 | [diff] [blame] | 134 | } |
| 135 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 136 | bool IsTransportSocketPoolStalled(HttpNetworkSession* session) { |
| 137 | return session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 138 | ->IsStalled(); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 139 | } |
| 140 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 141 | // Takes in a Value created from a NetLogHttpResponseParameter, and returns |
| 142 | // a JSONified list of headers as a single string. Uses single quotes instead |
| 143 | // of double quotes for easier comparison. Returns false on failure. |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 144 | bool GetHeaders(base::DictionaryValue* params, std::string* headers) { |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 145 | if (!params) |
| 146 | return false; |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 147 | base::ListValue* header_list; |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 148 | if (!params->GetList("headers", &header_list)) |
| 149 | return false; |
| 150 | std::string double_quote_headers; |
estade | 8d04646 | 2015-05-16 01:02:34 | [diff] [blame] | 151 | base::JSONWriter::Write(*header_list, &double_quote_headers); |
[email protected] | 466c986 | 2013-12-03 22:05:28 | [diff] [blame] | 152 | base::ReplaceChars(double_quote_headers, "\"", "'", headers); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 153 | return true; |
| 154 | } |
| 155 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 156 | // Tests LoadTimingInfo in the case a socket is reused and no PAC script is |
| 157 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 158 | void TestLoadTimingReused(const LoadTimingInfo& load_timing_info) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 159 | EXPECT_TRUE(load_timing_info.socket_reused); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 160 | EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 161 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 162 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 163 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 164 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 165 | ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 166 | EXPECT_FALSE(load_timing_info.send_start.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 167 | |
| 168 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 169 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 170 | // Set at a higher level. |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 171 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 172 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 173 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 174 | } |
| 175 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 176 | // Tests LoadTimingInfo in the case a new socket is used and no PAC script is |
| 177 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 178 | void TestLoadTimingNotReused(const LoadTimingInfo& load_timing_info, |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 179 | int connect_timing_flags) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 180 | EXPECT_FALSE(load_timing_info.socket_reused); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 181 | EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 182 | |
| 183 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 184 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 185 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 186 | ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 187 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 188 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 189 | load_timing_info.send_start); |
| 190 | |
| 191 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 192 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 193 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 194 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 195 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 196 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | // Tests LoadTimingInfo in the case a socket is reused and a PAC script is |
| 200 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 201 | void TestLoadTimingReusedWithPac(const LoadTimingInfo& load_timing_info) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 202 | EXPECT_TRUE(load_timing_info.socket_reused); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 203 | EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 204 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 205 | ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 206 | |
| 207 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 208 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 209 | load_timing_info.proxy_resolve_end); |
| 210 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 211 | load_timing_info.send_start); |
| 212 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 213 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 214 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 215 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 216 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 217 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | // Tests LoadTimingInfo in the case a new socket is used and a PAC script is |
| 221 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 222 | void TestLoadTimingNotReusedWithPac(const LoadTimingInfo& load_timing_info, |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 223 | int connect_timing_flags) { |
| 224 | EXPECT_FALSE(load_timing_info.socket_reused); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 225 | EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 226 | |
| 227 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 228 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 229 | load_timing_info.proxy_resolve_end); |
| 230 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 231 | load_timing_info.connect_timing.connect_start); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 232 | ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 233 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 234 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 235 | load_timing_info.send_start); |
| 236 | |
| 237 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 238 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 239 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 240 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 241 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 242 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 243 | } |
| 244 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 245 | void AddWebSocketHeaders(HttpRequestHeaders* headers) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 246 | headers->SetHeader("Connection", "Upgrade"); |
| 247 | headers->SetHeader("Upgrade", "websocket"); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 248 | headers->SetHeader("Origin", "http://www.example.org"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 249 | headers->SetHeader("Sec-WebSocket-Version", "13"); |
| 250 | headers->SetHeader("Sec-WebSocket-Key", "dGhlIHNhbXBsZSBub25jZQ=="); |
| 251 | } |
| 252 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 253 | std::unique_ptr<HttpNetworkSession> CreateSession( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 254 | SpdySessionDependencies* session_deps) { |
[email protected] | c6bf815 | 2012-12-02 07:43:34 | [diff] [blame] | 255 | return SpdySessionDependencies::SpdyCreateSession(session_deps); |
[email protected] | e8d53619 | 2008-10-17 22:21:14 | [diff] [blame] | 256 | } |
| 257 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 258 | } // namespace |
| 259 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 260 | class HttpNetworkTransactionTest : public PlatformTest { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 261 | public: |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 262 | ~HttpNetworkTransactionTest() override { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 263 | // Important to restore the per-pool limit first, since the pool limit must |
| 264 | // always be greater than group limit, and the tests reduce both limits. |
| 265 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 266 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_pool_sockets_); |
| 267 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 268 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_group_sockets_); |
| 269 | } |
| 270 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 271 | protected: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 272 | HttpNetworkTransactionTest() |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 273 | : old_max_group_sockets_(ClientSocketPoolManager::max_sockets_per_group( |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 274 | HttpNetworkSession::NORMAL_SOCKET_POOL)), |
| 275 | old_max_pool_sockets_(ClientSocketPoolManager::max_sockets_per_pool( |
| 276 | HttpNetworkSession::NORMAL_SOCKET_POOL)) { |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 277 | session_deps_.enable_http2_alternative_service_with_different_host = true; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 278 | } |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 279 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 280 | struct SimpleGetHelperResult { |
| 281 | int rv; |
| 282 | std::string status_line; |
| 283 | std::string response_data; |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 284 | int64_t total_received_bytes; |
| 285 | int64_t total_sent_bytes; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 286 | LoadTimingInfo load_timing_info; |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 287 | ConnectionAttempts connection_attempts; |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 288 | IPEndPoint remote_endpoint_after_start; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 289 | }; |
| 290 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 291 | void SetUp() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 292 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 293 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 294 | } |
| 295 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 296 | void TearDown() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 297 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 298 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 299 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 300 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 301 | PlatformTest::TearDown(); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 302 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 303 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 304 | } |
| 305 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 306 | // Either |write_failure| specifies a write failure or |read_failure| |
| 307 | // specifies a read failure when using a reused socket. In either case, the |
| 308 | // failure should cause the network transaction to resend the request, and the |
| 309 | // other argument should be NULL. |
| 310 | void KeepAliveConnectionResendRequestTest(const MockWrite* write_failure, |
| 311 | const MockRead* read_failure); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 312 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 313 | // Either |write_failure| specifies a write failure or |read_failure| |
| 314 | // specifies a read failure when using a reused socket. In either case, the |
| 315 | // failure should cause the network transaction to resend the request, and the |
| 316 | // other argument should be NULL. |
| 317 | void PreconnectErrorResendRequestTest(const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 318 | const MockRead* read_failure, |
| 319 | bool use_spdy); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 320 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 321 | SimpleGetHelperResult SimpleGetHelperForData(StaticSocketDataProvider* data[], |
| 322 | size_t data_count) { |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 323 | SimpleGetHelperResult out; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 324 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 325 | HttpRequestInfo request; |
| 326 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 327 | request.url = GURL("http://www.example.org/"); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 328 | request.load_flags = 0; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 329 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 330 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 331 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 332 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 333 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 334 | new HttpNetworkTransaction(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()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [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(); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [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. |
| 352 | EXPECT_TRUE(trans->GetLoadTimingInfo(&out.load_timing_info)); |
| 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 | |
| 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 = |
| 371 | trans->GetRemoteEndpoint(&out.remote_endpoint_after_start); |
| 372 | EXPECT_EQ(got_endpoint, |
| 373 | out.remote_endpoint_after_start.address().size() > 0); |
| 374 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 375 | rv = ReadTransaction(trans.get(), &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( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 381 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST_HEADERS, |
[email protected] | 169d001 | 2010-05-10 23:20:12 | [diff] [blame] | 382 | NetLog::PHASE_NONE); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 383 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 384 | entries, pos, |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 385 | NetLog::TYPE_HTTP_TRANSACTION_READ_RESPONSE_HEADERS, |
| 386 | NetLog::PHASE_NONE); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 387 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 388 | std::string line; |
| 389 | EXPECT_TRUE(entries[pos].GetStringValue("line", &line)); |
| 390 | EXPECT_EQ("GET / HTTP/1.1\r\n", line); |
| 391 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 392 | HttpRequestHeaders request_headers; |
| 393 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 394 | std::string value; |
| 395 | EXPECT_TRUE(request_headers.GetHeader("Host", &value)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 396 | EXPECT_EQ("www.example.org", value); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 397 | EXPECT_TRUE(request_headers.GetHeader("Connection", &value)); |
| 398 | EXPECT_EQ("keep-alive", value); |
| 399 | |
| 400 | std::string response_headers; |
| 401 | EXPECT_TRUE(GetHeaders(entries[pos].params.get(), &response_headers)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 402 | EXPECT_EQ("['Host: www.example.org','Connection: keep-alive']", |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 403 | response_headers); |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 404 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 405 | out.total_received_bytes = trans->GetTotalReceivedBytes(); |
| 406 | // The total number of sent bytes should not have changed. |
| 407 | EXPECT_EQ(out.total_sent_bytes, trans->GetTotalSentBytes()); |
| 408 | |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 409 | trans->GetConnectionAttempts(&out.connection_attempts); |
[email protected] | aecfbf2 | 2008-10-16 02:02:47 | [diff] [blame] | 410 | return out; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 411 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 412 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 413 | SimpleGetHelperResult SimpleGetHelper(MockRead data_reads[], |
| 414 | size_t reads_count) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 415 | MockWrite data_writes[] = { |
| 416 | MockWrite("GET / HTTP/1.1\r\n" |
| 417 | "Host: www.example.org\r\n" |
| 418 | "Connection: keep-alive\r\n\r\n"), |
| 419 | }; |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 420 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 421 | StaticSocketDataProvider reads(data_reads, reads_count, data_writes, |
| 422 | arraysize(data_writes)); |
| 423 | StaticSocketDataProvider* data[] = {&reads}; |
| 424 | SimpleGetHelperResult out = SimpleGetHelperForData(data, 1); |
| 425 | |
| 426 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
| 427 | out.total_sent_bytes); |
| 428 | return out; |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 429 | } |
| 430 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 431 | void ConnectStatusHelperWithExpectedStatus(const MockRead& status, |
| 432 | int expected_status); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 433 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 434 | void ConnectStatusHelper(const MockRead& status); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 435 | |
| 436 | void BypassHostCacheOnRefreshHelper(int load_flags); |
| 437 | |
| 438 | void CheckErrorIsPassedBack(int error, IoMode mode); |
| 439 | |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 440 | SpdyTestUtil spdy_util_; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 441 | SpdySessionDependencies session_deps_; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 442 | |
| 443 | // Original socket limits. Some tests set these. Safest to always restore |
| 444 | // them once each test has been run. |
| 445 | int old_max_group_sockets_; |
| 446 | int old_max_pool_sockets_; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 447 | }; |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 448 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 449 | namespace { |
| 450 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 451 | class BeforeHeadersSentHandler { |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 452 | public: |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 453 | BeforeHeadersSentHandler() |
| 454 | : observed_before_headers_sent_with_proxy_(false), |
| 455 | observed_before_headers_sent_(false) {} |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 456 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 457 | void OnBeforeHeadersSent(const ProxyInfo& proxy_info, |
| 458 | HttpRequestHeaders* request_headers) { |
| 459 | observed_before_headers_sent_ = true; |
| 460 | if (!proxy_info.is_http() && !proxy_info.is_https() && |
| 461 | !proxy_info.is_quic()) { |
| 462 | return; |
| 463 | } |
| 464 | observed_before_headers_sent_with_proxy_ = true; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 465 | observed_proxy_server_uri_ = proxy_info.proxy_server().ToURI(); |
| 466 | } |
| 467 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 468 | bool observed_before_headers_sent_with_proxy() const { |
| 469 | return observed_before_headers_sent_with_proxy_; |
| 470 | } |
| 471 | |
| 472 | bool observed_before_headers_sent() const { |
| 473 | return observed_before_headers_sent_; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 474 | } |
| 475 | |
| 476 | std::string observed_proxy_server_uri() const { |
| 477 | return observed_proxy_server_uri_; |
| 478 | } |
| 479 | |
| 480 | private: |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 481 | bool observed_before_headers_sent_with_proxy_; |
| 482 | bool observed_before_headers_sent_; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 483 | std::string observed_proxy_server_uri_; |
| 484 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 485 | DISALLOW_COPY_AND_ASSIGN(BeforeHeadersSentHandler); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 486 | }; |
| 487 | |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 488 | // Fill |str| with a long header list that consumes >= |size| bytes. |
| 489 | void FillLargeHeadersString(std::string* str, int size) { |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 490 | const char row[] = |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 491 | "SomeHeaderName: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n"; |
| 492 | const int sizeof_row = strlen(row); |
| 493 | const int num_rows = static_cast<int>( |
| 494 | ceil(static_cast<float>(size) / sizeof_row)); |
| 495 | const int sizeof_data = num_rows * sizeof_row; |
| 496 | DCHECK(sizeof_data >= size); |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 497 | str->reserve(sizeof_data); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 498 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 499 | for (int i = 0; i < num_rows; ++i) |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 500 | str->append(row, sizeof_row); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 501 | } |
| 502 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 503 | #if defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 504 | // Alternative functions that eliminate randomness and dependency on the local |
| 505 | // host name so that the generated NTLM messages are reproducible. |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 506 | void MockGenerateRandom1(uint8_t* output, size_t n) { |
| 507 | static const uint8_t bytes[] = {0x55, 0x29, 0x66, 0x26, |
| 508 | 0x6b, 0x9c, 0x73, 0x54}; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 509 | static size_t current_byte = 0; |
| 510 | for (size_t i = 0; i < n; ++i) { |
| 511 | output[i] = bytes[current_byte++]; |
| 512 | current_byte %= arraysize(bytes); |
| 513 | } |
| 514 | } |
| 515 | |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 516 | void MockGenerateRandom2(uint8_t* output, size_t n) { |
| 517 | static const uint8_t bytes[] = {0x96, 0x79, 0x85, 0xe7, 0x49, 0x93, |
| 518 | 0x70, 0xa1, 0x4e, 0xe7, 0x87, 0x45, |
| 519 | 0x31, 0x5b, 0xd3, 0x1f}; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 520 | static size_t current_byte = 0; |
| 521 | for (size_t i = 0; i < n; ++i) { |
| 522 | output[i] = bytes[current_byte++]; |
| 523 | current_byte %= arraysize(bytes); |
| 524 | } |
| 525 | } |
| 526 | |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 527 | std::string MockGetHostName() { |
| 528 | return "WTC-WIN7"; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 529 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 530 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 531 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 532 | template<typename ParentPool> |
| 533 | class CaptureGroupNameSocketPool : public ParentPool { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 534 | public: |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 535 | CaptureGroupNameSocketPool(HostResolver* host_resolver, |
| 536 | CertVerifier* cert_verifier); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 537 | |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 538 | const std::string last_group_name_received() const { |
| 539 | return last_group_name_; |
| 540 | } |
| 541 | |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 542 | int RequestSocket(const std::string& group_name, |
| 543 | const void* socket_params, |
| 544 | RequestPriority priority, |
mmenke | d3641e1 | 2016-01-28 16:06:15 | [diff] [blame] | 545 | ClientSocketPool::RespectLimits respect_limits, |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 546 | ClientSocketHandle* handle, |
| 547 | const CompletionCallback& callback, |
| 548 | const BoundNetLog& net_log) override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 549 | last_group_name_ = group_name; |
| 550 | return ERR_IO_PENDING; |
| 551 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 552 | void CancelRequest(const std::string& group_name, |
| 553 | ClientSocketHandle* handle) override {} |
| 554 | void ReleaseSocket(const std::string& group_name, |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 555 | std::unique_ptr<StreamSocket> socket, |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 556 | int id) override {} |
| 557 | void CloseIdleSockets() override {} |
| 558 | int IdleSocketCount() const override { return 0; } |
| 559 | int IdleSocketCountInGroup(const std::string& group_name) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 560 | return 0; |
| 561 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 562 | LoadState GetLoadState(const std::string& group_name, |
| 563 | const ClientSocketHandle* handle) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 564 | return LOAD_STATE_IDLE; |
| 565 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 566 | base::TimeDelta ConnectionTimeout() const override { |
[email protected] | a796bcec | 2010-03-22 17:17:26 | [diff] [blame] | 567 | return base::TimeDelta(); |
| 568 | } |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 569 | |
| 570 | private: |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 571 | std::string last_group_name_; |
| 572 | }; |
| 573 | |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 574 | typedef CaptureGroupNameSocketPool<TransportClientSocketPool> |
| 575 | CaptureGroupNameTransportSocketPool; |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 576 | typedef CaptureGroupNameSocketPool<HttpProxyClientSocketPool> |
| 577 | CaptureGroupNameHttpProxySocketPool; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 578 | typedef CaptureGroupNameSocketPool<SOCKSClientSocketPool> |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 579 | CaptureGroupNameSOCKSSocketPool; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 580 | typedef CaptureGroupNameSocketPool<SSLClientSocketPool> |
| 581 | CaptureGroupNameSSLSocketPool; |
| 582 | |
rkaplow | d90695c | 2015-03-25 22:12:41 | [diff] [blame] | 583 | template <typename ParentPool> |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 584 | CaptureGroupNameSocketPool<ParentPool>::CaptureGroupNameSocketPool( |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 585 | HostResolver* host_resolver, |
| 586 | CertVerifier* /* cert_verifier */) |
tbansal | 7b403bcc | 2016-04-13 22:33:21 | [diff] [blame] | 587 | : ParentPool(0, 0, host_resolver, NULL, NULL, NULL) {} |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 588 | |
hashimoto | 0d3e4fb | 2015-01-09 05:02:50 | [diff] [blame] | 589 | template <> |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 590 | CaptureGroupNameHttpProxySocketPool::CaptureGroupNameSocketPool( |
hashimoto | dae13b0 | 2015-01-15 04:28:21 | [diff] [blame] | 591 | HostResolver* /* host_resolver */, |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 592 | CertVerifier* /* cert_verifier */) |
rkaplow | d90695c | 2015-03-25 22:12:41 | [diff] [blame] | 593 | : HttpProxyClientSocketPool(0, 0, NULL, NULL, NULL) { |
hashimoto | 0d3e4fb | 2015-01-09 05:02:50 | [diff] [blame] | 594 | } |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 595 | |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 596 | template <> |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 597 | CaptureGroupNameSSLSocketPool::CaptureGroupNameSocketPool( |
hashimoto | dae13b0 | 2015-01-15 04:28:21 | [diff] [blame] | 598 | HostResolver* /* host_resolver */, |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 599 | CertVerifier* cert_verifier) |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 600 | : SSLClientSocketPool(0, |
| 601 | 0, |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 602 | cert_verifier, |
| 603 | NULL, |
| 604 | NULL, |
[email protected] | 284303b6 | 2013-11-28 15:11:54 | [diff] [blame] | 605 | NULL, |
eranm | 6571b2b | 2014-12-03 15:53:23 | [diff] [blame] | 606 | NULL, |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 607 | std::string(), |
| 608 | NULL, |
| 609 | NULL, |
| 610 | NULL, |
| 611 | NULL, |
| 612 | NULL, |
[email protected] | 8e45855 | 2014-08-05 00:02:15 | [diff] [blame] | 613 | NULL) { |
| 614 | } |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 615 | |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 616 | //----------------------------------------------------------------------------- |
| 617 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 618 | // Helper functions for validating that AuthChallengeInfo's are correctly |
| 619 | // configured for common cases. |
| 620 | bool CheckBasicServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 621 | if (!auth_challenge) |
| 622 | return false; |
| 623 | EXPECT_FALSE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 624 | EXPECT_EQ("http://www.example.org", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 625 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 626 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 627 | return true; |
| 628 | } |
| 629 | |
| 630 | bool CheckBasicProxyAuth(const AuthChallengeInfo* auth_challenge) { |
| 631 | if (!auth_challenge) |
| 632 | return false; |
| 633 | EXPECT_TRUE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 634 | EXPECT_EQ("http://myproxy:70", auth_challenge->challenger.Serialize()); |
| 635 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
| 636 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
| 637 | return true; |
| 638 | } |
| 639 | |
| 640 | bool CheckBasicSecureProxyAuth(const AuthChallengeInfo* auth_challenge) { |
| 641 | if (!auth_challenge) |
| 642 | return false; |
| 643 | EXPECT_TRUE(auth_challenge->is_proxy); |
| 644 | EXPECT_EQ("https://myproxy:70", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 645 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 646 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 647 | return true; |
| 648 | } |
| 649 | |
| 650 | bool CheckDigestServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 651 | if (!auth_challenge) |
| 652 | return false; |
| 653 | EXPECT_FALSE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 654 | EXPECT_EQ("http://www.example.org", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 655 | EXPECT_EQ("digestive", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 656 | EXPECT_EQ(kDigestAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 657 | return true; |
| 658 | } |
| 659 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 660 | #if defined(NTLM_PORTABLE) |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 661 | bool CheckNTLMServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 662 | if (!auth_challenge) |
| 663 | return false; |
| 664 | EXPECT_FALSE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 665 | EXPECT_EQ("http://172.22.68.17", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 666 | EXPECT_EQ(std::string(), auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 667 | EXPECT_EQ(kNtlmAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 668 | return true; |
| 669 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 670 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 671 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 672 | } // namespace |
| 673 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 674 | TEST_F(HttpNetworkTransactionTest, Basic) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 675 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 676 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 677 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 678 | } |
| 679 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 680 | TEST_F(HttpNetworkTransactionTest, SimpleGET) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 681 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 682 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 683 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 684 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 685 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 686 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 687 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 688 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 689 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 690 | EXPECT_EQ("hello world", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 691 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 692 | EXPECT_EQ(reads_size, out.total_received_bytes); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 693 | EXPECT_EQ(0u, out.connection_attempts.size()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 694 | |
| 695 | EXPECT_FALSE(out.remote_endpoint_after_start.address().empty()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 696 | } |
| 697 | |
| 698 | // Response with no status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 699 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeaders) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 700 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 701 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 702 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 703 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 704 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 705 | arraysize(data_reads)); |
mmenke | e2172e4 | 2016-07-15 03:14:32 | [diff] [blame] | 706 | EXPECT_THAT(out.rv, IsError(ERR_INVALID_HTTP_RESPONSE)); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 707 | } |
| 708 | |
| 709 | // Allow up to 4 bytes of junk to precede status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 710 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk3Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 711 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 712 | MockRead("xxxHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 713 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 714 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 715 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 716 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 717 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 718 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 719 | EXPECT_EQ("DATA", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 720 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 721 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 722 | } |
| 723 | |
| 724 | // Allow up to 4 bytes of junk to precede status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 725 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk4Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 726 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 727 | MockRead("\n\nQJHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 728 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 729 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 730 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 731 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 732 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 733 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 734 | EXPECT_EQ("DATA", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 735 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 736 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 737 | } |
| 738 | |
| 739 | // Beyond 4 bytes of slop and it should fail to find a status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 740 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk5Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 741 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 742 | MockRead("xxxxxHTTP/1.1 404 Not Found\nServer: blah"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 743 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 744 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 745 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 746 | arraysize(data_reads)); |
mmenke | e2172e4 | 2016-07-15 03:14:32 | [diff] [blame] | 747 | EXPECT_THAT(out.rv, IsError(ERR_INVALID_HTTP_RESPONSE)); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 748 | } |
| 749 | |
| 750 | // Same as StatusLineJunk4Bytes, except the read chunks are smaller. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 751 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk4Bytes_Slow) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 752 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 753 | MockRead("\n"), |
| 754 | MockRead("\n"), |
| 755 | MockRead("Q"), |
| 756 | MockRead("J"), |
| 757 | MockRead("HTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 758 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 759 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 760 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 761 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 762 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 763 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 764 | EXPECT_EQ("DATA", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 765 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 766 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 767 | } |
| 768 | |
| 769 | // Close the connection before enough bytes to have a status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 770 | TEST_F(HttpNetworkTransactionTest, StatusLinePartial) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 771 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 772 | MockRead("HTT"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 773 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 774 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 775 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 776 | arraysize(data_reads)); |
mmenke | e2172e4 | 2016-07-15 03:14:32 | [diff] [blame] | 777 | EXPECT_THAT(out.rv, IsError(ERR_INVALID_HTTP_RESPONSE)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 778 | } |
| 779 | |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 780 | // Simulate a 204 response, lacking a Content-Length header, sent over a |
| 781 | // persistent connection. The response should still terminate since a 204 |
| 782 | // cannot have a response body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 783 | TEST_F(HttpNetworkTransactionTest, StopsReading204) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 784 | char junk[] = "junk"; |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 785 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 786 | MockRead("HTTP/1.1 204 No Content\r\n\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 787 | MockRead(junk), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 788 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 789 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 790 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 791 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 792 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 793 | EXPECT_EQ("HTTP/1.1 204 No Content", out.status_line); |
| 794 | EXPECT_EQ("", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 795 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 796 | int64_t response_size = reads_size - strlen(junk); |
| 797 | EXPECT_EQ(response_size, out.total_received_bytes); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 798 | } |
| 799 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 800 | // A simple request using chunked encoding with some extra data after. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 801 | TEST_F(HttpNetworkTransactionTest, ChunkedEncoding) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 802 | std::string final_chunk = "0\r\n\r\n"; |
| 803 | std::string extra_data = "HTTP/1.1 200 OK\r\n"; |
| 804 | std::string last_read = final_chunk + extra_data; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 805 | MockRead data_reads[] = { |
| 806 | MockRead("HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n"), |
| 807 | MockRead("5\r\nHello\r\n"), |
| 808 | MockRead("1\r\n"), |
| 809 | MockRead(" \r\n"), |
| 810 | MockRead("5\r\nworld\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 811 | MockRead(last_read.data()), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 812 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 813 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 814 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 815 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 816 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 817 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 818 | EXPECT_EQ("Hello world", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 819 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 820 | int64_t response_size = reads_size - extra_data.size(); |
| 821 | EXPECT_EQ(response_size, out.total_received_bytes); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 822 | } |
| 823 | |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 824 | // Next tests deal with http://crbug.com/56344. |
| 825 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 826 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 827 | MultipleContentLengthHeadersNoTransferEncoding) { |
| 828 | MockRead data_reads[] = { |
| 829 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 830 | MockRead("Content-Length: 10\r\n"), |
| 831 | MockRead("Content-Length: 5\r\n\r\n"), |
| 832 | }; |
| 833 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 834 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 835 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH)); |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 836 | } |
| 837 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 838 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 839 | DuplicateContentLengthHeadersNoTransferEncoding) { |
| 840 | MockRead data_reads[] = { |
| 841 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 842 | MockRead("Content-Length: 5\r\n"), |
| 843 | MockRead("Content-Length: 5\r\n\r\n"), |
| 844 | MockRead("Hello"), |
| 845 | }; |
| 846 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 847 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 848 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 849 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 850 | EXPECT_EQ("Hello", out.response_data); |
| 851 | } |
| 852 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 853 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 854 | ComplexContentLengthHeadersNoTransferEncoding) { |
| 855 | // More than 2 dupes. |
| 856 | { |
| 857 | MockRead data_reads[] = { |
| 858 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 859 | MockRead("Content-Length: 5\r\n"), |
| 860 | MockRead("Content-Length: 5\r\n"), |
| 861 | MockRead("Content-Length: 5\r\n\r\n"), |
| 862 | MockRead("Hello"), |
| 863 | }; |
| 864 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 865 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 866 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 867 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 868 | EXPECT_EQ("Hello", out.response_data); |
| 869 | } |
| 870 | // HTTP/1.0 |
| 871 | { |
| 872 | MockRead data_reads[] = { |
| 873 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 874 | MockRead("Content-Length: 5\r\n"), |
| 875 | MockRead("Content-Length: 5\r\n"), |
| 876 | MockRead("Content-Length: 5\r\n\r\n"), |
| 877 | MockRead("Hello"), |
| 878 | }; |
| 879 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 880 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 881 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 882 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 883 | EXPECT_EQ("Hello", out.response_data); |
| 884 | } |
| 885 | // 2 dupes and one mismatched. |
| 886 | { |
| 887 | MockRead data_reads[] = { |
| 888 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 889 | MockRead("Content-Length: 10\r\n"), |
| 890 | MockRead("Content-Length: 10\r\n"), |
| 891 | MockRead("Content-Length: 5\r\n\r\n"), |
| 892 | }; |
| 893 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 894 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 895 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH)); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 896 | } |
| 897 | } |
| 898 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 899 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 900 | MultipleContentLengthHeadersTransferEncoding) { |
| 901 | MockRead data_reads[] = { |
| 902 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 903 | MockRead("Content-Length: 666\r\n"), |
| 904 | MockRead("Content-Length: 1337\r\n"), |
| 905 | MockRead("Transfer-Encoding: chunked\r\n\r\n"), |
| 906 | MockRead("5\r\nHello\r\n"), |
| 907 | MockRead("1\r\n"), |
| 908 | MockRead(" \r\n"), |
| 909 | MockRead("5\r\nworld\r\n"), |
| 910 | MockRead("0\r\n\r\nHTTP/1.1 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 911 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 912 | }; |
| 913 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 914 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 915 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 916 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 917 | EXPECT_EQ("Hello world", out.response_data); |
| 918 | } |
| 919 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 920 | // Next tests deal with http://crbug.com/98895. |
| 921 | |
| 922 | // Checks that a single Content-Disposition header results in no error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 923 | TEST_F(HttpNetworkTransactionTest, SingleContentDispositionHeader) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 924 | MockRead data_reads[] = { |
| 925 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 926 | MockRead("Content-Disposition: attachment;filename=\"salutations.txt\"r\n"), |
| 927 | MockRead("Content-Length: 5\r\n\r\n"), |
| 928 | MockRead("Hello"), |
| 929 | }; |
| 930 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 931 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 932 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 933 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 934 | EXPECT_EQ("Hello", out.response_data); |
| 935 | } |
| 936 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 937 | // Checks that two identical Content-Disposition headers result in no error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 938 | TEST_F(HttpNetworkTransactionTest, TwoIdenticalContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 939 | MockRead data_reads[] = { |
| 940 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 941 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 942 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 943 | MockRead("Content-Length: 5\r\n\r\n"), |
| 944 | MockRead("Hello"), |
| 945 | }; |
| 946 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 947 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 948 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 949 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 950 | EXPECT_EQ("Hello", out.response_data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 951 | } |
| 952 | |
| 953 | // Checks that two distinct Content-Disposition headers result in an error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 954 | TEST_F(HttpNetworkTransactionTest, TwoDistinctContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 955 | MockRead data_reads[] = { |
| 956 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 957 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 958 | MockRead("Content-Disposition: attachment;filename=\"hi.txt\"r\n"), |
| 959 | MockRead("Content-Length: 5\r\n\r\n"), |
| 960 | MockRead("Hello"), |
| 961 | }; |
| 962 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 963 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 964 | EXPECT_THAT(out.rv, |
| 965 | IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 966 | } |
| 967 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 968 | // Checks that two identical Location headers result in no error. |
| 969 | // Also tests Location header behavior. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 970 | TEST_F(HttpNetworkTransactionTest, TwoIdenticalLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 971 | MockRead data_reads[] = { |
| 972 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 973 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 974 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 975 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 976 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 977 | }; |
| 978 | |
| 979 | HttpRequestInfo request; |
| 980 | request.method = "GET"; |
| 981 | request.url = GURL("http://redirect.com/"); |
| 982 | request.load_flags = 0; |
| 983 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 984 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 985 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 986 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 987 | |
| 988 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 989 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 990 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 991 | TestCompletionCallback callback; |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 992 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 993 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 994 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 995 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 996 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 997 | |
| 998 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 999 | ASSERT_TRUE(response); |
| 1000 | ASSERT_TRUE(response->headers); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1001 | EXPECT_EQ("HTTP/1.1 302 Redirect", response->headers->GetStatusLine()); |
| 1002 | std::string url; |
| 1003 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 1004 | EXPECT_EQ("http://good.com/", url); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 1005 | EXPECT_TRUE(response->proxy_server.IsEmpty()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1006 | } |
| 1007 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1008 | // Checks that two distinct Location headers result in an error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1009 | TEST_F(HttpNetworkTransactionTest, TwoDistinctLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1010 | MockRead data_reads[] = { |
| 1011 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 1012 | MockRead("Location: http://good.com/\r\n"), |
| 1013 | MockRead("Location: http://evil.com/\r\n"), |
| 1014 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1015 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1016 | }; |
| 1017 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1018 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1019 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_LOCATION)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1020 | } |
| 1021 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1022 | // Do a request using the HEAD method. Verify that we don't try to read the |
| 1023 | // message body (since HEAD has none). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1024 | TEST_F(HttpNetworkTransactionTest, Head) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1025 | HttpRequestInfo request; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1026 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1027 | request.url = GURL("http://www.example.org/"); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1028 | request.load_flags = 0; |
| 1029 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1030 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1031 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1032 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1033 | BeforeHeadersSentHandler headers_handler; |
| 1034 | trans->SetBeforeHeadersSentCallback( |
| 1035 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 1036 | base::Unretained(&headers_handler))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1037 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1038 | MockWrite data_writes1[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 1039 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 1040 | "Host: www.example.org\r\n" |
| 1041 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1042 | }; |
| 1043 | MockRead data_reads1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 1044 | MockRead("HTTP/1.1 404 Not Found\r\n"), MockRead("Server: Blah\r\n"), |
| 1045 | MockRead("Content-Length: 1234\r\n\r\n"), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1046 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 1047 | // No response body because the test stops reading here. |
| 1048 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1049 | }; |
| 1050 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1051 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 1052 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1053 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1054 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1055 | TestCompletionCallback callback1; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1056 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1057 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1058 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1059 | |
| 1060 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1061 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1062 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1063 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1064 | ASSERT_TRUE(response); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1065 | |
| 1066 | // Check that the headers got parsed. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1067 | EXPECT_TRUE(response->headers); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1068 | EXPECT_EQ(1234, response->headers->GetContentLength()); |
| 1069 | EXPECT_EQ("HTTP/1.1 404 Not Found", response->headers->GetStatusLine()); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 1070 | EXPECT_TRUE(response->proxy_server.IsEmpty()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1071 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 1072 | EXPECT_FALSE(headers_handler.observed_before_headers_sent_with_proxy()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1073 | |
| 1074 | std::string server_header; |
olli.raula | ee489a5 | 2016-01-25 08:37:10 | [diff] [blame] | 1075 | size_t iter = 0; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1076 | bool has_server_header = response->headers->EnumerateHeader( |
| 1077 | &iter, "Server", &server_header); |
| 1078 | EXPECT_TRUE(has_server_header); |
| 1079 | EXPECT_EQ("Blah", server_header); |
| 1080 | |
| 1081 | // Reading should give EOF right away, since there is no message body |
| 1082 | // (despite non-zero content-length). |
| 1083 | std::string response_data; |
| 1084 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1085 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1086 | EXPECT_EQ("", response_data); |
| 1087 | } |
| 1088 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1089 | TEST_F(HttpNetworkTransactionTest, ReuseConnection) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1090 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1091 | |
| 1092 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1093 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1094 | MockRead("hello"), |
| 1095 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1096 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1097 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1098 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1099 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1100 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1101 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1102 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1103 | "hello", "world" |
| 1104 | }; |
| 1105 | |
| 1106 | for (int i = 0; i < 2; ++i) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1107 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1108 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1109 | request.url = GURL("http://www.example.org/"); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1110 | request.load_flags = 0; |
| 1111 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1112 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1113 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1114 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1115 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1116 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1117 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1118 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1119 | |
| 1120 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1121 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1122 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1123 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1124 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1125 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1126 | EXPECT_TRUE(response->headers); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1127 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 1128 | EXPECT_TRUE(response->proxy_server.IsEmpty()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1129 | |
| 1130 | std::string response_data; |
[email protected] | af4876d | 2008-10-21 23:10:57 | [diff] [blame] | 1131 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1132 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1133 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1134 | } |
| 1135 | } |
| 1136 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1137 | TEST_F(HttpNetworkTransactionTest, Ignores100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1138 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 1139 | element_readers.push_back( |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1140 | base::WrapUnique(new UploadBytesElementReader("foo", 3))); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 1141 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1142 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1143 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1144 | request.method = "POST"; |
| 1145 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1146 | request.upload_data_stream = &upload_data_stream; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1147 | request.load_flags = 0; |
| 1148 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1149 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1150 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1151 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1152 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1153 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1154 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 1155 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 1156 | MockRead("hello 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] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1162 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1163 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1164 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1165 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1166 | |
| 1167 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1168 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1169 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1170 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1171 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1172 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1173 | EXPECT_TRUE(response->headers); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1174 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1175 | |
| 1176 | std::string response_data; |
[email protected] | af4876d | 2008-10-21 23:10:57 | [diff] [blame] | 1177 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1178 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1179 | EXPECT_EQ("hello world", response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1180 | } |
| 1181 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1182 | // This test is almost the same as Ignores100 above, but the response contains |
| 1183 | // 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] | 1184 | // HTTP/1.1 and the two status headers are read in one read. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1185 | TEST_F(HttpNetworkTransactionTest, Ignores1xx) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1186 | HttpRequestInfo request; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1187 | request.method = "GET"; |
| 1188 | request.url = GURL("http://www.foo.com/"); |
| 1189 | request.load_flags = 0; |
| 1190 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1191 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1192 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1193 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1194 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1195 | MockRead data_reads[] = { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1196 | MockRead("HTTP/1.1 102 Unspecified status code\r\n\r\n" |
| 1197 | "HTTP/1.1 200 OK\r\n\r\n"), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1198 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1199 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1200 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1201 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1202 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1203 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1204 | TestCompletionCallback callback; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1205 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1206 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1207 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1208 | |
| 1209 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1210 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1211 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1212 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1213 | ASSERT_TRUE(response); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1214 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1215 | EXPECT_TRUE(response->headers); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1216 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1217 | |
| 1218 | std::string response_data; |
| 1219 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1220 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1221 | EXPECT_EQ("hello world", response_data); |
| 1222 | } |
| 1223 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1224 | TEST_F(HttpNetworkTransactionTest, Incomplete100ThenEOF) { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1225 | HttpRequestInfo request; |
| 1226 | request.method = "POST"; |
| 1227 | request.url = GURL("http://www.foo.com/"); |
| 1228 | request.load_flags = 0; |
| 1229 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1230 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1231 | std::unique_ptr<HttpTransaction> trans( |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1232 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 1233 | |
| 1234 | MockRead data_reads[] = { |
| 1235 | MockRead(SYNCHRONOUS, "HTTP/1.0 100 Continue\r\n"), |
| 1236 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1237 | }; |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1238 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 1239 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1240 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1241 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1242 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1243 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1244 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1245 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1246 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1247 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1248 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1249 | std::string response_data; |
| 1250 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1251 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1252 | EXPECT_EQ("", response_data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1253 | } |
| 1254 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1255 | TEST_F(HttpNetworkTransactionTest, EmptyResponse) { |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1256 | HttpRequestInfo request; |
| 1257 | request.method = "POST"; |
| 1258 | request.url = GURL("http://www.foo.com/"); |
| 1259 | request.load_flags = 0; |
| 1260 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1261 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1262 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1263 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1264 | |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1265 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1266 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1267 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1268 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1269 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1270 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1271 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1272 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1273 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1274 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1275 | |
| 1276 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1277 | EXPECT_THAT(rv, IsError(ERR_EMPTY_RESPONSE)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1278 | } |
| 1279 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1280 | void HttpNetworkTransactionTest::KeepAliveConnectionResendRequestTest( |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1281 | const MockWrite* write_failure, |
| 1282 | const MockRead* read_failure) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1283 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1284 | request.method = "GET"; |
| 1285 | request.url = GURL("http://www.foo.com/"); |
| 1286 | request.load_flags = 0; |
| 1287 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1288 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1289 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1290 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1291 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1292 | // Written data for successfully sending both requests. |
| 1293 | MockWrite data1_writes[] = { |
| 1294 | MockWrite("GET / HTTP/1.1\r\n" |
| 1295 | "Host: www.foo.com\r\n" |
| 1296 | "Connection: keep-alive\r\n\r\n"), |
| 1297 | MockWrite("GET / HTTP/1.1\r\n" |
| 1298 | "Host: www.foo.com\r\n" |
| 1299 | "Connection: keep-alive\r\n\r\n") |
| 1300 | }; |
| 1301 | |
| 1302 | // Read results for the first request. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1303 | MockRead data1_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1304 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1305 | MockRead("hello"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1306 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1307 | }; |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1308 | |
| 1309 | if (write_failure) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1310 | ASSERT_FALSE(read_failure); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1311 | data1_writes[1] = *write_failure; |
| 1312 | } else { |
| 1313 | ASSERT_TRUE(read_failure); |
| 1314 | data1_reads[2] = *read_failure; |
| 1315 | } |
| 1316 | |
| 1317 | StaticSocketDataProvider data1(data1_reads, arraysize(data1_reads), |
| 1318 | data1_writes, arraysize(data1_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1319 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1320 | |
| 1321 | MockRead data2_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1322 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1323 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1324 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1325 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1326 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1327 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1328 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 1329 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1330 | "hello", "world" |
| 1331 | }; |
| 1332 | |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 1333 | uint32_t first_socket_log_id = NetLog::Source::kInvalidId; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1334 | for (int i = 0; i < 2; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1335 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1336 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1337 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1338 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1339 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1340 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1341 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1342 | |
| 1343 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1344 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1345 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1346 | LoadTimingInfo load_timing_info; |
| 1347 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 1348 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1349 | if (i == 0) { |
| 1350 | first_socket_log_id = load_timing_info.socket_log_id; |
| 1351 | } else { |
| 1352 | // The second request should be using a new socket. |
| 1353 | EXPECT_NE(first_socket_log_id, load_timing_info.socket_log_id); |
| 1354 | } |
| 1355 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1356 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1357 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1358 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1359 | EXPECT_TRUE(response->headers); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1360 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1361 | |
| 1362 | std::string response_data; |
[email protected] | af4876d | 2008-10-21 23:10:57 | [diff] [blame] | 1363 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1364 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1365 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1366 | } |
| 1367 | } |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1368 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1369 | void HttpNetworkTransactionTest::PreconnectErrorResendRequestTest( |
| 1370 | const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1371 | const MockRead* read_failure, |
| 1372 | bool use_spdy) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1373 | HttpRequestInfo request; |
| 1374 | request.method = "GET"; |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1375 | request.url = GURL("https://www.foo.com/"); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1376 | request.load_flags = 0; |
| 1377 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1378 | TestNetLog net_log; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1379 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1380 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1381 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1382 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 1383 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 1384 | if (use_spdy) { |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 1385 | ssl1.next_proto = kProtoHTTP2; |
| 1386 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1387 | } |
| 1388 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 1389 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1390 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1391 | // SPDY versions of the request and response. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1392 | SpdySerializedFrame spdy_request(spdy_util_.ConstructSpdyGet( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 1393 | request.url.spec().c_str(), 1, DEFAULT_PRIORITY)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1394 | SpdySerializedFrame spdy_response( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 1395 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1396 | SpdySerializedFrame spdy_data( |
| 1397 | spdy_util_.ConstructSpdyDataFrame(1, "hello", 5, true)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1398 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1399 | // HTTP/1.1 versions of the request and response. |
| 1400 | const char kHttpRequest[] = "GET / HTTP/1.1\r\n" |
| 1401 | "Host: www.foo.com\r\n" |
| 1402 | "Connection: keep-alive\r\n\r\n"; |
| 1403 | const char kHttpResponse[] = "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"; |
| 1404 | const char kHttpData[] = "hello"; |
| 1405 | |
| 1406 | std::vector<MockRead> data1_reads; |
| 1407 | std::vector<MockWrite> data1_writes; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1408 | if (write_failure) { |
| 1409 | ASSERT_FALSE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1410 | data1_writes.push_back(*write_failure); |
| 1411 | data1_reads.push_back(MockRead(ASYNC, OK)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1412 | } else { |
| 1413 | ASSERT_TRUE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1414 | if (use_spdy) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1415 | data1_writes.push_back(CreateMockWrite(spdy_request)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1416 | } else { |
| 1417 | data1_writes.push_back(MockWrite(kHttpRequest)); |
| 1418 | } |
| 1419 | data1_reads.push_back(*read_failure); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1420 | } |
| 1421 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1422 | StaticSocketDataProvider data1(&data1_reads[0], data1_reads.size(), |
| 1423 | &data1_writes[0], data1_writes.size()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1424 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1425 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1426 | std::vector<MockRead> data2_reads; |
| 1427 | std::vector<MockWrite> data2_writes; |
| 1428 | |
| 1429 | if (use_spdy) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1430 | data2_writes.push_back(CreateMockWrite(spdy_request, 0, ASYNC)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1431 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1432 | data2_reads.push_back(CreateMockRead(spdy_response, 1, ASYNC)); |
| 1433 | data2_reads.push_back(CreateMockRead(spdy_data, 2, ASYNC)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1434 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1435 | } else { |
| 1436 | data2_writes.push_back( |
| 1437 | MockWrite(ASYNC, kHttpRequest, strlen(kHttpRequest), 0)); |
| 1438 | |
| 1439 | data2_reads.push_back( |
| 1440 | MockRead(ASYNC, kHttpResponse, strlen(kHttpResponse), 1)); |
| 1441 | data2_reads.push_back(MockRead(ASYNC, kHttpData, strlen(kHttpData), 2)); |
| 1442 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1443 | } |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 1444 | SequencedSocketData data2(&data2_reads[0], data2_reads.size(), |
| 1445 | &data2_writes[0], data2_writes.size()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1446 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1447 | |
| 1448 | // Preconnect a socket. |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 1449 | session->http_stream_factory()->PreconnectStreams(1, request); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1450 | // Wait for the preconnect to complete. |
| 1451 | // TODO(davidben): Some way to wait for an idle socket count might be handy. |
| 1452 | base::RunLoop().RunUntilIdle(); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1453 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1454 | |
| 1455 | // Make the request. |
| 1456 | TestCompletionCallback callback; |
| 1457 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1458 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1459 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 1460 | |
| 1461 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1462 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1463 | |
| 1464 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1465 | EXPECT_THAT(rv, IsOk()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1466 | |
| 1467 | LoadTimingInfo load_timing_info; |
| 1468 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1469 | TestLoadTimingNotReused( |
| 1470 | load_timing_info, |
| 1471 | CONNECT_TIMING_HAS_DNS_TIMES|CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1472 | |
| 1473 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1474 | ASSERT_TRUE(response); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1475 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1476 | EXPECT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1477 | if (response->was_fetched_via_spdy) { |
| 1478 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 1479 | } else { |
| 1480 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1481 | } |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1482 | |
| 1483 | std::string response_data; |
| 1484 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1485 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1486 | EXPECT_EQ(kHttpData, response_data); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1487 | } |
| 1488 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1489 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionNotConnectedOnWrite) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1490 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1491 | KeepAliveConnectionResendRequestTest(&write_failure, NULL); |
| 1492 | } |
| 1493 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1494 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionReset) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1495 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1496 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1497 | } |
| 1498 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1499 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionEOF) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1500 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1501 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1502 | } |
| 1503 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1504 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1505 | // if the socket was a reused keep alive socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1506 | TEST_F(HttpNetworkTransactionTest, KeepAlive408) { |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1507 | MockRead read_failure(SYNCHRONOUS, |
| 1508 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1509 | "Connection: Keep-Alive\r\n" |
| 1510 | "Content-Length: 6\r\n\r\n" |
| 1511 | "Pickle"); |
| 1512 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
| 1513 | } |
| 1514 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1515 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorNotConnectedOnWrite) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1516 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1517 | PreconnectErrorResendRequestTest(&write_failure, NULL, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1518 | } |
| 1519 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1520 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorReset) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1521 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1522 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1523 | } |
| 1524 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1525 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorEOF) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1526 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1527 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1528 | } |
| 1529 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1530 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorAsyncEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1531 | MockRead read_failure(ASYNC, OK); // EOF |
| 1532 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1533 | } |
| 1534 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1535 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1536 | // if the socket was a preconnected (UNUSED_IDLE) socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1537 | TEST_F(HttpNetworkTransactionTest, RetryOnIdle408) { |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1538 | MockRead read_failure(SYNCHRONOUS, |
| 1539 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1540 | "Connection: Keep-Alive\r\n" |
| 1541 | "Content-Length: 6\r\n\r\n" |
| 1542 | "Pickle"); |
| 1543 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
| 1544 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1545 | } |
| 1546 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1547 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorNotConnectedOnWrite) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1548 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
| 1549 | PreconnectErrorResendRequestTest(&write_failure, NULL, true); |
| 1550 | } |
| 1551 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1552 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorReset) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1553 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
| 1554 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
| 1555 | } |
| 1556 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1557 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1558 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
| 1559 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
| 1560 | } |
| 1561 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1562 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorAsyncEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1563 | MockRead read_failure(ASYNC, OK); // EOF |
| 1564 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1565 | } |
| 1566 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1567 | TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionReset) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1568 | HttpRequestInfo request; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1569 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1570 | request.url = GURL("http://www.example.org/"); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1571 | request.load_flags = 0; |
| 1572 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1573 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1574 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1575 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1576 | |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1577 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1578 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1579 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 1580 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1581 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1582 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1583 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1584 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1585 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1586 | TestCompletionCallback callback; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1587 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1588 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1589 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1590 | |
| 1591 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1592 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 1593 | |
| 1594 | IPEndPoint endpoint; |
| 1595 | EXPECT_TRUE(trans->GetRemoteEndpoint(&endpoint)); |
| 1596 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1597 | } |
| 1598 | |
| 1599 | // What do various browsers do when the server closes a non-keepalive |
| 1600 | // connection without sending any response header or body? |
| 1601 | // |
| 1602 | // IE7: error page |
| 1603 | // Safari 3.1.2 (Windows): error page |
| 1604 | // Firefox 3.0.1: blank page |
| 1605 | // Opera 9.52: after five attempts, blank page |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1606 | // Us with WinHTTP: error page (ERR_INVALID_RESPONSE) |
| 1607 | // Us: error page (EMPTY_RESPONSE) |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1608 | TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionEOF) { |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1609 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1610 | MockRead(SYNCHRONOUS, OK), // EOF |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1611 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 1612 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1613 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1614 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1615 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1616 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1617 | EXPECT_THAT(out.rv, IsError(ERR_EMPTY_RESPONSE)); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1618 | } |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1619 | |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1620 | // Next 2 cases (KeepAliveEarlyClose and KeepAliveEarlyClose2) are regression |
| 1621 | // tests. There was a bug causing HttpNetworkTransaction to hang in the |
| 1622 | // destructor in such situations. |
| 1623 | // See http://crbug.com/154712 and http://crbug.com/156609. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1624 | TEST_F(HttpNetworkTransactionTest, KeepAliveEarlyClose) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1625 | HttpRequestInfo request; |
| 1626 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1627 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1628 | request.load_flags = 0; |
| 1629 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1630 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1631 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1632 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1633 | |
| 1634 | MockRead data_reads[] = { |
| 1635 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1636 | MockRead("Connection: keep-alive\r\n"), |
| 1637 | MockRead("Content-Length: 100\r\n\r\n"), |
| 1638 | MockRead("hello"), |
| 1639 | MockRead(SYNCHRONOUS, 0), |
| 1640 | }; |
| 1641 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1642 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1643 | |
| 1644 | TestCompletionCallback callback; |
| 1645 | |
| 1646 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1647 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1648 | |
| 1649 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1650 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1651 | |
| 1652 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1653 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1654 | if (rv == ERR_IO_PENDING) |
| 1655 | rv = callback.WaitForResult(); |
| 1656 | EXPECT_EQ(5, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1657 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1658 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1659 | |
| 1660 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 1661 | base::RunLoop().RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1662 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 1663 | } |
| 1664 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1665 | TEST_F(HttpNetworkTransactionTest, KeepAliveEarlyClose2) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1666 | HttpRequestInfo request; |
| 1667 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1668 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1669 | request.load_flags = 0; |
| 1670 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1671 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1672 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1673 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1674 | |
| 1675 | MockRead data_reads[] = { |
| 1676 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1677 | MockRead("Connection: keep-alive\r\n"), |
| 1678 | MockRead("Content-Length: 100\r\n\r\n"), |
| 1679 | MockRead(SYNCHRONOUS, 0), |
| 1680 | }; |
| 1681 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1682 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1683 | |
| 1684 | TestCompletionCallback callback; |
| 1685 | |
| 1686 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1687 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1688 | |
| 1689 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1690 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1691 | |
| 1692 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1693 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1694 | if (rv == ERR_IO_PENDING) |
| 1695 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1696 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1697 | |
| 1698 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 1699 | base::RunLoop().RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1700 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 1701 | } |
| 1702 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1703 | // Test that we correctly reuse a keep-alive connection after not explicitly |
| 1704 | // reading the body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1705 | TEST_F(HttpNetworkTransactionTest, KeepAliveAfterUnreadBody) { |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1706 | HttpRequestInfo request; |
| 1707 | request.method = "GET"; |
| 1708 | request.url = GURL("http://www.foo.com/"); |
| 1709 | request.load_flags = 0; |
| 1710 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1711 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1712 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1713 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1714 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1715 | const char* request_data = |
| 1716 | "GET / HTTP/1.1\r\n" |
| 1717 | "Host: www.foo.com\r\n" |
| 1718 | "Connection: keep-alive\r\n\r\n"; |
| 1719 | MockWrite data_writes[] = { |
| 1720 | MockWrite(ASYNC, 0, request_data), MockWrite(ASYNC, 2, request_data), |
| 1721 | MockWrite(ASYNC, 4, request_data), MockWrite(ASYNC, 6, request_data), |
| 1722 | MockWrite(ASYNC, 8, request_data), MockWrite(ASYNC, 10, request_data), |
| 1723 | MockWrite(ASYNC, 12, request_data), MockWrite(ASYNC, 14, request_data), |
| 1724 | MockWrite(ASYNC, 17, request_data), MockWrite(ASYNC, 20, request_data), |
| 1725 | }; |
| 1726 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1727 | // Note that because all these reads happen in the same |
| 1728 | // StaticSocketDataProvider, it shows that the same socket is being reused for |
| 1729 | // all transactions. |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1730 | MockRead data_reads[] = { |
| 1731 | MockRead(ASYNC, 1, "HTTP/1.1 204 No Content\r\n\r\n"), |
| 1732 | MockRead(ASYNC, 3, "HTTP/1.1 205 Reset Content\r\n\r\n"), |
| 1733 | MockRead(ASYNC, 5, "HTTP/1.1 304 Not Modified\r\n\r\n"), |
| 1734 | MockRead(ASYNC, 7, |
| 1735 | "HTTP/1.1 302 Found\r\n" |
| 1736 | "Content-Length: 0\r\n\r\n"), |
| 1737 | MockRead(ASYNC, 9, |
| 1738 | "HTTP/1.1 302 Found\r\n" |
| 1739 | "Content-Length: 5\r\n\r\n" |
| 1740 | "hello"), |
| 1741 | MockRead(ASYNC, 11, |
| 1742 | "HTTP/1.1 301 Moved Permanently\r\n" |
| 1743 | "Content-Length: 0\r\n\r\n"), |
| 1744 | MockRead(ASYNC, 13, |
| 1745 | "HTTP/1.1 301 Moved Permanently\r\n" |
| 1746 | "Content-Length: 5\r\n\r\n" |
| 1747 | "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1748 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1749 | // In the next two rounds, IsConnectedAndIdle returns false, due to |
| 1750 | // the set_busy_before_sync_reads(true) call, while the |
| 1751 | // HttpNetworkTransaction is being shut down, but the socket is still |
| 1752 | // reuseable. See http://crbug.com/544255. |
| 1753 | MockRead(ASYNC, 15, |
| 1754 | "HTTP/1.1 200 Hunky-Dory\r\n" |
| 1755 | "Content-Length: 5\r\n\r\n"), |
| 1756 | MockRead(SYNCHRONOUS, 16, "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1757 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1758 | MockRead(ASYNC, 18, |
| 1759 | "HTTP/1.1 200 Hunky-Dory\r\n" |
| 1760 | "Content-Length: 5\r\n\r\n" |
| 1761 | "he"), |
| 1762 | MockRead(SYNCHRONOUS, 19, "llo"), |
| 1763 | |
| 1764 | // The body of the final request is actually read. |
| 1765 | MockRead(ASYNC, 21, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1766 | MockRead(ASYNC, 22, "hello"), |
| 1767 | }; |
| 1768 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 1769 | arraysize(data_writes)); |
| 1770 | data.set_busy_before_sync_reads(true); |
| 1771 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 1772 | |
| 1773 | const int kNumUnreadBodies = arraysize(data_writes) - 1; |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1774 | std::string response_lines[kNumUnreadBodies]; |
| 1775 | |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 1776 | uint32_t first_socket_log_id = NetLog::Source::kInvalidId; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1777 | for (size_t i = 0; i < kNumUnreadBodies; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1778 | TestCompletionCallback callback; |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1779 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1780 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1781 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1782 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1783 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1784 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1785 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1786 | LoadTimingInfo load_timing_info; |
| 1787 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 1788 | if (i == 0) { |
| 1789 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1790 | first_socket_log_id = load_timing_info.socket_log_id; |
| 1791 | } else { |
| 1792 | TestLoadTimingReused(load_timing_info); |
| 1793 | EXPECT_EQ(first_socket_log_id, load_timing_info.socket_log_id); |
| 1794 | } |
| 1795 | |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1796 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1797 | ASSERT_TRUE(response); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1798 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1799 | ASSERT_TRUE(response->headers); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1800 | response_lines[i] = response->headers->GetStatusLine(); |
| 1801 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1802 | // Delete the transaction without reading the response bodies. Then spin |
| 1803 | // the message loop, so the response bodies are drained. |
| 1804 | trans.reset(); |
| 1805 | base::RunLoop().RunUntilIdle(); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1806 | } |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1807 | |
| 1808 | const char* const kStatusLines[] = { |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1809 | "HTTP/1.1 204 No Content", |
| 1810 | "HTTP/1.1 205 Reset Content", |
| 1811 | "HTTP/1.1 304 Not Modified", |
| 1812 | "HTTP/1.1 302 Found", |
| 1813 | "HTTP/1.1 302 Found", |
| 1814 | "HTTP/1.1 301 Moved Permanently", |
| 1815 | "HTTP/1.1 301 Moved Permanently", |
| 1816 | "HTTP/1.1 200 Hunky-Dory", |
| 1817 | "HTTP/1.1 200 Hunky-Dory", |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1818 | }; |
| 1819 | |
mostynb | 91e0da98 | 2015-01-20 19:17:27 | [diff] [blame] | 1820 | static_assert(kNumUnreadBodies == arraysize(kStatusLines), |
| 1821 | "forgot to update kStatusLines"); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1822 | |
| 1823 | for (int i = 0; i < kNumUnreadBodies; ++i) |
| 1824 | EXPECT_EQ(kStatusLines[i], response_lines[i]); |
| 1825 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1826 | TestCompletionCallback callback; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1827 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1828 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1829 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1830 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1831 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1832 | ASSERT_TRUE(response); |
| 1833 | ASSERT_TRUE(response->headers); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1834 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1835 | std::string response_data; |
| 1836 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1837 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1838 | EXPECT_EQ("hello", response_data); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1839 | } |
| 1840 | |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 1841 | // Sockets that receive extra data after a response is complete should not be |
| 1842 | // reused. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1843 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData1) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 1844 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1845 | MockWrite data_writes1[] = { |
| 1846 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 1847 | "Host: www.borked.com\r\n" |
| 1848 | "Connection: keep-alive\r\n\r\n"), |
| 1849 | }; |
| 1850 | |
| 1851 | MockRead data_reads1[] = { |
| 1852 | MockRead("HTTP/1.1 200 OK\r\n" |
| 1853 | "Connection: keep-alive\r\n" |
| 1854 | "Content-Length: 22\r\n\r\n" |
| 1855 | "This server is borked."), |
| 1856 | }; |
| 1857 | |
| 1858 | MockWrite data_writes2[] = { |
| 1859 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 1860 | "Host: www.borked.com\r\n" |
| 1861 | "Connection: keep-alive\r\n\r\n"), |
| 1862 | }; |
| 1863 | |
| 1864 | MockRead data_reads2[] = { |
| 1865 | MockRead("HTTP/1.1 200 OK\r\n" |
| 1866 | "Content-Length: 3\r\n\r\n" |
| 1867 | "foo"), |
| 1868 | }; |
| 1869 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 1870 | data_writes1, arraysize(data_writes1)); |
| 1871 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1872 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 1873 | data_writes2, arraysize(data_writes2)); |
| 1874 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1875 | |
| 1876 | TestCompletionCallback callback; |
| 1877 | HttpRequestInfo request1; |
| 1878 | request1.method = "HEAD"; |
| 1879 | request1.url = GURL("http://www.borked.com/"); |
| 1880 | |
| 1881 | std::unique_ptr<HttpTransaction> trans1( |
| 1882 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 1883 | int rv = trans1->Start(&request1, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1884 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 1885 | |
| 1886 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 1887 | ASSERT_TRUE(response1); |
| 1888 | ASSERT_TRUE(response1->headers); |
| 1889 | EXPECT_EQ(200, response1->headers->response_code()); |
| 1890 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 1891 | |
| 1892 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1893 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 1894 | EXPECT_EQ("", response_data1); |
| 1895 | // Deleting the transaction attempts to release the socket back into the |
| 1896 | // socket pool. |
| 1897 | trans1.reset(); |
| 1898 | |
| 1899 | HttpRequestInfo request2; |
| 1900 | request2.method = "GET"; |
| 1901 | request2.url = GURL("http://www.borked.com/foo"); |
| 1902 | |
| 1903 | std::unique_ptr<HttpTransaction> trans2( |
| 1904 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 1905 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1906 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 1907 | |
| 1908 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 1909 | ASSERT_TRUE(response2); |
| 1910 | ASSERT_TRUE(response2->headers); |
| 1911 | EXPECT_EQ(200, response2->headers->response_code()); |
| 1912 | |
| 1913 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1914 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 1915 | EXPECT_EQ("foo", response_data2); |
| 1916 | } |
| 1917 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1918 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData2) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 1919 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1920 | MockWrite data_writes1[] = { |
| 1921 | MockWrite("GET / HTTP/1.1\r\n" |
| 1922 | "Host: www.borked.com\r\n" |
| 1923 | "Connection: keep-alive\r\n\r\n"), |
| 1924 | }; |
| 1925 | |
| 1926 | MockRead data_reads1[] = { |
| 1927 | MockRead("HTTP/1.1 200 OK\r\n" |
| 1928 | "Connection: keep-alive\r\n" |
| 1929 | "Content-Length: 22\r\n\r\n" |
| 1930 | "This server is borked." |
| 1931 | "Bonus data!"), |
| 1932 | }; |
| 1933 | |
| 1934 | MockWrite data_writes2[] = { |
| 1935 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 1936 | "Host: www.borked.com\r\n" |
| 1937 | "Connection: keep-alive\r\n\r\n"), |
| 1938 | }; |
| 1939 | |
| 1940 | MockRead data_reads2[] = { |
| 1941 | MockRead("HTTP/1.1 200 OK\r\n" |
| 1942 | "Content-Length: 3\r\n\r\n" |
| 1943 | "foo"), |
| 1944 | }; |
| 1945 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 1946 | data_writes1, arraysize(data_writes1)); |
| 1947 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1948 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 1949 | data_writes2, arraysize(data_writes2)); |
| 1950 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1951 | |
| 1952 | TestCompletionCallback callback; |
| 1953 | HttpRequestInfo request1; |
| 1954 | request1.method = "GET"; |
| 1955 | request1.url = GURL("http://www.borked.com/"); |
| 1956 | |
| 1957 | std::unique_ptr<HttpTransaction> trans1( |
| 1958 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 1959 | int rv = trans1->Start(&request1, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1960 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 1961 | |
| 1962 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 1963 | ASSERT_TRUE(response1); |
| 1964 | ASSERT_TRUE(response1->headers); |
| 1965 | EXPECT_EQ(200, response1->headers->response_code()); |
| 1966 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 1967 | |
| 1968 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1969 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 1970 | EXPECT_EQ("This server is borked.", response_data1); |
| 1971 | // Deleting the transaction attempts to release the socket back into the |
| 1972 | // socket pool. |
| 1973 | trans1.reset(); |
| 1974 | |
| 1975 | HttpRequestInfo request2; |
| 1976 | request2.method = "GET"; |
| 1977 | request2.url = GURL("http://www.borked.com/foo"); |
| 1978 | |
| 1979 | std::unique_ptr<HttpTransaction> trans2( |
| 1980 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 1981 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1982 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 1983 | |
| 1984 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 1985 | ASSERT_TRUE(response2); |
| 1986 | ASSERT_TRUE(response2->headers); |
| 1987 | EXPECT_EQ(200, response2->headers->response_code()); |
| 1988 | |
| 1989 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1990 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 1991 | EXPECT_EQ("foo", response_data2); |
| 1992 | } |
| 1993 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1994 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData3) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 1995 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1996 | MockWrite data_writes1[] = { |
| 1997 | MockWrite("GET / HTTP/1.1\r\n" |
| 1998 | "Host: www.borked.com\r\n" |
| 1999 | "Connection: keep-alive\r\n\r\n"), |
| 2000 | }; |
| 2001 | |
| 2002 | MockRead data_reads1[] = { |
| 2003 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2004 | "Connection: keep-alive\r\n" |
| 2005 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 2006 | MockRead("16\r\nThis server is borked.\r\n"), |
| 2007 | MockRead("0\r\n\r\nBonus data!"), |
| 2008 | }; |
| 2009 | |
| 2010 | MockWrite data_writes2[] = { |
| 2011 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2012 | "Host: www.borked.com\r\n" |
| 2013 | "Connection: keep-alive\r\n\r\n"), |
| 2014 | }; |
| 2015 | |
| 2016 | MockRead data_reads2[] = { |
| 2017 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2018 | "Content-Length: 3\r\n\r\n" |
| 2019 | "foo"), |
| 2020 | }; |
| 2021 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2022 | data_writes1, arraysize(data_writes1)); |
| 2023 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2024 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2025 | data_writes2, arraysize(data_writes2)); |
| 2026 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2027 | |
| 2028 | TestCompletionCallback callback; |
| 2029 | HttpRequestInfo request1; |
| 2030 | request1.method = "GET"; |
| 2031 | request1.url = GURL("http://www.borked.com/"); |
| 2032 | |
| 2033 | std::unique_ptr<HttpTransaction> trans1( |
| 2034 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 2035 | int rv = trans1->Start(&request1, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2036 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2037 | |
| 2038 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2039 | ASSERT_TRUE(response1); |
| 2040 | ASSERT_TRUE(response1->headers); |
| 2041 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2042 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2043 | |
| 2044 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2045 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2046 | EXPECT_EQ("This server is borked.", response_data1); |
| 2047 | // Deleting the transaction attempts to release the socket back into the |
| 2048 | // socket pool. |
| 2049 | trans1.reset(); |
| 2050 | |
| 2051 | HttpRequestInfo request2; |
| 2052 | request2.method = "GET"; |
| 2053 | request2.url = GURL("http://www.borked.com/foo"); |
| 2054 | |
| 2055 | std::unique_ptr<HttpTransaction> trans2( |
| 2056 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 2057 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2058 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2059 | |
| 2060 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2061 | ASSERT_TRUE(response2); |
| 2062 | ASSERT_TRUE(response2->headers); |
| 2063 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2064 | |
| 2065 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2066 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2067 | EXPECT_EQ("foo", response_data2); |
| 2068 | } |
| 2069 | |
| 2070 | // This is a little different from the others - it tests the case that the |
| 2071 | // HttpStreamParser doesn't know if there's extra data on a socket or not when |
| 2072 | // the HttpNetworkTransaction is torn down, because the response body hasn't |
| 2073 | // been read from yet, but the request goes through the HttpResponseBodyDrainer. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2074 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData4) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2075 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2076 | MockWrite data_writes1[] = { |
| 2077 | MockWrite("GET / HTTP/1.1\r\n" |
| 2078 | "Host: www.borked.com\r\n" |
| 2079 | "Connection: keep-alive\r\n\r\n"), |
| 2080 | }; |
| 2081 | |
| 2082 | MockRead data_reads1[] = { |
| 2083 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2084 | "Connection: keep-alive\r\n" |
| 2085 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 2086 | MockRead("16\r\nThis server is borked.\r\n"), |
| 2087 | MockRead("0\r\n\r\nBonus data!"), |
| 2088 | }; |
| 2089 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2090 | data_writes1, arraysize(data_writes1)); |
| 2091 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2092 | |
| 2093 | TestCompletionCallback callback; |
| 2094 | HttpRequestInfo request1; |
| 2095 | request1.method = "GET"; |
| 2096 | request1.url = GURL("http://www.borked.com/"); |
| 2097 | |
| 2098 | std::unique_ptr<HttpTransaction> trans1( |
| 2099 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 2100 | int rv = trans1->Start(&request1, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2101 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2102 | |
| 2103 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2104 | ASSERT_TRUE(response1); |
| 2105 | ASSERT_TRUE(response1->headers); |
| 2106 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2107 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2108 | |
| 2109 | // Deleting the transaction creates an HttpResponseBodyDrainer to read the |
| 2110 | // response body. |
| 2111 | trans1.reset(); |
| 2112 | |
| 2113 | // Let the HttpResponseBodyDrainer drain the socket. It should determine the |
| 2114 | // socket can't be reused, rather than returning it to the socket pool. |
| 2115 | base::RunLoop().RunUntilIdle(); |
| 2116 | |
| 2117 | // There should be no idle sockets in the pool. |
| 2118 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 2119 | } |
| 2120 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2121 | // Test the request-challenge-retry sequence for basic auth. |
| 2122 | // (basic auth is the easiest to mock, because it has no randomness). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2123 | TEST_F(HttpNetworkTransactionTest, BasicAuth) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2124 | HttpRequestInfo request; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2125 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2126 | request.url = GURL("http://www.example.org/"); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2127 | request.load_flags = 0; |
| 2128 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2129 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2130 | session_deps_.net_log = &log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2131 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2132 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 2133 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2134 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2135 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2136 | MockWrite( |
| 2137 | "GET / HTTP/1.1\r\n" |
| 2138 | "Host: www.example.org\r\n" |
| 2139 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2140 | }; |
| 2141 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2142 | MockRead data_reads1[] = { |
| 2143 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2144 | // Give a couple authenticate options (only the middle one is actually |
| 2145 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 2146 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2147 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2148 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2149 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2150 | // Large content-length -- won't matter, as connection will be reset. |
| 2151 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2152 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2153 | }; |
| 2154 | |
| 2155 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2156 | // be issuing -- the final header line contains the credentials. |
| 2157 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2158 | MockWrite( |
| 2159 | "GET / HTTP/1.1\r\n" |
| 2160 | "Host: www.example.org\r\n" |
| 2161 | "Connection: keep-alive\r\n" |
| 2162 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2163 | }; |
| 2164 | |
| 2165 | // Lastly, the server responds with the actual content. |
| 2166 | MockRead data_reads2[] = { |
| 2167 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2168 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2169 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2170 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2171 | }; |
| 2172 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2173 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2174 | data_writes1, arraysize(data_writes1)); |
| 2175 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2176 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2177 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2178 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2179 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2180 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2181 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2182 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2183 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2184 | |
| 2185 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2186 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2187 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2188 | LoadTimingInfo load_timing_info1; |
| 2189 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info1)); |
| 2190 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2191 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2192 | int64_t writes_size1 = CountWriteBytes(data_writes1, arraysize(data_writes1)); |
| 2193 | EXPECT_EQ(writes_size1, trans->GetTotalSentBytes()); |
| 2194 | int64_t reads_size1 = CountReadBytes(data_reads1, arraysize(data_reads1)); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2195 | EXPECT_EQ(reads_size1, trans->GetTotalReceivedBytes()); |
| 2196 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2197 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2198 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2199 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2200 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2201 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2202 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2203 | rv = trans->RestartWithAuth( |
| 2204 | AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2205 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2206 | |
| 2207 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2208 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2209 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2210 | LoadTimingInfo load_timing_info2; |
| 2211 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info2)); |
| 2212 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2213 | // The load timing after restart should have a new socket ID, and times after |
| 2214 | // those of the first load timing. |
| 2215 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2216 | load_timing_info2.connect_timing.connect_start); |
| 2217 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2218 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2219 | int64_t writes_size2 = CountWriteBytes(data_writes2, arraysize(data_writes2)); |
| 2220 | EXPECT_EQ(writes_size1 + writes_size2, trans->GetTotalSentBytes()); |
| 2221 | int64_t reads_size2 = CountReadBytes(data_reads2, arraysize(data_reads2)); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2222 | EXPECT_EQ(reads_size1 + reads_size2, trans->GetTotalReceivedBytes()); |
| 2223 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2224 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2225 | ASSERT_TRUE(response); |
| 2226 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2227 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2228 | } |
| 2229 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2230 | // Test the request-challenge-retry sequence for basic auth. |
| 2231 | // (basic auth is the easiest to mock, because it has no randomness). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2232 | TEST_F(HttpNetworkTransactionTest, BasicAuthWithAddressChange) { |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2233 | HttpRequestInfo request; |
| 2234 | request.method = "GET"; |
| 2235 | request.url = GURL("http://www.example.org/"); |
| 2236 | request.load_flags = 0; |
| 2237 | |
| 2238 | TestNetLog log; |
| 2239 | MockHostResolver* resolver = new MockHostResolver(); |
| 2240 | session_deps_.net_log = &log; |
| 2241 | session_deps_.host_resolver.reset(resolver); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2242 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 2243 | std::unique_ptr<HttpTransaction> trans( |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2244 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 2245 | |
| 2246 | resolver->rules()->ClearRules(); |
| 2247 | resolver->rules()->AddRule("www.example.org", "127.0.0.1"); |
| 2248 | |
| 2249 | MockWrite data_writes1[] = { |
| 2250 | MockWrite("GET / HTTP/1.1\r\n" |
| 2251 | "Host: www.example.org\r\n" |
| 2252 | "Connection: keep-alive\r\n\r\n"), |
| 2253 | }; |
| 2254 | |
| 2255 | MockRead data_reads1[] = { |
| 2256 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2257 | // Give a couple authenticate options (only the middle one is actually |
| 2258 | // supported). |
| 2259 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 2260 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2261 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2262 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2263 | // Large content-length -- won't matter, as connection will be reset. |
| 2264 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 2265 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 2266 | }; |
| 2267 | |
| 2268 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2269 | // be issuing -- the final header line contains the credentials. |
| 2270 | MockWrite data_writes2[] = { |
| 2271 | MockWrite("GET / HTTP/1.1\r\n" |
| 2272 | "Host: www.example.org\r\n" |
| 2273 | "Connection: keep-alive\r\n" |
| 2274 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2275 | }; |
| 2276 | |
| 2277 | // Lastly, the server responds with the actual content. |
| 2278 | MockRead data_reads2[] = { |
| 2279 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2280 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2281 | MockRead("Content-Length: 100\r\n\r\n"), MockRead(SYNCHRONOUS, OK), |
| 2282 | }; |
| 2283 | |
| 2284 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2285 | data_writes1, arraysize(data_writes1)); |
| 2286 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2287 | data_writes2, arraysize(data_writes2)); |
| 2288 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2289 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2290 | |
| 2291 | TestCompletionCallback callback1; |
| 2292 | |
| 2293 | EXPECT_EQ(OK, callback1.GetResult(trans->Start(&request, callback1.callback(), |
| 2294 | BoundNetLog()))); |
| 2295 | |
| 2296 | LoadTimingInfo load_timing_info1; |
| 2297 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info1)); |
| 2298 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2299 | |
| 2300 | int64_t writes_size1 = CountWriteBytes(data_writes1, arraysize(data_writes1)); |
| 2301 | EXPECT_EQ(writes_size1, trans->GetTotalSentBytes()); |
| 2302 | int64_t reads_size1 = CountReadBytes(data_reads1, arraysize(data_reads1)); |
| 2303 | EXPECT_EQ(reads_size1, trans->GetTotalReceivedBytes()); |
| 2304 | |
| 2305 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 2306 | ASSERT_TRUE(response); |
| 2307 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 2308 | |
| 2309 | IPEndPoint endpoint; |
| 2310 | EXPECT_TRUE(trans->GetRemoteEndpoint(&endpoint)); |
| 2311 | ASSERT_FALSE(endpoint.address().empty()); |
| 2312 | EXPECT_EQ("127.0.0.1:80", endpoint.ToString()); |
| 2313 | |
| 2314 | resolver->rules()->ClearRules(); |
| 2315 | resolver->rules()->AddRule("www.example.org", "127.0.0.2"); |
| 2316 | |
| 2317 | TestCompletionCallback callback2; |
| 2318 | |
| 2319 | EXPECT_EQ(OK, callback2.GetResult(trans->RestartWithAuth( |
| 2320 | AuthCredentials(kFoo, kBar), callback2.callback()))); |
| 2321 | |
| 2322 | LoadTimingInfo load_timing_info2; |
| 2323 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info2)); |
| 2324 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2325 | // The load timing after restart should have a new socket ID, and times after |
| 2326 | // those of the first load timing. |
| 2327 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2328 | load_timing_info2.connect_timing.connect_start); |
| 2329 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2330 | |
| 2331 | int64_t writes_size2 = CountWriteBytes(data_writes2, arraysize(data_writes2)); |
| 2332 | EXPECT_EQ(writes_size1 + writes_size2, trans->GetTotalSentBytes()); |
| 2333 | int64_t reads_size2 = CountReadBytes(data_reads2, arraysize(data_reads2)); |
| 2334 | EXPECT_EQ(reads_size1 + reads_size2, trans->GetTotalReceivedBytes()); |
| 2335 | |
| 2336 | response = trans->GetResponseInfo(); |
| 2337 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2338 | EXPECT_FALSE(response->auth_challenge); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2339 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 2340 | |
| 2341 | EXPECT_TRUE(trans->GetRemoteEndpoint(&endpoint)); |
| 2342 | ASSERT_FALSE(endpoint.address().empty()); |
| 2343 | EXPECT_EQ("127.0.0.2:80", endpoint.ToString()); |
| 2344 | } |
| 2345 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2346 | TEST_F(HttpNetworkTransactionTest, DoNotSendAuth) { |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2347 | HttpRequestInfo request; |
| 2348 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2349 | request.url = GURL("http://www.example.org/"); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2350 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2351 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2352 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2353 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 2354 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2355 | |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2356 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2357 | MockWrite( |
| 2358 | "GET / HTTP/1.1\r\n" |
| 2359 | "Host: www.example.org\r\n" |
| 2360 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2361 | }; |
| 2362 | |
| 2363 | MockRead data_reads[] = { |
| 2364 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2365 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2366 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2367 | // Large content-length -- won't matter, as connection will be reset. |
| 2368 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2369 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2370 | }; |
| 2371 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2372 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 2373 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2374 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2375 | TestCompletionCallback callback; |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2376 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2377 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2378 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2379 | |
| 2380 | rv = callback.WaitForResult(); |
| 2381 | EXPECT_EQ(0, rv); |
| 2382 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2383 | int64_t writes_size = CountWriteBytes(data_writes, arraysize(data_writes)); |
| 2384 | EXPECT_EQ(writes_size, trans->GetTotalSentBytes()); |
| 2385 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2386 | EXPECT_EQ(reads_size, trans->GetTotalReceivedBytes()); |
| 2387 | |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2388 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2389 | ASSERT_TRUE(response); |
| 2390 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2391 | } |
| 2392 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2393 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2394 | // connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2395 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAlive) { |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2396 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 2397 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 2398 | // reused. See http://crbug.com/544255. |
| 2399 | for (int i = 0; i < 2; ++i) { |
| 2400 | HttpRequestInfo request; |
| 2401 | request.method = "GET"; |
| 2402 | request.url = GURL("http://www.example.org/"); |
| 2403 | request.load_flags = 0; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2404 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2405 | TestNetLog log; |
| 2406 | session_deps_.net_log = &log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2407 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2408 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2409 | MockWrite data_writes[] = { |
| 2410 | MockWrite(ASYNC, 0, |
| 2411 | "GET / HTTP/1.1\r\n" |
| 2412 | "Host: www.example.org\r\n" |
| 2413 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2414 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2415 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2416 | // be issuing -- the final header line contains the credentials. |
| 2417 | MockWrite(ASYNC, 6, |
| 2418 | "GET / HTTP/1.1\r\n" |
| 2419 | "Host: www.example.org\r\n" |
| 2420 | "Connection: keep-alive\r\n" |
| 2421 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2422 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2423 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2424 | MockRead data_reads[] = { |
| 2425 | MockRead(ASYNC, 1, "HTTP/1.1 401 Unauthorized\r\n"), |
| 2426 | MockRead(ASYNC, 2, "WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2427 | MockRead(ASYNC, 3, "Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2428 | MockRead(ASYNC, 4, "Content-Length: 14\r\n\r\n"), |
| 2429 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 5, "Unauthorized\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2430 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2431 | // Lastly, the server responds with the actual content. |
| 2432 | MockRead(ASYNC, 7, "HTTP/1.1 200 OK\r\n"), |
| 2433 | MockRead(ASYNC, 8, "Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2434 | MockRead(ASYNC, 9, "Content-Length: 5\r\n\r\n"), |
| 2435 | MockRead(ASYNC, 10, "Hello"), |
| 2436 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2437 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2438 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 2439 | arraysize(data_writes)); |
| 2440 | data.set_busy_before_sync_reads(true); |
| 2441 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2442 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2443 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2444 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2445 | std::unique_ptr<HttpTransaction> trans( |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2446 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 2447 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2448 | ASSERT_THAT(callback1.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2449 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2450 | LoadTimingInfo load_timing_info1; |
| 2451 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info1)); |
| 2452 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2453 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2454 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 2455 | ASSERT_TRUE(response); |
| 2456 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2457 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2458 | TestCompletionCallback callback2; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2459 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2460 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 2461 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2462 | ASSERT_THAT(callback2.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2463 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2464 | LoadTimingInfo load_timing_info2; |
| 2465 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info2)); |
| 2466 | TestLoadTimingReused(load_timing_info2); |
| 2467 | // The load timing after restart should have the same socket ID, and times |
| 2468 | // those of the first load timing. |
| 2469 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2470 | load_timing_info2.send_start); |
| 2471 | 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] | 2472 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2473 | response = trans->GetResponseInfo(); |
| 2474 | ASSERT_TRUE(response); |
| 2475 | EXPECT_FALSE(response->auth_challenge); |
| 2476 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2477 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2478 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2479 | EXPECT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2480 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2481 | int64_t writes_size = CountWriteBytes(data_writes, arraysize(data_writes)); |
| 2482 | EXPECT_EQ(writes_size, trans->GetTotalSentBytes()); |
| 2483 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 2484 | EXPECT_EQ(reads_size, trans->GetTotalReceivedBytes()); |
| 2485 | } |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2486 | } |
| 2487 | |
| 2488 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2489 | // connection and with no response body to drain. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2490 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2491 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2492 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2493 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2494 | request.load_flags = 0; |
| 2495 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2496 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2497 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2498 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2499 | MockWrite( |
| 2500 | "GET / HTTP/1.1\r\n" |
| 2501 | "Host: www.example.org\r\n" |
| 2502 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2503 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2504 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2505 | // be issuing -- the final header line contains the credentials. |
| 2506 | MockWrite( |
| 2507 | "GET / HTTP/1.1\r\n" |
| 2508 | "Host: www.example.org\r\n" |
| 2509 | "Connection: keep-alive\r\n" |
| 2510 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2511 | }; |
| 2512 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2513 | MockRead data_reads1[] = { |
| 2514 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2515 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2516 | MockRead("Content-Length: 0\r\n\r\n"), // No response body. |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2517 | |
| 2518 | // Lastly, the server responds with the actual content. |
| 2519 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2520 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2521 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2522 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2523 | }; |
| 2524 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2525 | // An incorrect reconnect would cause this to be read. |
| 2526 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2527 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2528 | }; |
| 2529 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2530 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2531 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2532 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2533 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2534 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2535 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2536 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2537 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2538 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2539 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2540 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2541 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2542 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2543 | |
| 2544 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2545 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2546 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2547 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2548 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2549 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2550 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2551 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2552 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2553 | rv = trans->RestartWithAuth( |
| 2554 | AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2555 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2556 | |
| 2557 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2558 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2559 | |
| 2560 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2561 | ASSERT_TRUE(response); |
| 2562 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2563 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2564 | } |
| 2565 | |
| 2566 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2567 | // connection and with a large response body to drain. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2568 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveLargeBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2569 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2570 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2571 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2572 | request.load_flags = 0; |
| 2573 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2574 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2575 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2576 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2577 | MockWrite( |
| 2578 | "GET / HTTP/1.1\r\n" |
| 2579 | "Host: www.example.org\r\n" |
| 2580 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2581 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2582 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2583 | // be issuing -- the final header line contains the credentials. |
| 2584 | MockWrite( |
| 2585 | "GET / HTTP/1.1\r\n" |
| 2586 | "Host: www.example.org\r\n" |
| 2587 | "Connection: keep-alive\r\n" |
| 2588 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2589 | }; |
| 2590 | |
| 2591 | // Respond with 5 kb of response body. |
| 2592 | std::string large_body_string("Unauthorized"); |
| 2593 | large_body_string.append(5 * 1024, ' '); |
| 2594 | large_body_string.append("\r\n"); |
| 2595 | |
| 2596 | MockRead data_reads1[] = { |
| 2597 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2598 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2599 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2600 | // 5134 = 12 + 5 * 1024 + 2 |
| 2601 | MockRead("Content-Length: 5134\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2602 | MockRead(ASYNC, large_body_string.data(), large_body_string.size()), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2603 | |
| 2604 | // Lastly, the server responds with the actual content. |
| 2605 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2606 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2607 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2608 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2609 | }; |
| 2610 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2611 | // An incorrect reconnect would cause this to be read. |
| 2612 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2613 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2614 | }; |
| 2615 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2616 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2617 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2618 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2619 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2620 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2621 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2622 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2623 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2624 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2625 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2626 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2627 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2628 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2629 | |
| 2630 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2631 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2632 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2633 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2634 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2635 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2636 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2637 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2638 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2639 | rv = trans->RestartWithAuth( |
| 2640 | AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2641 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2642 | |
| 2643 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2644 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2645 | |
| 2646 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2647 | ASSERT_TRUE(response); |
| 2648 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2649 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2650 | } |
| 2651 | |
| 2652 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2653 | // connection, but the server gets impatient and closes the connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2654 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveImpatientServer) { |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2655 | HttpRequestInfo request; |
| 2656 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2657 | request.url = GURL("http://www.example.org/"); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2658 | request.load_flags = 0; |
| 2659 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2660 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2661 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2662 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2663 | MockWrite( |
| 2664 | "GET / HTTP/1.1\r\n" |
| 2665 | "Host: www.example.org\r\n" |
| 2666 | "Connection: keep-alive\r\n\r\n"), |
| 2667 | // This simulates the seemingly successful write to a closed connection |
| 2668 | // if the bug is not fixed. |
| 2669 | MockWrite( |
| 2670 | "GET / HTTP/1.1\r\n" |
| 2671 | "Host: www.example.org\r\n" |
| 2672 | "Connection: keep-alive\r\n" |
| 2673 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2674 | }; |
| 2675 | |
| 2676 | MockRead data_reads1[] = { |
| 2677 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2678 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2679 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2680 | MockRead("Content-Length: 14\r\n\r\n"), |
| 2681 | // Tell MockTCPClientSocket to simulate the server closing the connection. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2682 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2683 | MockRead("Unauthorized\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2684 | MockRead(SYNCHRONOUS, OK), // The server closes the connection. |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2685 | }; |
| 2686 | |
| 2687 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2688 | // be issuing -- the final header line contains the credentials. |
| 2689 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2690 | MockWrite( |
| 2691 | "GET / HTTP/1.1\r\n" |
| 2692 | "Host: www.example.org\r\n" |
| 2693 | "Connection: keep-alive\r\n" |
| 2694 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2695 | }; |
| 2696 | |
| 2697 | // Lastly, the server responds with the actual content. |
| 2698 | MockRead data_reads2[] = { |
| 2699 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2700 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2701 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2702 | MockRead("hello"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2703 | }; |
| 2704 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2705 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2706 | data_writes1, arraysize(data_writes1)); |
| 2707 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2708 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2709 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2710 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2711 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2712 | TestCompletionCallback callback1; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2713 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2714 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2715 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2716 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2717 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2718 | |
| 2719 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2720 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2721 | |
| 2722 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2723 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2724 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2725 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2726 | TestCompletionCallback callback2; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2727 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2728 | rv = trans->RestartWithAuth( |
| 2729 | AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2730 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2731 | |
| 2732 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2733 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2734 | |
| 2735 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2736 | ASSERT_TRUE(response); |
| 2737 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2738 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2739 | } |
| 2740 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2741 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 2742 | // that requires a restart when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2743 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp10) { |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2744 | HttpRequestInfo request; |
| 2745 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2746 | request.url = GURL("https://www.example.org/"); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2747 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2748 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2749 | |
| 2750 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 2751 | session_deps_.proxy_service = |
| 2752 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2753 | BoundTestNetLog log; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2754 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2755 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2756 | |
| 2757 | // Since we have proxy, should try to establish tunnel. |
| 2758 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2759 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 2760 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2761 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2762 | }; |
| 2763 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2764 | // The proxy responds to the connect with a 407, using a non-persistent |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2765 | // connection. |
| 2766 | MockRead data_reads1[] = { |
| 2767 | // No credentials. |
| 2768 | MockRead("HTTP/1.0 407 Proxy Authentication Required\r\n"), |
| 2769 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n\r\n"), |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2770 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2771 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2772 | // Since the first connection couldn't be reused, need to establish another |
| 2773 | // once given credentials. |
| 2774 | MockWrite data_writes2[] = { |
| 2775 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2776 | // be issuing -- the final header line contains the credentials. |
| 2777 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 2778 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2779 | "Proxy-Connection: keep-alive\r\n" |
| 2780 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2781 | |
| 2782 | MockWrite("GET / HTTP/1.1\r\n" |
| 2783 | "Host: www.example.org\r\n" |
| 2784 | "Connection: keep-alive\r\n\r\n"), |
| 2785 | }; |
| 2786 | |
| 2787 | MockRead data_reads2[] = { |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2788 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 2789 | |
| 2790 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2791 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2792 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2793 | MockRead(SYNCHRONOUS, "hello"), |
| 2794 | }; |
| 2795 | |
| 2796 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2797 | data_writes1, arraysize(data_writes1)); |
| 2798 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2799 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2800 | data_writes2, arraysize(data_writes2)); |
| 2801 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2802 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 2803 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 2804 | |
| 2805 | TestCompletionCallback callback1; |
| 2806 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2807 | std::unique_ptr<HttpTransaction> trans( |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2808 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 2809 | |
| 2810 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2811 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2812 | |
| 2813 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2814 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 2815 | TestNetLogEntry::List entries; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2816 | log.GetEntries(&entries); |
| 2817 | size_t pos = ExpectLogContainsSomewhere( |
| 2818 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 2819 | NetLog::PHASE_NONE); |
| 2820 | ExpectLogContainsSomewhere( |
| 2821 | entries, pos, NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 2822 | NetLog::PHASE_NONE); |
| 2823 | |
| 2824 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2825 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2826 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2827 | ASSERT_TRUE(response->headers); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2828 | EXPECT_EQ(407, response->headers->response_code()); |
| 2829 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 2830 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 2831 | |
| 2832 | LoadTimingInfo load_timing_info; |
| 2833 | // CONNECT requests and responses are handled at the connect job level, so |
| 2834 | // the transaction does not yet have a connection. |
| 2835 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2836 | |
| 2837 | TestCompletionCallback callback2; |
| 2838 | |
| 2839 | rv = |
| 2840 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2841 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2842 | |
| 2843 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2844 | EXPECT_THAT(rv, IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2845 | |
| 2846 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2847 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2848 | |
| 2849 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2850 | EXPECT_EQ(200, response->headers->response_code()); |
| 2851 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 2852 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 2853 | |
| 2854 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2855 | EXPECT_FALSE(response->auth_challenge); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2856 | |
| 2857 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2858 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 2859 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 2860 | |
| 2861 | trans.reset(); |
| 2862 | session->CloseAllConnections(); |
| 2863 | } |
| 2864 | |
| 2865 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 2866 | // that requires a restart when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2867 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp11) { |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2868 | HttpRequestInfo request; |
| 2869 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2870 | request.url = GURL("https://www.example.org/"); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2871 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2872 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2873 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2874 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 2875 | session_deps_.proxy_service = |
| 2876 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2877 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2878 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2879 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2880 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2881 | // Since we have proxy, should try to establish tunnel. |
| 2882 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2883 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 2884 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2885 | "Proxy-Connection: keep-alive\r\n\r\n"), |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 2886 | }; |
| 2887 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2888 | // The proxy responds to the connect with a 407, using a non-persistent |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 2889 | // connection. |
| 2890 | MockRead data_reads1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2891 | // No credentials. |
| 2892 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 2893 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2894 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 2895 | }; |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 2896 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2897 | MockWrite data_writes2[] = { |
| 2898 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2899 | // be issuing -- the final header line contains the credentials. |
| 2900 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 2901 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2902 | "Proxy-Connection: keep-alive\r\n" |
| 2903 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 2904 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2905 | MockWrite("GET / HTTP/1.1\r\n" |
| 2906 | "Host: www.example.org\r\n" |
| 2907 | "Connection: keep-alive\r\n\r\n"), |
| 2908 | }; |
| 2909 | |
| 2910 | MockRead data_reads2[] = { |
| 2911 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 2912 | |
| 2913 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2914 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2915 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2916 | MockRead(SYNCHRONOUS, "hello"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2917 | }; |
| 2918 | |
| 2919 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2920 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2921 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2922 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2923 | data_writes2, arraysize(data_writes2)); |
| 2924 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2925 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2926 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2927 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2928 | TestCompletionCallback callback1; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2929 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2930 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2931 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2932 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2933 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2934 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2935 | |
| 2936 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2937 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 2938 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2939 | log.GetEntries(&entries); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2940 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2941 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2942 | NetLog::PHASE_NONE); |
| 2943 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2944 | entries, pos, |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2945 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 2946 | NetLog::PHASE_NONE); |
| 2947 | |
| 2948 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2949 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2950 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2951 | ASSERT_TRUE(response->headers); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2952 | EXPECT_EQ(407, response->headers->response_code()); |
| 2953 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2954 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2955 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2956 | LoadTimingInfo load_timing_info; |
| 2957 | // CONNECT requests and responses are handled at the connect job level, so |
| 2958 | // the transaction does not yet have a connection. |
| 2959 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2960 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2961 | TestCompletionCallback callback2; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2962 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2963 | rv = trans->RestartWithAuth( |
| 2964 | AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2965 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2966 | |
| 2967 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2968 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2969 | |
| 2970 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2971 | ASSERT_TRUE(response); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2972 | |
| 2973 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2974 | EXPECT_EQ(200, response->headers->response_code()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2975 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2976 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 2977 | |
| 2978 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2979 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2980 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2981 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2982 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 2983 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 2984 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2985 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 2986 | session->CloseAllConnections(); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2987 | } |
| 2988 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2989 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2990 | // proxy connection with HTTP/1.0 responses, when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2991 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp10) { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 2992 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 2993 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 2994 | // reused. See http://crbug.com/544255. |
| 2995 | for (int i = 0; i < 2; ++i) { |
| 2996 | HttpRequestInfo request; |
| 2997 | request.method = "GET"; |
| 2998 | request.url = GURL("https://www.example.org/"); |
| 2999 | // Ensure that proxy authentication is attempted even |
| 3000 | // when the no authentication data flag is set. |
| 3001 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3002 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3003 | // Configure against proxy server "myproxy:70". |
| 3004 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
| 3005 | BoundTestNetLog log; |
| 3006 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3007 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3008 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3009 | std::unique_ptr<HttpTransaction> trans( |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3010 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3011 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3012 | // Since we have proxy, should try to establish tunnel. |
| 3013 | MockWrite data_writes1[] = { |
| 3014 | MockWrite(ASYNC, 0, |
| 3015 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3016 | "Host: www.example.org:443\r\n" |
| 3017 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3018 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3019 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3020 | // be issuing -- the final header line contains the credentials. |
| 3021 | MockWrite(ASYNC, 3, |
| 3022 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3023 | "Host: www.example.org:443\r\n" |
| 3024 | "Proxy-Connection: keep-alive\r\n" |
| 3025 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 3026 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3027 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3028 | // The proxy responds to the connect with a 407, using a persistent |
| 3029 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 3030 | MockRead data_reads1[] = { |
| 3031 | // No credentials. |
| 3032 | MockRead(ASYNC, 1, |
| 3033 | "HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 3034 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3035 | "Proxy-Connection: keep-alive\r\n" |
| 3036 | "Content-Length: 10\r\n\r\n"), |
| 3037 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 2, "0123456789"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3038 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3039 | // Wrong credentials (wrong password). |
| 3040 | MockRead(ASYNC, 4, |
| 3041 | "HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 3042 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3043 | "Proxy-Connection: keep-alive\r\n" |
| 3044 | "Content-Length: 10\r\n\r\n"), |
| 3045 | // No response body because the test stops reading here. |
| 3046 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 5), |
| 3047 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3048 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3049 | SequencedSocketData data1(data_reads1, arraysize(data_reads1), data_writes1, |
| 3050 | arraysize(data_writes1)); |
| 3051 | data1.set_busy_before_sync_reads(true); |
| 3052 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3053 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3054 | TestCompletionCallback callback1; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3055 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3056 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3057 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3058 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3059 | TestNetLogEntry::List entries; |
| 3060 | log.GetEntries(&entries); |
| 3061 | size_t pos = ExpectLogContainsSomewhere( |
| 3062 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3063 | NetLog::PHASE_NONE); |
| 3064 | ExpectLogContainsSomewhere( |
| 3065 | entries, pos, |
| 3066 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3067 | NetLog::PHASE_NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3068 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3069 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3070 | ASSERT_TRUE(response); |
| 3071 | ASSERT_TRUE(response->headers); |
| 3072 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3073 | EXPECT_EQ(407, response->headers->response_code()); |
| 3074 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3075 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 3076 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3077 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3078 | TestCompletionCallback callback2; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3079 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3080 | // Wrong password (should be "bar"). |
| 3081 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBaz), |
| 3082 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3083 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3084 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3085 | response = trans->GetResponseInfo(); |
| 3086 | ASSERT_TRUE(response); |
| 3087 | ASSERT_TRUE(response->headers); |
| 3088 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3089 | EXPECT_EQ(407, response->headers->response_code()); |
| 3090 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3091 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 3092 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3093 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3094 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 3095 | // out of scope. |
| 3096 | session->CloseAllConnections(); |
| 3097 | } |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3098 | } |
| 3099 | |
| 3100 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3101 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3102 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp11) { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3103 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 3104 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 3105 | // reused. See http://crbug.com/544255. |
| 3106 | for (int i = 0; i < 2; ++i) { |
| 3107 | HttpRequestInfo request; |
| 3108 | request.method = "GET"; |
| 3109 | request.url = GURL("https://www.example.org/"); |
| 3110 | // Ensure that proxy authentication is attempted even |
| 3111 | // when the no authentication data flag is set. |
| 3112 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
| 3113 | |
| 3114 | // Configure against proxy server "myproxy:70". |
| 3115 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
| 3116 | BoundTestNetLog log; |
| 3117 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3118 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3119 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3120 | std::unique_ptr<HttpTransaction> trans( |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3121 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 3122 | |
| 3123 | // Since we have proxy, should try to establish tunnel. |
| 3124 | MockWrite data_writes1[] = { |
| 3125 | MockWrite(ASYNC, 0, |
| 3126 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3127 | "Host: www.example.org:443\r\n" |
| 3128 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3129 | |
| 3130 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3131 | // be issuing -- the final header line contains the credentials. |
| 3132 | MockWrite(ASYNC, 3, |
| 3133 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3134 | "Host: www.example.org:443\r\n" |
| 3135 | "Proxy-Connection: keep-alive\r\n" |
| 3136 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 3137 | }; |
| 3138 | |
| 3139 | // The proxy responds to the connect with a 407, using a persistent |
| 3140 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 3141 | MockRead data_reads1[] = { |
| 3142 | // No credentials. |
| 3143 | MockRead(ASYNC, 1, |
| 3144 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3145 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3146 | "Content-Length: 10\r\n\r\n"), |
| 3147 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 2, "0123456789"), |
| 3148 | |
| 3149 | // Wrong credentials (wrong password). |
| 3150 | MockRead(ASYNC, 4, |
| 3151 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3152 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3153 | "Content-Length: 10\r\n\r\n"), |
| 3154 | // No response body because the test stops reading here. |
| 3155 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 5), |
| 3156 | }; |
| 3157 | |
| 3158 | SequencedSocketData data1(data_reads1, arraysize(data_reads1), data_writes1, |
| 3159 | arraysize(data_writes1)); |
| 3160 | data1.set_busy_before_sync_reads(true); |
| 3161 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3162 | |
| 3163 | TestCompletionCallback callback1; |
| 3164 | |
| 3165 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3166 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3167 | |
| 3168 | TestNetLogEntry::List entries; |
| 3169 | log.GetEntries(&entries); |
| 3170 | size_t pos = ExpectLogContainsSomewhere( |
| 3171 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3172 | NetLog::PHASE_NONE); |
| 3173 | ExpectLogContainsSomewhere( |
| 3174 | entries, pos, |
| 3175 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3176 | NetLog::PHASE_NONE); |
| 3177 | |
| 3178 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3179 | ASSERT_TRUE(response); |
| 3180 | ASSERT_TRUE(response->headers); |
| 3181 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3182 | EXPECT_EQ(407, response->headers->response_code()); |
| 3183 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3184 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3185 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3186 | |
| 3187 | TestCompletionCallback callback2; |
| 3188 | |
| 3189 | // Wrong password (should be "bar"). |
| 3190 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBaz), |
| 3191 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3192 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3193 | |
| 3194 | response = trans->GetResponseInfo(); |
| 3195 | ASSERT_TRUE(response); |
| 3196 | ASSERT_TRUE(response->headers); |
| 3197 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3198 | EXPECT_EQ(407, response->headers->response_code()); |
| 3199 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3200 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3201 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3202 | |
| 3203 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 3204 | // out of scope. |
| 3205 | session->CloseAllConnections(); |
| 3206 | } |
| 3207 | } |
| 3208 | |
| 3209 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3210 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel, in |
| 3211 | // the case the server sends extra data on the original socket, so it can't be |
| 3212 | // reused. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3213 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveExtraData) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3214 | HttpRequestInfo request; |
| 3215 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3216 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3217 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3218 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3219 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3220 | // Configure against proxy server "myproxy:70". |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3221 | session_deps_.proxy_service = |
| 3222 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3223 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3224 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3225 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3226 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3227 | // Since we have proxy, should try to establish tunnel. |
| 3228 | MockWrite data_writes1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3229 | MockWrite(ASYNC, 0, |
| 3230 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3231 | "Host: www.example.org:443\r\n" |
| 3232 | "Proxy-Connection: keep-alive\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3233 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3234 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3235 | // The proxy responds to the connect with a 407, using a persistent, but sends |
| 3236 | // extra data, so the socket cannot be reused. |
| 3237 | MockRead data_reads1[] = { |
| 3238 | // No credentials. |
| 3239 | MockRead(ASYNC, 1, |
| 3240 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3241 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3242 | "Content-Length: 10\r\n\r\n"), |
| 3243 | MockRead(SYNCHRONOUS, 2, "0123456789"), |
| 3244 | MockRead(SYNCHRONOUS, 3, "I'm broken!"), |
| 3245 | }; |
| 3246 | |
| 3247 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3248 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3249 | // be issuing -- the final header line contains the credentials. |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3250 | MockWrite(ASYNC, 0, |
| 3251 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3252 | "Host: www.example.org:443\r\n" |
| 3253 | "Proxy-Connection: keep-alive\r\n" |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3254 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3255 | |
| 3256 | MockWrite(ASYNC, 2, |
| 3257 | "GET / HTTP/1.1\r\n" |
| 3258 | "Host: www.example.org\r\n" |
| 3259 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3260 | }; |
| 3261 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3262 | MockRead data_reads2[] = { |
| 3263 | MockRead(ASYNC, 1, "HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3264 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3265 | MockRead(ASYNC, 3, |
| 3266 | "HTTP/1.1 200 OK\r\n" |
| 3267 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 3268 | "Content-Length: 5\r\n\r\n"), |
| 3269 | // No response body because the test stops reading here. |
| 3270 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 4), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3271 | }; |
| 3272 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3273 | SequencedSocketData data1(data_reads1, arraysize(data_reads1), data_writes1, |
| 3274 | arraysize(data_writes1)); |
| 3275 | data1.set_busy_before_sync_reads(true); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3276 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3277 | SequencedSocketData data2(data_reads2, arraysize(data_reads2), data_writes2, |
| 3278 | arraysize(data_writes2)); |
| 3279 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3280 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3281 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3282 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3283 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3284 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3285 | std::unique_ptr<HttpTransaction> trans( |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3286 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3287 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3288 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3289 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3290 | |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3291 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3292 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 3293 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3294 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 3295 | NetLog::PHASE_NONE); |
| 3296 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3297 | entries, pos, |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 3298 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3299 | NetLog::PHASE_NONE); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3300 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3301 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3302 | ASSERT_TRUE(response); |
| 3303 | ASSERT_TRUE(response->headers); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3304 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3305 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3306 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3307 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3308 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3309 | LoadTimingInfo load_timing_info; |
| 3310 | // CONNECT requests and responses are handled at the connect job level, so |
| 3311 | // the transaction does not yet have a connection. |
| 3312 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3313 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3314 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3315 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3316 | rv = |
| 3317 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3318 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3319 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3320 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3321 | EXPECT_EQ(200, response->headers->response_code()); |
| 3322 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3323 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 3324 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3325 | // The password prompt info should not be set. |
| 3326 | EXPECT_FALSE(response->auth_challenge); |
| 3327 | |
| 3328 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3329 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3330 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3331 | |
| 3332 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3333 | session->CloseAllConnections(); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3334 | } |
| 3335 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3336 | // Test the case a proxy closes a socket while the challenge body is being |
| 3337 | // drained. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3338 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHangupDuringBody) { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3339 | HttpRequestInfo request; |
| 3340 | request.method = "GET"; |
| 3341 | request.url = GURL("https://www.example.org/"); |
| 3342 | // Ensure that proxy authentication is attempted even |
| 3343 | // when the no authentication data flag is set. |
| 3344 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
| 3345 | |
| 3346 | // Configure against proxy server "myproxy:70". |
| 3347 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3348 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3349 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3350 | std::unique_ptr<HttpTransaction> trans( |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3351 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 3352 | |
| 3353 | // Since we have proxy, should try to establish tunnel. |
| 3354 | MockWrite data_writes1[] = { |
| 3355 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3356 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3357 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3358 | }; |
| 3359 | |
| 3360 | // The proxy responds to the connect with a 407, using a persistent |
| 3361 | // connection. |
| 3362 | MockRead data_reads1[] = { |
| 3363 | // No credentials. |
| 3364 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3365 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3366 | MockRead("Content-Length: 10\r\n\r\n"), MockRead("spam!"), |
| 3367 | // Server hands up in the middle of the body. |
| 3368 | MockRead(ASYNC, ERR_CONNECTION_CLOSED), |
| 3369 | }; |
| 3370 | |
| 3371 | MockWrite data_writes2[] = { |
| 3372 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3373 | // be issuing -- the final header line contains the credentials. |
| 3374 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3375 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3376 | "Proxy-Connection: keep-alive\r\n" |
| 3377 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3378 | |
| 3379 | MockWrite("GET / HTTP/1.1\r\n" |
| 3380 | "Host: www.example.org\r\n" |
| 3381 | "Connection: keep-alive\r\n\r\n"), |
| 3382 | }; |
| 3383 | |
| 3384 | MockRead data_reads2[] = { |
| 3385 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3386 | |
| 3387 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3388 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3389 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3390 | MockRead(SYNCHRONOUS, "hello"), |
| 3391 | }; |
| 3392 | |
| 3393 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3394 | data_writes1, arraysize(data_writes1)); |
| 3395 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3396 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3397 | data_writes2, arraysize(data_writes2)); |
| 3398 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3399 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3400 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3401 | |
| 3402 | TestCompletionCallback callback; |
| 3403 | |
| 3404 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3405 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3406 | |
| 3407 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3408 | ASSERT_TRUE(response); |
| 3409 | ASSERT_TRUE(response->headers); |
| 3410 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3411 | EXPECT_EQ(407, response->headers->response_code()); |
| 3412 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3413 | |
| 3414 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3415 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3416 | |
| 3417 | response = trans->GetResponseInfo(); |
| 3418 | ASSERT_TRUE(response); |
| 3419 | ASSERT_TRUE(response->headers); |
| 3420 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3421 | EXPECT_EQ(200, response->headers->response_code()); |
| 3422 | std::string body; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3423 | EXPECT_THAT(ReadTransaction(trans.get(), &body), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3424 | EXPECT_EQ("hello", body); |
| 3425 | } |
| 3426 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3427 | // Test that we don't read the response body when we fail to establish a tunnel, |
| 3428 | // even if the user cancels the proxy's auth attempt. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3429 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyCancelTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3430 | HttpRequestInfo request; |
| 3431 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3432 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3433 | request.load_flags = 0; |
| 3434 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3435 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3436 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3437 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3438 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3439 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3440 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3441 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3442 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3443 | // Since we have proxy, should try to establish tunnel. |
| 3444 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3445 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3446 | "Host: www.example.org:443\r\n" |
| 3447 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3448 | }; |
| 3449 | |
| 3450 | // The proxy responds to the connect with a 407. |
| 3451 | MockRead data_reads[] = { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3452 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3453 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3454 | MockRead("Content-Length: 10\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3455 | MockRead("0123456789"), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3456 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3457 | }; |
| 3458 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 3459 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 3460 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3461 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3462 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3463 | TestCompletionCallback callback; |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3464 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3465 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3466 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3467 | |
| 3468 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3469 | EXPECT_THAT(rv, IsOk()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3470 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3471 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3472 | ASSERT_TRUE(response); |
| 3473 | ASSERT_TRUE(response->headers); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3474 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3475 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3476 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3477 | |
| 3478 | std::string response_data; |
| 3479 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3480 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 3481 | |
| 3482 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3483 | session->CloseAllConnections(); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3484 | } |
| 3485 | |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3486 | // Test that we don't pass extraneous headers from the proxy's response to the |
| 3487 | // caller when the proxy responds to CONNECT with 407. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3488 | TEST_F(HttpNetworkTransactionTest, SanitizeProxyAuthHeaders) { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3489 | HttpRequestInfo request; |
| 3490 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3491 | request.url = GURL("https://www.example.org/"); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3492 | request.load_flags = 0; |
| 3493 | |
| 3494 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3495 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3496 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3497 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3498 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3499 | std::unique_ptr<HttpTransaction> trans( |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3500 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 3501 | |
| 3502 | // Since we have proxy, should try to establish tunnel. |
| 3503 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3504 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3505 | "Host: www.example.org:443\r\n" |
| 3506 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3507 | }; |
| 3508 | |
| 3509 | // The proxy responds to the connect with a 407. |
| 3510 | MockRead data_reads[] = { |
| 3511 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3512 | MockRead("X-Foo: bar\r\n"), |
| 3513 | MockRead("Set-Cookie: foo=bar\r\n"), |
| 3514 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3515 | MockRead("Content-Length: 10\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3516 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3517 | }; |
| 3518 | |
| 3519 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 3520 | arraysize(data_writes)); |
| 3521 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 3522 | |
| 3523 | TestCompletionCallback callback; |
| 3524 | |
| 3525 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3526 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3527 | |
| 3528 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3529 | EXPECT_THAT(rv, IsOk()); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3530 | |
| 3531 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3532 | ASSERT_TRUE(response); |
| 3533 | ASSERT_TRUE(response->headers); |
| 3534 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3535 | EXPECT_EQ(407, response->headers->response_code()); |
| 3536 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3537 | EXPECT_FALSE(response->headers->HasHeader("X-Foo")); |
| 3538 | EXPECT_FALSE(response->headers->HasHeader("Set-Cookie")); |
| 3539 | |
| 3540 | std::string response_data; |
| 3541 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3542 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3543 | |
| 3544 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
| 3545 | session->CloseAllConnections(); |
| 3546 | } |
| 3547 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3548 | // Test when a server (non-proxy) returns a 407 (proxy-authenticate). |
| 3549 | // The request should fail with ERR_UNEXPECTED_PROXY_AUTH. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3550 | TEST_F(HttpNetworkTransactionTest, UnexpectedProxyAuth) { |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3551 | HttpRequestInfo request; |
| 3552 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3553 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3554 | request.load_flags = 0; |
| 3555 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3556 | // We are using a DIRECT connection (i.e. no proxy) for this session. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3557 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 3558 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 3559 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3560 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3561 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3562 | MockWrite( |
| 3563 | "GET / HTTP/1.1\r\n" |
| 3564 | "Host: www.example.org\r\n" |
| 3565 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3566 | }; |
| 3567 | |
| 3568 | MockRead data_reads1[] = { |
| 3569 | MockRead("HTTP/1.0 407 Proxy Auth required\r\n"), |
| 3570 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3571 | // Large content-length -- won't matter, as connection will be reset. |
| 3572 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3573 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3574 | }; |
| 3575 | |
| 3576 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3577 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3578 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3579 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3580 | TestCompletionCallback callback; |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3581 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3582 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3583 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3584 | |
| 3585 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3586 | EXPECT_THAT(rv, IsError(ERR_UNEXPECTED_PROXY_AUTH)); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3587 | } |
| 3588 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3589 | // Tests when an HTTPS server (non-proxy) returns a 407 (proxy-authentication) |
| 3590 | // through a non-authenticating proxy. The request should fail with |
| 3591 | // ERR_UNEXPECTED_PROXY_AUTH. |
| 3592 | // Note that it is impossible to detect if an HTTP server returns a 407 through |
| 3593 | // a non-authenticating proxy - there is nothing to indicate whether the |
| 3594 | // response came from the proxy or the server, so it is treated as if the proxy |
| 3595 | // issued the challenge. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3596 | TEST_F(HttpNetworkTransactionTest, HttpsServerRequestsProxyAuthThroughProxy) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3597 | HttpRequestInfo request; |
| 3598 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3599 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3600 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3601 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3602 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3603 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3604 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3605 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3606 | // Since we have proxy, should try to establish tunnel. |
| 3607 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3608 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3609 | "Host: www.example.org:443\r\n" |
| 3610 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3611 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3612 | MockWrite("GET / HTTP/1.1\r\n" |
| 3613 | "Host: www.example.org\r\n" |
| 3614 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3615 | }; |
| 3616 | |
| 3617 | MockRead data_reads1[] = { |
| 3618 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3619 | |
| 3620 | MockRead("HTTP/1.1 407 Unauthorized\r\n"), |
| 3621 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3622 | MockRead("\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3623 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3624 | }; |
| 3625 | |
| 3626 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3627 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3628 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3629 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3630 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3631 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3632 | TestCompletionCallback callback1; |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3633 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3634 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3635 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3636 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3637 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3638 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3639 | |
| 3640 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3641 | EXPECT_THAT(rv, IsError(ERR_UNEXPECTED_PROXY_AUTH)); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3642 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3643 | log.GetEntries(&entries); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3644 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3645 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3646 | NetLog::PHASE_NONE); |
| 3647 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3648 | entries, pos, |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3649 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3650 | NetLog::PHASE_NONE); |
| 3651 | } |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3652 | |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3653 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 3654 | // that uses non-persistent connections. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3655 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3656 | AuthAllowsDefaultCredentialsTunnelConnectionClose) { |
| 3657 | HttpRequestInfo request; |
| 3658 | request.method = "GET"; |
| 3659 | request.url = GURL("https://www.example.org/"); |
| 3660 | |
| 3661 | // Configure against proxy server "myproxy:70". |
| 3662 | session_deps_.proxy_service = |
| 3663 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 3664 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3665 | std::unique_ptr<HttpAuthHandlerMock::Factory> auth_handler_factory( |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3666 | new HttpAuthHandlerMock::Factory()); |
| 3667 | auth_handler_factory->set_do_init_from_challenge(true); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3668 | std::unique_ptr<HttpAuthHandlerMock> mock_handler(new HttpAuthHandlerMock()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3669 | mock_handler->set_allows_default_credentials(true); |
| 3670 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 3671 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 3672 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3673 | |
| 3674 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 3675 | NetLog net_log; |
| 3676 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3677 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3678 | |
| 3679 | // Since we have proxy, should try to establish tunnel. |
| 3680 | MockWrite data_writes1[] = { |
| 3681 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3682 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3683 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3684 | }; |
| 3685 | |
| 3686 | // The proxy responds to the connect with a 407, using a non-persistent |
| 3687 | // connection. |
| 3688 | MockRead data_reads1[] = { |
| 3689 | // No credentials. |
| 3690 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3691 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 3692 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 3693 | }; |
| 3694 | |
| 3695 | // Since the first connection couldn't be reused, need to establish another |
| 3696 | // once given credentials. |
| 3697 | MockWrite data_writes2[] = { |
| 3698 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3699 | // be issuing -- the final header line contains the credentials. |
| 3700 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3701 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3702 | "Proxy-Connection: keep-alive\r\n" |
| 3703 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 3704 | |
| 3705 | MockWrite("GET / HTTP/1.1\r\n" |
| 3706 | "Host: www.example.org\r\n" |
| 3707 | "Connection: keep-alive\r\n\r\n"), |
| 3708 | }; |
| 3709 | |
| 3710 | MockRead data_reads2[] = { |
| 3711 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 3712 | |
| 3713 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3714 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3715 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3716 | MockRead(SYNCHRONOUS, "hello"), |
| 3717 | }; |
| 3718 | |
| 3719 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3720 | data_writes1, arraysize(data_writes1)); |
| 3721 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3722 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3723 | data_writes2, arraysize(data_writes2)); |
| 3724 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3725 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3726 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3727 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3728 | std::unique_ptr<HttpTransaction> trans( |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3729 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 3730 | |
| 3731 | TestCompletionCallback callback; |
| 3732 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3733 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3734 | |
| 3735 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3736 | ASSERT_TRUE(response); |
| 3737 | ASSERT_TRUE(response->headers); |
| 3738 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
| 3739 | EXPECT_EQ(407, response->headers->response_code()); |
| 3740 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3741 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3742 | EXPECT_FALSE(response->auth_challenge); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3743 | |
| 3744 | LoadTimingInfo load_timing_info; |
| 3745 | // CONNECT requests and responses are handled at the connect job level, so |
| 3746 | // the transaction does not yet have a connection. |
| 3747 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3748 | |
| 3749 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3750 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3751 | response = trans->GetResponseInfo(); |
| 3752 | ASSERT_TRUE(response); |
| 3753 | ASSERT_TRUE(response->headers); |
| 3754 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3755 | EXPECT_EQ(200, response->headers->response_code()); |
| 3756 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 3757 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3758 | |
| 3759 | // The password prompt info should not be set. |
| 3760 | EXPECT_FALSE(response->auth_challenge); |
| 3761 | |
| 3762 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3763 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3764 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3765 | |
| 3766 | trans.reset(); |
| 3767 | session->CloseAllConnections(); |
| 3768 | } |
| 3769 | |
| 3770 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 3771 | // that hangs up when credentials are initially sent. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3772 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3773 | AuthAllowsDefaultCredentialsTunnelServerClosesConnection) { |
| 3774 | HttpRequestInfo request; |
| 3775 | request.method = "GET"; |
| 3776 | request.url = GURL("https://www.example.org/"); |
| 3777 | |
| 3778 | // Configure against proxy server "myproxy:70". |
| 3779 | session_deps_.proxy_service = |
| 3780 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 3781 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3782 | std::unique_ptr<HttpAuthHandlerMock::Factory> auth_handler_factory( |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3783 | new HttpAuthHandlerMock::Factory()); |
| 3784 | auth_handler_factory->set_do_init_from_challenge(true); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3785 | std::unique_ptr<HttpAuthHandlerMock> mock_handler(new HttpAuthHandlerMock()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3786 | mock_handler->set_allows_default_credentials(true); |
| 3787 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 3788 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 3789 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3790 | |
| 3791 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 3792 | NetLog net_log; |
| 3793 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3794 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3795 | |
| 3796 | // Should try to establish tunnel. |
| 3797 | MockWrite data_writes1[] = { |
| 3798 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3799 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3800 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3801 | |
| 3802 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3803 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3804 | "Proxy-Connection: keep-alive\r\n" |
| 3805 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 3806 | }; |
| 3807 | |
| 3808 | // The proxy responds to the connect with a 407, using a non-persistent |
| 3809 | // connection. |
| 3810 | MockRead data_reads1[] = { |
| 3811 | // No credentials. |
| 3812 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3813 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 3814 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 3815 | }; |
| 3816 | |
| 3817 | // Since the first connection was closed, need to establish another once given |
| 3818 | // credentials. |
| 3819 | MockWrite data_writes2[] = { |
| 3820 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3821 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3822 | "Proxy-Connection: keep-alive\r\n" |
| 3823 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 3824 | |
| 3825 | MockWrite("GET / HTTP/1.1\r\n" |
| 3826 | "Host: www.example.org\r\n" |
| 3827 | "Connection: keep-alive\r\n\r\n"), |
| 3828 | }; |
| 3829 | |
| 3830 | MockRead data_reads2[] = { |
| 3831 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 3832 | |
| 3833 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3834 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3835 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3836 | MockRead(SYNCHRONOUS, "hello"), |
| 3837 | }; |
| 3838 | |
| 3839 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3840 | data_writes1, arraysize(data_writes1)); |
| 3841 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3842 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3843 | data_writes2, arraysize(data_writes2)); |
| 3844 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3845 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3846 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3847 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3848 | std::unique_ptr<HttpTransaction> trans( |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3849 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 3850 | |
| 3851 | TestCompletionCallback callback; |
| 3852 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3853 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3854 | |
| 3855 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3856 | ASSERT_TRUE(response); |
| 3857 | ASSERT_TRUE(response->headers); |
| 3858 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3859 | EXPECT_EQ(407, response->headers->response_code()); |
| 3860 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3861 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 3862 | EXPECT_FALSE(response->auth_challenge); |
| 3863 | |
| 3864 | LoadTimingInfo load_timing_info; |
| 3865 | // CONNECT requests and responses are handled at the connect job level, so |
| 3866 | // the transaction does not yet have a connection. |
| 3867 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3868 | |
| 3869 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3870 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3871 | |
| 3872 | response = trans->GetResponseInfo(); |
| 3873 | ASSERT_TRUE(response); |
| 3874 | ASSERT_TRUE(response->headers); |
| 3875 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3876 | EXPECT_EQ(200, response->headers->response_code()); |
| 3877 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 3878 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3879 | |
| 3880 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3881 | EXPECT_FALSE(response->auth_challenge); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3882 | |
| 3883 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3884 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3885 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3886 | |
| 3887 | trans.reset(); |
| 3888 | session->CloseAllConnections(); |
| 3889 | } |
| 3890 | |
| 3891 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 3892 | // that hangs up when credentials are initially sent, and hangs up again when |
| 3893 | // they are retried. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3894 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3895 | AuthAllowsDefaultCredentialsTunnelServerClosesConnectionTwice) { |
| 3896 | HttpRequestInfo request; |
| 3897 | request.method = "GET"; |
| 3898 | request.url = GURL("https://www.example.org/"); |
| 3899 | |
| 3900 | // Configure against proxy server "myproxy:70". |
| 3901 | session_deps_.proxy_service = |
| 3902 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 3903 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3904 | std::unique_ptr<HttpAuthHandlerMock::Factory> auth_handler_factory( |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3905 | new HttpAuthHandlerMock::Factory()); |
| 3906 | auth_handler_factory->set_do_init_from_challenge(true); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3907 | std::unique_ptr<HttpAuthHandlerMock> mock_handler(new HttpAuthHandlerMock()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3908 | mock_handler->set_allows_default_credentials(true); |
| 3909 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 3910 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 3911 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3912 | |
| 3913 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 3914 | NetLog net_log; |
| 3915 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3916 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3917 | |
| 3918 | // Should try to establish tunnel. |
| 3919 | MockWrite data_writes1[] = { |
| 3920 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3921 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3922 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3923 | |
| 3924 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3925 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3926 | "Proxy-Connection: keep-alive\r\n" |
| 3927 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 3928 | }; |
| 3929 | |
| 3930 | // The proxy responds to the connect with a 407, and then hangs up after the |
| 3931 | // second request is sent. |
| 3932 | MockRead data_reads1[] = { |
| 3933 | // No credentials. |
| 3934 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3935 | MockRead("Content-Length: 0\r\n"), |
| 3936 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 3937 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 3938 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 3939 | }; |
| 3940 | |
| 3941 | // HttpNetworkTransaction sees a reused connection that was closed with |
| 3942 | // ERR_CONNECTION_CLOSED, realized it might have been a race, so retries the |
| 3943 | // request. |
| 3944 | MockWrite data_writes2[] = { |
| 3945 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3946 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3947 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3948 | }; |
| 3949 | |
| 3950 | // The proxy, having had more than enough of us, just hangs up. |
| 3951 | MockRead data_reads2[] = { |
| 3952 | // No credentials. |
| 3953 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 3954 | }; |
| 3955 | |
| 3956 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3957 | data_writes1, arraysize(data_writes1)); |
| 3958 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3959 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3960 | data_writes2, arraysize(data_writes2)); |
| 3961 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3962 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3963 | std::unique_ptr<HttpTransaction> trans( |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3964 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 3965 | |
| 3966 | TestCompletionCallback callback; |
| 3967 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3968 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3969 | |
| 3970 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3971 | ASSERT_TRUE(response); |
| 3972 | ASSERT_TRUE(response->headers); |
| 3973 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3974 | EXPECT_EQ(407, response->headers->response_code()); |
| 3975 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3976 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 3977 | EXPECT_FALSE(response->auth_challenge); |
| 3978 | |
| 3979 | LoadTimingInfo load_timing_info; |
| 3980 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3981 | |
| 3982 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3983 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_EMPTY_RESPONSE)); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3984 | |
| 3985 | trans.reset(); |
| 3986 | session->CloseAllConnections(); |
| 3987 | } |
| 3988 | |
| 3989 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 3990 | // that hangs up when credentials are initially sent, and sends a challenge |
| 3991 | // again they are retried. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3992 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3993 | AuthAllowsDefaultCredentialsTunnelServerChallengesTwice) { |
| 3994 | HttpRequestInfo request; |
| 3995 | request.method = "GET"; |
| 3996 | request.url = GURL("https://www.example.org/"); |
| 3997 | |
| 3998 | // Configure against proxy server "myproxy:70". |
| 3999 | session_deps_.proxy_service = |
| 4000 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 4001 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4002 | std::unique_ptr<HttpAuthHandlerMock::Factory> auth_handler_factory( |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4003 | new HttpAuthHandlerMock::Factory()); |
| 4004 | auth_handler_factory->set_do_init_from_challenge(true); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4005 | std::unique_ptr<HttpAuthHandlerMock> mock_handler(new HttpAuthHandlerMock()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4006 | mock_handler->set_allows_default_credentials(true); |
| 4007 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4008 | HttpAuth::AUTH_PROXY); |
| 4009 | // Add another handler for the second challenge. It supports default |
| 4010 | // credentials, but they shouldn't be used, since they were already tried. |
| 4011 | mock_handler.reset(new HttpAuthHandlerMock()); |
| 4012 | mock_handler->set_allows_default_credentials(true); |
| 4013 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4014 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4015 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4016 | |
| 4017 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4018 | NetLog net_log; |
| 4019 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4020 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4021 | |
| 4022 | // Should try to establish tunnel. |
| 4023 | MockWrite data_writes1[] = { |
| 4024 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4025 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4026 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4027 | }; |
| 4028 | |
| 4029 | // The proxy responds to the connect with a 407, using a non-persistent |
| 4030 | // connection. |
| 4031 | MockRead data_reads1[] = { |
| 4032 | // No credentials. |
| 4033 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4034 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4035 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4036 | }; |
| 4037 | |
| 4038 | // Since the first connection was closed, need to establish another once given |
| 4039 | // credentials. |
| 4040 | MockWrite data_writes2[] = { |
| 4041 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4042 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4043 | "Proxy-Connection: keep-alive\r\n" |
| 4044 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4045 | }; |
| 4046 | |
| 4047 | MockRead data_reads2[] = { |
| 4048 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4049 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4050 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4051 | }; |
| 4052 | |
| 4053 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4054 | data_writes1, arraysize(data_writes1)); |
| 4055 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4056 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4057 | data_writes2, arraysize(data_writes2)); |
| 4058 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4059 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4060 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4061 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4062 | std::unique_ptr<HttpTransaction> trans( |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4063 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 4064 | |
| 4065 | TestCompletionCallback callback; |
| 4066 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4067 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4068 | |
| 4069 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4070 | ASSERT_TRUE(response); |
| 4071 | ASSERT_TRUE(response->headers); |
| 4072 | EXPECT_EQ(407, response->headers->response_code()); |
| 4073 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4074 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4075 | EXPECT_FALSE(response->auth_challenge); |
| 4076 | |
| 4077 | LoadTimingInfo load_timing_info; |
| 4078 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4079 | |
| 4080 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4081 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4082 | response = trans->GetResponseInfo(); |
| 4083 | ASSERT_TRUE(response); |
| 4084 | ASSERT_TRUE(response->headers); |
| 4085 | EXPECT_EQ(407, response->headers->response_code()); |
| 4086 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 4087 | EXPECT_TRUE(response->auth_challenge); |
| 4088 | |
| 4089 | trans.reset(); |
| 4090 | session->CloseAllConnections(); |
| 4091 | } |
| 4092 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4093 | // Test the load timing for HTTPS requests with an HTTP proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4094 | TEST_F(HttpNetworkTransactionTest, HttpProxyLoadTimingNoPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4095 | HttpRequestInfo request1; |
| 4096 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4097 | request1.url = GURL("https://www.example.org/1"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4098 | |
| 4099 | HttpRequestInfo request2; |
| 4100 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4101 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4102 | |
| 4103 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4104 | session_deps_.proxy_service = ProxyService::CreateFixed("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4105 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4106 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4107 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4108 | |
| 4109 | // Since we have proxy, should try to establish tunnel. |
| 4110 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4111 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4112 | "Host: www.example.org:443\r\n" |
| 4113 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4114 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4115 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 4116 | "Host: www.example.org\r\n" |
| 4117 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4118 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4119 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 4120 | "Host: www.example.org\r\n" |
| 4121 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4122 | }; |
| 4123 | |
| 4124 | // The proxy responds to the connect with a 407, using a persistent |
| 4125 | // connection. |
| 4126 | MockRead data_reads1[] = { |
| 4127 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 4128 | |
| 4129 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4130 | MockRead("Content-Length: 1\r\n\r\n"), |
| 4131 | MockRead(SYNCHRONOUS, "1"), |
| 4132 | |
| 4133 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4134 | MockRead("Content-Length: 2\r\n\r\n"), |
| 4135 | MockRead(SYNCHRONOUS, "22"), |
| 4136 | }; |
| 4137 | |
| 4138 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4139 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4140 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4141 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4142 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4143 | |
| 4144 | TestCompletionCallback callback1; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4145 | std::unique_ptr<HttpTransaction> trans1( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4146 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4147 | |
| 4148 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4149 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4150 | |
| 4151 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4152 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4153 | |
| 4154 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4155 | ASSERT_TRUE(response1); |
| 4156 | ASSERT_TRUE(response1->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4157 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 4158 | |
| 4159 | LoadTimingInfo load_timing_info1; |
| 4160 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 4161 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4162 | |
| 4163 | trans1.reset(); |
| 4164 | |
| 4165 | TestCompletionCallback callback2; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4166 | std::unique_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4167 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4168 | |
| 4169 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4170 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4171 | |
| 4172 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4173 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4174 | |
| 4175 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4176 | ASSERT_TRUE(response2); |
| 4177 | ASSERT_TRUE(response2->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4178 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 4179 | |
| 4180 | LoadTimingInfo load_timing_info2; |
| 4181 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4182 | TestLoadTimingReused(load_timing_info2); |
| 4183 | |
| 4184 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 4185 | |
| 4186 | trans2.reset(); |
| 4187 | session->CloseAllConnections(); |
| 4188 | } |
| 4189 | |
| 4190 | // 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] | 4191 | TEST_F(HttpNetworkTransactionTest, HttpProxyLoadTimingWithPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4192 | HttpRequestInfo request1; |
| 4193 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4194 | request1.url = GURL("https://www.example.org/1"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4195 | |
| 4196 | HttpRequestInfo request2; |
| 4197 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4198 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4199 | |
| 4200 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4201 | session_deps_.proxy_service = |
| 4202 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4203 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4204 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4205 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4206 | |
| 4207 | // Since we have proxy, should try to establish tunnel. |
| 4208 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4209 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4210 | "Host: www.example.org:443\r\n" |
| 4211 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4212 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4213 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 4214 | "Host: www.example.org\r\n" |
| 4215 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4216 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4217 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 4218 | "Host: www.example.org\r\n" |
| 4219 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4220 | }; |
| 4221 | |
| 4222 | // The proxy responds to the connect with a 407, using a persistent |
| 4223 | // connection. |
| 4224 | MockRead data_reads1[] = { |
| 4225 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 4226 | |
| 4227 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4228 | MockRead("Content-Length: 1\r\n\r\n"), |
| 4229 | MockRead(SYNCHRONOUS, "1"), |
| 4230 | |
| 4231 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4232 | MockRead("Content-Length: 2\r\n\r\n"), |
| 4233 | MockRead(SYNCHRONOUS, "22"), |
| 4234 | }; |
| 4235 | |
| 4236 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4237 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4238 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4239 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4240 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4241 | |
| 4242 | TestCompletionCallback callback1; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4243 | std::unique_ptr<HttpTransaction> trans1( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4244 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4245 | |
| 4246 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4247 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4248 | |
| 4249 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4250 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4251 | |
| 4252 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4253 | ASSERT_TRUE(response1); |
| 4254 | ASSERT_TRUE(response1->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4255 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 4256 | |
| 4257 | LoadTimingInfo load_timing_info1; |
| 4258 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 4259 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 4260 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4261 | |
| 4262 | trans1.reset(); |
| 4263 | |
| 4264 | TestCompletionCallback callback2; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4265 | std::unique_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4266 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4267 | |
| 4268 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4269 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4270 | |
| 4271 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4272 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4273 | |
| 4274 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4275 | ASSERT_TRUE(response2); |
| 4276 | ASSERT_TRUE(response2->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4277 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 4278 | |
| 4279 | LoadTimingInfo load_timing_info2; |
| 4280 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4281 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 4282 | |
| 4283 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 4284 | |
| 4285 | trans2.reset(); |
| 4286 | session->CloseAllConnections(); |
| 4287 | } |
| 4288 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4289 | // Test a simple get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4290 | TEST_F(HttpNetworkTransactionTest, HttpsProxyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4291 | HttpRequestInfo request; |
| 4292 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4293 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4294 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4295 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4296 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4297 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4298 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4299 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4300 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4301 | // Since we have proxy, should use full url |
| 4302 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4303 | MockWrite( |
| 4304 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 4305 | "Host: www.example.org\r\n" |
| 4306 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4307 | }; |
| 4308 | |
| 4309 | MockRead data_reads1[] = { |
| 4310 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4311 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4312 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4313 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4314 | }; |
| 4315 | |
| 4316 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4317 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4318 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4319 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4320 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4321 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4322 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4323 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4324 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4325 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4326 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4327 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4328 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4329 | |
| 4330 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4331 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4332 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4333 | LoadTimingInfo load_timing_info; |
| 4334 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4335 | TestLoadTimingNotReused(load_timing_info, |
| 4336 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 4337 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4338 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4339 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4340 | |
| 4341 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4342 | EXPECT_EQ(200, response->headers->response_code()); |
| 4343 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 4344 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4345 | |
| 4346 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4347 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4348 | } |
| 4349 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4350 | // Test a SPDY get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4351 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4352 | HttpRequestInfo request; |
| 4353 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4354 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4355 | request.load_flags = 0; |
| 4356 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4357 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4358 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4359 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4360 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4361 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4362 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4363 | // fetch http://www.example.org/ via SPDY |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4364 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 4365 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4366 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4367 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4368 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4369 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4370 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4371 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4372 | }; |
| 4373 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4374 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4375 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4376 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4377 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4378 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 4379 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4380 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4381 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4382 | TestCompletionCallback callback1; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4383 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4384 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4385 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4386 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4387 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4388 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4389 | |
| 4390 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4391 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4392 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4393 | LoadTimingInfo load_timing_info; |
| 4394 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4395 | TestLoadTimingNotReused(load_timing_info, |
| 4396 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 4397 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4398 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4399 | ASSERT_TRUE(response); |
| 4400 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 4401 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4402 | |
| 4403 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4404 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 4405 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4406 | } |
| 4407 | |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4408 | // Verifies that a session which races and wins against the owning transaction |
| 4409 | // (completing prior to host resolution), doesn't fail the transaction. |
| 4410 | // Regression test for crbug.com/334413. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4411 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGetWithSessionRace) { |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4412 | HttpRequestInfo request; |
| 4413 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4414 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4415 | request.load_flags = 0; |
| 4416 | |
| 4417 | // Configure SPDY proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4418 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4419 | BoundTestNetLog log; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4420 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4421 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4422 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4423 | // Fetch http://www.example.org/ through the SPDY proxy. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4424 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 4425 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4426 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4427 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4428 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4429 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4430 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4431 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4432 | }; |
| 4433 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4434 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4435 | arraysize(spdy_writes)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4436 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 4437 | |
| 4438 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 4439 | ssl.next_proto = kProtoHTTP2; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4440 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4441 | |
| 4442 | TestCompletionCallback callback1; |
| 4443 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4444 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4445 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 4446 | |
| 4447 | // Stall the hostname resolution begun by the transaction. |
| 4448 | session_deps_.host_resolver->set_synchronous_mode(false); |
| 4449 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 4450 | |
| 4451 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4452 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4453 | |
| 4454 | // Race a session to the proxy, which completes first. |
| 4455 | session_deps_.host_resolver->set_ondemand_mode(false); |
| 4456 | SpdySessionKey key( |
| 4457 | HostPortPair("proxy", 70), ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
| 4458 | base::WeakPtr<SpdySession> spdy_session = |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4459 | CreateSecureSpdySession(session.get(), key, log.bound()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4460 | |
| 4461 | // Unstall the resolution begun by the transaction. |
| 4462 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 4463 | session_deps_.host_resolver->ResolveAllPending(); |
| 4464 | |
| 4465 | EXPECT_FALSE(callback1.have_result()); |
| 4466 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4467 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4468 | |
| 4469 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4470 | ASSERT_TRUE(response); |
| 4471 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 4472 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4473 | |
| 4474 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4475 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4476 | EXPECT_EQ(kUploadData, response_data); |
| 4477 | } |
| 4478 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4479 | // Test a SPDY get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4480 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGetWithProxyAuth) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4481 | HttpRequestInfo request; |
| 4482 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4483 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4484 | request.load_flags = 0; |
| 4485 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4486 | // Configure against https proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4487 | session_deps_.proxy_service = ProxyService::CreateFixed("https://myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4488 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4489 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4490 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4491 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4492 | // The first request will be a bare GET, the second request will be a |
| 4493 | // GET with a Proxy-Authorization header. |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 4494 | spdy_util_.set_default_url(request.url); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4495 | SpdySerializedFrame req_get( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4496 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, false)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4497 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4498 | const char* const kExtraAuthorizationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4499 | "proxy-authorization", "Basic Zm9vOmJhcg==" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4500 | }; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4501 | SpdySerializedFrame req_get_authorization(spdy_util_.ConstructSpdyGet( |
| 4502 | kExtraAuthorizationHeaders, arraysize(kExtraAuthorizationHeaders) / 2, 3, |
| 4503 | LOWEST, false)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4504 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4505 | CreateMockWrite(req_get, 0), CreateMockWrite(req_get_authorization, 3), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4506 | }; |
| 4507 | |
| 4508 | // The first response is a 407 proxy authentication challenge, and the second |
| 4509 | // response will be a 200 response since the second request includes a valid |
| 4510 | // Authorization header. |
| 4511 | const char* const kExtraAuthenticationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4512 | "proxy-authenticate", "Basic realm=\"MyRealm1\"" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4513 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4514 | SpdySerializedFrame resp_authentication(spdy_util_.ConstructSpdyReplyError( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4515 | "407 Proxy Authentication Required", kExtraAuthenticationHeaders, |
| 4516 | arraysize(kExtraAuthenticationHeaders) / 2, 1)); |
| 4517 | SpdySerializedFrame body_authentication( |
| 4518 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4519 | SpdySerializedFrame resp_data(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4520 | SpdySerializedFrame body_data(spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4521 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4522 | CreateMockRead(resp_authentication, 1), |
| 4523 | CreateMockRead(body_authentication, 2), |
| 4524 | CreateMockRead(resp_data, 4), |
| 4525 | CreateMockRead(body_data, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4526 | MockRead(ASYNC, 0, 6), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4527 | }; |
| 4528 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4529 | SequencedSocketData data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4530 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4531 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4532 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4533 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 4534 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4535 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4536 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4537 | TestCompletionCallback callback1; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4538 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4539 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4540 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4541 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4542 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4543 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4544 | |
| 4545 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4546 | EXPECT_THAT(rv, IsOk()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4547 | |
| 4548 | const HttpResponseInfo* const response = trans->GetResponseInfo(); |
| 4549 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4550 | ASSERT_TRUE(response); |
| 4551 | ASSERT_TRUE(response->headers); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4552 | EXPECT_EQ(407, response->headers->response_code()); |
| 4553 | EXPECT_TRUE(response->was_fetched_via_spdy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 4554 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4555 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4556 | TestCompletionCallback callback2; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4557 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4558 | rv = trans->RestartWithAuth( |
| 4559 | AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4560 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4561 | |
| 4562 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4563 | EXPECT_THAT(rv, IsOk()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4564 | |
| 4565 | const HttpResponseInfo* const response_restart = trans->GetResponseInfo(); |
| 4566 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4567 | ASSERT_TRUE(response_restart); |
| 4568 | ASSERT_TRUE(response_restart->headers); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4569 | EXPECT_EQ(200, response_restart->headers->response_code()); |
| 4570 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4571 | EXPECT_FALSE(response_restart->auth_challenge); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4572 | } |
| 4573 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4574 | // Test a SPDY CONNECT through an HTTPS Proxy to an HTTPS (non-SPDY) Server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4575 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectHttps) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4576 | HttpRequestInfo request; |
| 4577 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4578 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4579 | request.load_flags = 0; |
| 4580 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4581 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4582 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4583 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4584 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4585 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4586 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4587 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4588 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4589 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4590 | // CONNECT to www.example.org:443 via SPDY |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4591 | SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4592 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 4593 | // fetch https://www.example.org/ via HTTP |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4594 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4595 | const char get[] = |
| 4596 | "GET / HTTP/1.1\r\n" |
| 4597 | "Host: www.example.org\r\n" |
| 4598 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4599 | SpdySerializedFrame wrapped_get( |
| 4600 | spdy_util_.ConstructSpdyDataFrame(1, get, strlen(get), false)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4601 | SpdySerializedFrame conn_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4602 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 4603 | "Content-Length: 10\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4604 | SpdySerializedFrame wrapped_get_resp( |
| 4605 | spdy_util_.ConstructSpdyDataFrame(1, resp, strlen(resp), false)); |
| 4606 | SpdySerializedFrame wrapped_body( |
| 4607 | spdy_util_.ConstructSpdyDataFrame(1, "1234567890", 10, false)); |
| 4608 | SpdySerializedFrame window_update( |
| 4609 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 4610 | |
| 4611 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4612 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_get, 2), |
| 4613 | CreateMockWrite(window_update, 6), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 4614 | }; |
| 4615 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4616 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4617 | CreateMockRead(conn_resp, 1, ASYNC), |
| 4618 | CreateMockRead(wrapped_get_resp, 3, ASYNC), |
| 4619 | CreateMockRead(wrapped_body, 4, ASYNC), |
| 4620 | CreateMockRead(wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4621 | MockRead(ASYNC, 0, 7), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4622 | }; |
| 4623 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4624 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4625 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4626 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4627 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4628 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 4629 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4630 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4631 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4632 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4633 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4634 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4635 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4636 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4637 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4638 | |
| 4639 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4640 | ASSERT_THAT(rv, IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4641 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4642 | LoadTimingInfo load_timing_info; |
| 4643 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4644 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4645 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4646 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4647 | ASSERT_TRUE(response); |
| 4648 | ASSERT_TRUE(response->headers); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4649 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4650 | |
| 4651 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4652 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4653 | EXPECT_EQ("1234567890", response_data); |
| 4654 | } |
| 4655 | |
| 4656 | // Test a SPDY CONNECT through an HTTPS Proxy to a SPDY server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4657 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectSpdy) { |
| 4658 | SpdyTestUtil spdy_util_wrapped; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4659 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4660 | HttpRequestInfo request; |
| 4661 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4662 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4663 | request.load_flags = 0; |
| 4664 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4665 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4666 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4667 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4668 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4669 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4670 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4671 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4672 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4673 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4674 | // CONNECT to www.example.org:443 via SPDY |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4675 | SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4676 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 4677 | // fetch https://www.example.org/ via SPDY |
| 4678 | const char kMyUrl[] = "https://www.example.org/"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4679 | SpdySerializedFrame get( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4680 | spdy_util_wrapped.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4681 | SpdySerializedFrame wrapped_get(spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4682 | SpdySerializedFrame conn_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4683 | SpdySerializedFrame get_resp( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4684 | spdy_util_wrapped.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4685 | SpdySerializedFrame wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4686 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4687 | SpdySerializedFrame body(spdy_util_wrapped.ConstructSpdyDataFrame(1, true)); |
| 4688 | SpdySerializedFrame wrapped_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4689 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4690 | SpdySerializedFrame window_update_get_resp( |
| 4691 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
| 4692 | SpdySerializedFrame window_update_body( |
| 4693 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body.size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 4694 | |
| 4695 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4696 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_get, 2), |
| 4697 | CreateMockWrite(window_update_get_resp, 6), |
| 4698 | CreateMockWrite(window_update_body, 7), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 4699 | }; |
| 4700 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4701 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4702 | CreateMockRead(conn_resp, 1, ASYNC), |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4703 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4704 | CreateMockRead(wrapped_get_resp, 4, ASYNC), |
| 4705 | CreateMockRead(wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4706 | MockRead(ASYNC, 0, 8), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4707 | }; |
| 4708 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4709 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4710 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4711 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4712 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4713 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 4714 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4715 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4716 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 4717 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4718 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4719 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4720 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4721 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4722 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4723 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4724 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4725 | // Allow the SpdyProxyClientSocket's write callback to complete. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 4726 | base::RunLoop().RunUntilIdle(); |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4727 | // Now allow the read of the response to complete. |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 4728 | spdy_data.Resume(); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4729 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4730 | EXPECT_THAT(rv, IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4731 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4732 | LoadTimingInfo load_timing_info; |
| 4733 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4734 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4735 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4736 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4737 | ASSERT_TRUE(response); |
| 4738 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 4739 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4740 | |
| 4741 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4742 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 4743 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4744 | } |
| 4745 | |
| 4746 | // Test a SPDY CONNECT failure through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4747 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectFailure) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4748 | HttpRequestInfo request; |
| 4749 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4750 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4751 | request.load_flags = 0; |
| 4752 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4753 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4754 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4755 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4756 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4757 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4758 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4759 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4760 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4761 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4762 | // CONNECT to www.example.org:443 via SPDY |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4763 | SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4764 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4765 | SpdySerializedFrame get( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 4766 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4767 | |
| 4768 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4769 | CreateMockWrite(connect, 0), CreateMockWrite(get, 2), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4770 | }; |
| 4771 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4772 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError(1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4773 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4774 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4775 | CreateMockRead(resp, 1, ASYNC), MockRead(ASYNC, 0, 3), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4776 | }; |
| 4777 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4778 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4779 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4780 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4781 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4782 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 4783 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4784 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4785 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 4786 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4787 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4788 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4789 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4790 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4791 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4792 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4793 | |
| 4794 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4795 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4796 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 4797 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4798 | } |
| 4799 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4800 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 4801 | // HTTPS Proxy to different servers. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4802 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4803 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsTwoServers) { |
| 4804 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4805 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4806 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4807 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4808 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4809 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4810 | |
| 4811 | HttpRequestInfo request1; |
| 4812 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4813 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4814 | request1.load_flags = 0; |
| 4815 | |
| 4816 | HttpRequestInfo request2; |
| 4817 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4818 | request2.url = GURL("https://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4819 | request2.load_flags = 0; |
| 4820 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4821 | // CONNECT to www.example.org:443 via SPDY. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4822 | SpdySerializedFrame connect1(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4823 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4824 | SpdySerializedFrame conn_resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4825 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4826 | // Fetch https://www.example.org/ via HTTP. |
| 4827 | const char get1[] = |
| 4828 | "GET / HTTP/1.1\r\n" |
| 4829 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4830 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4831 | SpdySerializedFrame wrapped_get1( |
| 4832 | spdy_util_.ConstructSpdyDataFrame(1, get1, strlen(get1), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4833 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 4834 | "Content-Length: 1\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4835 | SpdySerializedFrame wrapped_get_resp1( |
| 4836 | spdy_util_.ConstructSpdyDataFrame(1, resp1, strlen(resp1), false)); |
| 4837 | SpdySerializedFrame wrapped_body1( |
| 4838 | spdy_util_.ConstructSpdyDataFrame(1, "1", 1, false)); |
| 4839 | SpdySerializedFrame window_update( |
| 4840 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1.size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4841 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4842 | // CONNECT to mail.example.org:443 via SPDY. |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 4843 | SpdyHeaderBlock connect2_block; |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 4844 | connect2_block[spdy_util_.GetMethodKey()] = "CONNECT"; |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 4845 | connect2_block[spdy_util_.GetHostKey()] = "mail.example.org:443"; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4846 | SpdySerializedFrame connect2(spdy_util_.ConstructSpdyHeaders( |
| 4847 | 3, std::move(connect2_block), LOWEST, false)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 4848 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4849 | SpdySerializedFrame conn_resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4850 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4851 | // Fetch https://mail.example.org/ via HTTP. |
| 4852 | const char get2[] = |
| 4853 | "GET / HTTP/1.1\r\n" |
| 4854 | "Host: mail.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4855 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4856 | SpdySerializedFrame wrapped_get2( |
| 4857 | spdy_util_.ConstructSpdyDataFrame(3, get2, strlen(get2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4858 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 4859 | "Content-Length: 2\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4860 | SpdySerializedFrame wrapped_get_resp2( |
| 4861 | spdy_util_.ConstructSpdyDataFrame(3, resp2, strlen(resp2), false)); |
| 4862 | SpdySerializedFrame wrapped_body2( |
| 4863 | spdy_util_.ConstructSpdyDataFrame(3, "22", 2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4864 | |
| 4865 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4866 | CreateMockWrite(connect1, 0), CreateMockWrite(wrapped_get1, 2), |
| 4867 | CreateMockWrite(connect2, 5), CreateMockWrite(wrapped_get2, 7), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4868 | }; |
| 4869 | |
| 4870 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4871 | CreateMockRead(conn_resp1, 1, ASYNC), |
| 4872 | CreateMockRead(wrapped_get_resp1, 3, ASYNC), |
| 4873 | CreateMockRead(wrapped_body1, 4, ASYNC), |
| 4874 | CreateMockRead(conn_resp2, 6, ASYNC), |
| 4875 | CreateMockRead(wrapped_get_resp2, 8, ASYNC), |
| 4876 | CreateMockRead(wrapped_body2, 9, ASYNC), |
| 4877 | MockRead(ASYNC, 0, 10), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4878 | }; |
| 4879 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4880 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4881 | arraysize(spdy_writes)); |
| 4882 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4883 | |
| 4884 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 4885 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4886 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4887 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4888 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4889 | SSLSocketDataProvider ssl3(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4890 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4891 | |
| 4892 | TestCompletionCallback callback; |
| 4893 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4894 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4895 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4896 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4897 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4898 | |
| 4899 | LoadTimingInfo load_timing_info; |
| 4900 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4901 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4902 | |
| 4903 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4904 | ASSERT_TRUE(response); |
| 4905 | ASSERT_TRUE(response->headers); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4906 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4907 | |
| 4908 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 4909 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4910 | rv = trans->Read(buf.get(), 256, callback.callback()); |
| 4911 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4912 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4913 | std::unique_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4914 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4915 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4916 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4917 | |
| 4918 | LoadTimingInfo load_timing_info2; |
| 4919 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4920 | // Even though the SPDY connection is reused, a new tunnelled connection has |
| 4921 | // to be created, so the socket's load timing looks like a fresh connection. |
| 4922 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4923 | |
| 4924 | // The requests should have different IDs, since they each are using their own |
| 4925 | // separate stream. |
| 4926 | EXPECT_NE(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 4927 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4928 | rv = trans2->Read(buf.get(), 256, callback.callback()); |
| 4929 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4930 | } |
| 4931 | |
| 4932 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 4933 | // HTTPS Proxy to the same server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4934 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4935 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsSameServer) { |
| 4936 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4937 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4938 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4939 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4940 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4941 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4942 | |
| 4943 | HttpRequestInfo request1; |
| 4944 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4945 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4946 | request1.load_flags = 0; |
| 4947 | |
| 4948 | HttpRequestInfo request2; |
| 4949 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4950 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4951 | request2.load_flags = 0; |
| 4952 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4953 | // CONNECT to www.example.org:443 via SPDY. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4954 | SpdySerializedFrame connect1(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4955 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4956 | SpdySerializedFrame conn_resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4957 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4958 | // Fetch https://www.example.org/ via HTTP. |
| 4959 | const char get1[] = |
| 4960 | "GET / HTTP/1.1\r\n" |
| 4961 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4962 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4963 | SpdySerializedFrame wrapped_get1( |
| 4964 | spdy_util_.ConstructSpdyDataFrame(1, get1, strlen(get1), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4965 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 4966 | "Content-Length: 1\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4967 | SpdySerializedFrame wrapped_get_resp1( |
| 4968 | spdy_util_.ConstructSpdyDataFrame(1, resp1, strlen(resp1), false)); |
| 4969 | SpdySerializedFrame wrapped_body1( |
| 4970 | spdy_util_.ConstructSpdyDataFrame(1, "1", 1, false)); |
| 4971 | SpdySerializedFrame window_update( |
| 4972 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1.size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4973 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4974 | // Fetch https://www.example.org/2 via HTTP. |
| 4975 | const char get2[] = |
| 4976 | "GET /2 HTTP/1.1\r\n" |
| 4977 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4978 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4979 | SpdySerializedFrame wrapped_get2( |
| 4980 | spdy_util_.ConstructSpdyDataFrame(1, get2, strlen(get2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4981 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 4982 | "Content-Length: 2\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4983 | SpdySerializedFrame wrapped_get_resp2( |
| 4984 | spdy_util_.ConstructSpdyDataFrame(1, resp2, strlen(resp2), false)); |
| 4985 | SpdySerializedFrame wrapped_body2( |
| 4986 | spdy_util_.ConstructSpdyDataFrame(1, "22", 2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4987 | |
| 4988 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4989 | CreateMockWrite(connect1, 0), CreateMockWrite(wrapped_get1, 2), |
| 4990 | CreateMockWrite(wrapped_get2, 5), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4991 | }; |
| 4992 | |
| 4993 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4994 | CreateMockRead(conn_resp1, 1, ASYNC), |
| 4995 | CreateMockRead(wrapped_get_resp1, 3, ASYNC), |
| 4996 | CreateMockRead(wrapped_body1, 4, ASYNC), |
| 4997 | CreateMockRead(wrapped_get_resp2, 6, ASYNC), |
| 4998 | CreateMockRead(wrapped_body2, 7, ASYNC), |
| 4999 | MockRead(ASYNC, 0, 8), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5000 | }; |
| 5001 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5002 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5003 | arraysize(spdy_writes)); |
| 5004 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5005 | |
| 5006 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5007 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5008 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5009 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5010 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5011 | |
| 5012 | TestCompletionCallback callback; |
| 5013 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5014 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5015 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5016 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5017 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5018 | |
| 5019 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5020 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5021 | |
| 5022 | LoadTimingInfo load_timing_info; |
| 5023 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 5024 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5025 | |
| 5026 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5027 | ASSERT_TRUE(response); |
| 5028 | ASSERT_TRUE(response->headers); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5029 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5030 | |
| 5031 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5032 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5033 | EXPECT_EQ(1, trans->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5034 | trans.reset(); |
| 5035 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5036 | std::unique_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5037 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5038 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5039 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5040 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5041 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5042 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5043 | |
| 5044 | LoadTimingInfo load_timing_info2; |
| 5045 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 5046 | TestLoadTimingReused(load_timing_info2); |
| 5047 | |
| 5048 | // The requests should have the same ID. |
| 5049 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 5050 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5051 | EXPECT_EQ(2, trans2->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5052 | } |
| 5053 | |
| 5054 | // Test load timing in the case of of two HTTP requests through a SPDY HTTPS |
| 5055 | // Proxy to different servers. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5056 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyLoadTimingTwoHttpRequests) { |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5057 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5058 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5059 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5060 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5061 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5062 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5063 | |
| 5064 | HttpRequestInfo request1; |
| 5065 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5066 | request1.url = GURL("http://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5067 | request1.load_flags = 0; |
| 5068 | |
| 5069 | HttpRequestInfo request2; |
| 5070 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5071 | request2.url = GURL("http://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5072 | request2.load_flags = 0; |
| 5073 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5074 | // http://www.example.org/ |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 5075 | SpdyHeaderBlock headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5076 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5077 | SpdySerializedFrame get1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5078 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
| 5079 | SpdySerializedFrame get_resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5080 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, "1", 1, true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5081 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5082 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5083 | // http://mail.example.org/ |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 5084 | SpdyHeaderBlock headers2( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5085 | spdy_util_.ConstructGetHeaderBlockForProxy("http://mail.example.org/")); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5086 | SpdySerializedFrame get2( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5087 | spdy_util_.ConstructSpdyHeaders(3, std::move(headers2), LOWEST, true)); |
| 5088 | SpdySerializedFrame get_resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5089 | SpdySerializedFrame body2( |
| 5090 | spdy_util_.ConstructSpdyDataFrame(3, "22", 2, true)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5091 | |
| 5092 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5093 | CreateMockWrite(get1, 0), CreateMockWrite(get2, 3), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5094 | }; |
| 5095 | |
| 5096 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5097 | CreateMockRead(get_resp1, 1, ASYNC), |
| 5098 | CreateMockRead(body1, 2, ASYNC), |
| 5099 | CreateMockRead(get_resp2, 4, ASYNC), |
| 5100 | CreateMockRead(body2, 5, ASYNC), |
| 5101 | MockRead(ASYNC, 0, 6), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5102 | }; |
| 5103 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5104 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5105 | arraysize(spdy_writes)); |
| 5106 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5107 | |
| 5108 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5109 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5110 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5111 | |
| 5112 | TestCompletionCallback callback; |
| 5113 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5114 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5115 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5116 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5117 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5118 | |
| 5119 | LoadTimingInfo load_timing_info; |
| 5120 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 5121 | TestLoadTimingNotReused(load_timing_info, |
| 5122 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5123 | |
| 5124 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5125 | ASSERT_TRUE(response); |
| 5126 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5127 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5128 | |
| 5129 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5130 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5131 | rv = trans->Read(buf.get(), 256, callback.callback()); |
| 5132 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5133 | // Delete the first request, so the second one can reuse the socket. |
| 5134 | trans.reset(); |
| 5135 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5136 | std::unique_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5137 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5138 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5139 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5140 | |
| 5141 | LoadTimingInfo load_timing_info2; |
| 5142 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 5143 | TestLoadTimingReused(load_timing_info2); |
| 5144 | |
| 5145 | // The requests should have the same ID. |
| 5146 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 5147 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5148 | rv = trans2->Read(buf.get(), 256, callback.callback()); |
| 5149 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5150 | } |
| 5151 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5152 | // Test the challenge-response-retry sequence through an HTTPS Proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5153 | TEST_F(HttpNetworkTransactionTest, HttpsProxyAuthRetry) { |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5154 | HttpRequestInfo request; |
| 5155 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5156 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5157 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5158 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5159 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5160 | // Configure against https proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5161 | session_deps_.proxy_service = ProxyService::CreateFixed("https://myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5162 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5163 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5164 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5165 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5166 | // Since we have proxy, should use full url |
| 5167 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5168 | MockWrite( |
| 5169 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5170 | "Host: www.example.org\r\n" |
| 5171 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5172 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5173 | // After calling trans->RestartWithAuth(), this is the request we should |
| 5174 | // be issuing -- the final header line contains the credentials. |
| 5175 | MockWrite( |
| 5176 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5177 | "Host: www.example.org\r\n" |
| 5178 | "Proxy-Connection: keep-alive\r\n" |
| 5179 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5180 | }; |
| 5181 | |
| 5182 | // The proxy responds to the GET with a 407, using a persistent |
| 5183 | // connection. |
| 5184 | MockRead data_reads1[] = { |
| 5185 | // No credentials. |
| 5186 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 5187 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5188 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 5189 | MockRead("Content-Length: 0\r\n\r\n"), |
| 5190 | |
| 5191 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5192 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5193 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5194 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5195 | }; |
| 5196 | |
| 5197 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5198 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5199 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5200 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5201 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5202 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5203 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5204 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5205 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5206 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5207 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5208 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5209 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5210 | |
| 5211 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5212 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5213 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5214 | LoadTimingInfo load_timing_info; |
| 5215 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 5216 | TestLoadTimingNotReused(load_timing_info, |
| 5217 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5218 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5219 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5220 | ASSERT_TRUE(response); |
| 5221 | ASSERT_TRUE(response->headers); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5222 | EXPECT_EQ(407, response->headers->response_code()); |
| 5223 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 5224 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5225 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5226 | TestCompletionCallback callback2; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5227 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5228 | rv = trans->RestartWithAuth( |
| 5229 | AuthCredentials(kFoo, kBar), callback2.callback()); |
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 = callback2.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 | load_timing_info = LoadTimingInfo(); |
| 5236 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 5237 | // Retrying with HTTP AUTH is considered to be reusing a socket. |
| 5238 | TestLoadTimingReused(load_timing_info); |
| 5239 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5240 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5241 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5242 | |
| 5243 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 5244 | EXPECT_EQ(200, response->headers->response_code()); |
| 5245 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5246 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 5247 | |
| 5248 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5249 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5250 | } |
| 5251 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5252 | void HttpNetworkTransactionTest::ConnectStatusHelperWithExpectedStatus( |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5253 | const MockRead& status, int expected_status) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5254 | HttpRequestInfo request; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5255 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5256 | request.url = GURL("https://www.example.org/"); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5257 | request.load_flags = 0; |
| 5258 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5259 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5260 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5261 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5262 | |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5263 | // Since we have proxy, should try to establish tunnel. |
| 5264 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5265 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5266 | "Host: www.example.org:443\r\n" |
| 5267 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5268 | }; |
| 5269 | |
| 5270 | MockRead data_reads[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 5271 | status, MockRead("Content-Length: 10\r\n\r\n"), |
| 5272 | // No response body because the test stops reading here. |
| 5273 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5274 | }; |
| 5275 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5276 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 5277 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5278 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5279 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5280 | TestCompletionCallback callback; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5281 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5282 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5283 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5284 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5285 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5286 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5287 | |
| 5288 | rv = callback.WaitForResult(); |
| 5289 | EXPECT_EQ(expected_status, rv); |
| 5290 | } |
| 5291 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5292 | void HttpNetworkTransactionTest::ConnectStatusHelper( |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5293 | const MockRead& status) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5294 | ConnectStatusHelperWithExpectedStatus( |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5295 | status, ERR_TUNNEL_CONNECTION_FAILED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5296 | } |
| 5297 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5298 | TEST_F(HttpNetworkTransactionTest, ConnectStatus100) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5299 | ConnectStatusHelper(MockRead("HTTP/1.1 100 Continue\r\n")); |
| 5300 | } |
| 5301 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5302 | TEST_F(HttpNetworkTransactionTest, ConnectStatus101) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5303 | ConnectStatusHelper(MockRead("HTTP/1.1 101 Switching Protocols\r\n")); |
| 5304 | } |
| 5305 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5306 | TEST_F(HttpNetworkTransactionTest, ConnectStatus201) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5307 | ConnectStatusHelper(MockRead("HTTP/1.1 201 Created\r\n")); |
| 5308 | } |
| 5309 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5310 | TEST_F(HttpNetworkTransactionTest, ConnectStatus202) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5311 | ConnectStatusHelper(MockRead("HTTP/1.1 202 Accepted\r\n")); |
| 5312 | } |
| 5313 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5314 | TEST_F(HttpNetworkTransactionTest, ConnectStatus203) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5315 | ConnectStatusHelper( |
| 5316 | MockRead("HTTP/1.1 203 Non-Authoritative Information\r\n")); |
| 5317 | } |
| 5318 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5319 | TEST_F(HttpNetworkTransactionTest, ConnectStatus204) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5320 | ConnectStatusHelper(MockRead("HTTP/1.1 204 No Content\r\n")); |
| 5321 | } |
| 5322 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5323 | TEST_F(HttpNetworkTransactionTest, ConnectStatus205) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5324 | ConnectStatusHelper(MockRead("HTTP/1.1 205 Reset Content\r\n")); |
| 5325 | } |
| 5326 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5327 | TEST_F(HttpNetworkTransactionTest, ConnectStatus206) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5328 | ConnectStatusHelper(MockRead("HTTP/1.1 206 Partial Content\r\n")); |
| 5329 | } |
| 5330 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5331 | TEST_F(HttpNetworkTransactionTest, ConnectStatus300) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5332 | ConnectStatusHelper(MockRead("HTTP/1.1 300 Multiple Choices\r\n")); |
| 5333 | } |
| 5334 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5335 | TEST_F(HttpNetworkTransactionTest, ConnectStatus301) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5336 | ConnectStatusHelper(MockRead("HTTP/1.1 301 Moved Permanently\r\n")); |
| 5337 | } |
| 5338 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5339 | TEST_F(HttpNetworkTransactionTest, ConnectStatus302) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5340 | ConnectStatusHelper(MockRead("HTTP/1.1 302 Found\r\n")); |
| 5341 | } |
| 5342 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5343 | TEST_F(HttpNetworkTransactionTest, ConnectStatus303) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5344 | ConnectStatusHelper(MockRead("HTTP/1.1 303 See Other\r\n")); |
| 5345 | } |
| 5346 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5347 | TEST_F(HttpNetworkTransactionTest, ConnectStatus304) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5348 | ConnectStatusHelper(MockRead("HTTP/1.1 304 Not Modified\r\n")); |
| 5349 | } |
| 5350 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5351 | TEST_F(HttpNetworkTransactionTest, ConnectStatus305) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5352 | ConnectStatusHelper(MockRead("HTTP/1.1 305 Use Proxy\r\n")); |
| 5353 | } |
| 5354 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5355 | TEST_F(HttpNetworkTransactionTest, ConnectStatus306) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5356 | ConnectStatusHelper(MockRead("HTTP/1.1 306\r\n")); |
| 5357 | } |
| 5358 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5359 | TEST_F(HttpNetworkTransactionTest, ConnectStatus307) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5360 | ConnectStatusHelper(MockRead("HTTP/1.1 307 Temporary Redirect\r\n")); |
| 5361 | } |
| 5362 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5363 | TEST_F(HttpNetworkTransactionTest, ConnectStatus308) { |
[email protected] | 0a17aab3 | 2014-04-24 03:32:37 | [diff] [blame] | 5364 | ConnectStatusHelper(MockRead("HTTP/1.1 308 Permanent Redirect\r\n")); |
| 5365 | } |
| 5366 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5367 | TEST_F(HttpNetworkTransactionTest, ConnectStatus400) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5368 | ConnectStatusHelper(MockRead("HTTP/1.1 400 Bad Request\r\n")); |
| 5369 | } |
| 5370 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5371 | TEST_F(HttpNetworkTransactionTest, ConnectStatus401) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5372 | ConnectStatusHelper(MockRead("HTTP/1.1 401 Unauthorized\r\n")); |
| 5373 | } |
| 5374 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5375 | TEST_F(HttpNetworkTransactionTest, ConnectStatus402) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5376 | ConnectStatusHelper(MockRead("HTTP/1.1 402 Payment Required\r\n")); |
| 5377 | } |
| 5378 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5379 | TEST_F(HttpNetworkTransactionTest, ConnectStatus403) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5380 | ConnectStatusHelper(MockRead("HTTP/1.1 403 Forbidden\r\n")); |
| 5381 | } |
| 5382 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5383 | TEST_F(HttpNetworkTransactionTest, ConnectStatus404) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5384 | ConnectStatusHelper(MockRead("HTTP/1.1 404 Not Found\r\n")); |
| 5385 | } |
| 5386 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5387 | TEST_F(HttpNetworkTransactionTest, ConnectStatus405) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5388 | ConnectStatusHelper(MockRead("HTTP/1.1 405 Method Not Allowed\r\n")); |
| 5389 | } |
| 5390 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5391 | TEST_F(HttpNetworkTransactionTest, ConnectStatus406) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5392 | ConnectStatusHelper(MockRead("HTTP/1.1 406 Not Acceptable\r\n")); |
| 5393 | } |
| 5394 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5395 | TEST_F(HttpNetworkTransactionTest, ConnectStatus407) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5396 | ConnectStatusHelperWithExpectedStatus( |
| 5397 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
[email protected] | a7ea883 | 2010-07-12 17:54:54 | [diff] [blame] | 5398 | ERR_PROXY_AUTH_UNSUPPORTED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5399 | } |
| 5400 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5401 | TEST_F(HttpNetworkTransactionTest, ConnectStatus408) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5402 | ConnectStatusHelper(MockRead("HTTP/1.1 408 Request Timeout\r\n")); |
| 5403 | } |
| 5404 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5405 | TEST_F(HttpNetworkTransactionTest, ConnectStatus409) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5406 | ConnectStatusHelper(MockRead("HTTP/1.1 409 Conflict\r\n")); |
| 5407 | } |
| 5408 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5409 | TEST_F(HttpNetworkTransactionTest, ConnectStatus410) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5410 | ConnectStatusHelper(MockRead("HTTP/1.1 410 Gone\r\n")); |
| 5411 | } |
| 5412 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5413 | TEST_F(HttpNetworkTransactionTest, ConnectStatus411) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5414 | ConnectStatusHelper(MockRead("HTTP/1.1 411 Length Required\r\n")); |
| 5415 | } |
| 5416 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5417 | TEST_F(HttpNetworkTransactionTest, ConnectStatus412) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5418 | ConnectStatusHelper(MockRead("HTTP/1.1 412 Precondition Failed\r\n")); |
| 5419 | } |
| 5420 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5421 | TEST_F(HttpNetworkTransactionTest, ConnectStatus413) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5422 | ConnectStatusHelper(MockRead("HTTP/1.1 413 Request Entity Too Large\r\n")); |
| 5423 | } |
| 5424 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5425 | TEST_F(HttpNetworkTransactionTest, ConnectStatus414) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5426 | ConnectStatusHelper(MockRead("HTTP/1.1 414 Request-URI Too Long\r\n")); |
| 5427 | } |
| 5428 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5429 | TEST_F(HttpNetworkTransactionTest, ConnectStatus415) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5430 | ConnectStatusHelper(MockRead("HTTP/1.1 415 Unsupported Media Type\r\n")); |
| 5431 | } |
| 5432 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5433 | TEST_F(HttpNetworkTransactionTest, ConnectStatus416) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5434 | ConnectStatusHelper( |
| 5435 | MockRead("HTTP/1.1 416 Requested Range Not Satisfiable\r\n")); |
| 5436 | } |
| 5437 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5438 | TEST_F(HttpNetworkTransactionTest, ConnectStatus417) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5439 | ConnectStatusHelper(MockRead("HTTP/1.1 417 Expectation Failed\r\n")); |
| 5440 | } |
| 5441 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5442 | TEST_F(HttpNetworkTransactionTest, ConnectStatus500) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5443 | ConnectStatusHelper(MockRead("HTTP/1.1 500 Internal Server Error\r\n")); |
| 5444 | } |
| 5445 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5446 | TEST_F(HttpNetworkTransactionTest, ConnectStatus501) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5447 | ConnectStatusHelper(MockRead("HTTP/1.1 501 Not Implemented\r\n")); |
| 5448 | } |
| 5449 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5450 | TEST_F(HttpNetworkTransactionTest, ConnectStatus502) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5451 | ConnectStatusHelper(MockRead("HTTP/1.1 502 Bad Gateway\r\n")); |
| 5452 | } |
| 5453 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5454 | TEST_F(HttpNetworkTransactionTest, ConnectStatus503) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5455 | ConnectStatusHelper(MockRead("HTTP/1.1 503 Service Unavailable\r\n")); |
| 5456 | } |
| 5457 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5458 | TEST_F(HttpNetworkTransactionTest, ConnectStatus504) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5459 | ConnectStatusHelper(MockRead("HTTP/1.1 504 Gateway Timeout\r\n")); |
| 5460 | } |
| 5461 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5462 | TEST_F(HttpNetworkTransactionTest, ConnectStatus505) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5463 | ConnectStatusHelper(MockRead("HTTP/1.1 505 HTTP Version Not Supported\r\n")); |
| 5464 | } |
| 5465 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5466 | // Test the flow when both the proxy server AND origin server require |
| 5467 | // authentication. Again, this uses basic auth for both since that is |
| 5468 | // the simplest to mock. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5469 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyThenServer) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5470 | HttpRequestInfo request; |
| 5471 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5472 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5473 | request.load_flags = 0; |
| 5474 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5475 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5476 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5477 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 5478 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5479 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 5480 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5481 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5482 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5483 | MockWrite( |
| 5484 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5485 | "Host: www.example.org\r\n" |
| 5486 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5487 | }; |
| 5488 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5489 | MockRead data_reads1[] = { |
| 5490 | MockRead("HTTP/1.0 407 Unauthorized\r\n"), |
| 5491 | // Give a couple authenticate options (only the middle one is actually |
| 5492 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 5493 | MockRead("Proxy-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5494 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5495 | MockRead("Proxy-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 5496 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5497 | // Large content-length -- won't matter, as connection will be reset. |
| 5498 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5499 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5500 | }; |
| 5501 | |
| 5502 | // After calling trans->RestartWithAuth() the first time, this is the |
| 5503 | // request we should be issuing -- the final header line contains the |
| 5504 | // proxy's credentials. |
| 5505 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5506 | MockWrite( |
| 5507 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5508 | "Host: www.example.org\r\n" |
| 5509 | "Proxy-Connection: keep-alive\r\n" |
| 5510 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5511 | }; |
| 5512 | |
| 5513 | // Now the proxy server lets the request pass through to origin server. |
| 5514 | // The origin server responds with a 401. |
| 5515 | MockRead data_reads2[] = { |
| 5516 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5517 | // Note: We are using the same realm-name as the proxy server. This is |
| 5518 | // completely valid, as realms are unique across hosts. |
| 5519 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5520 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5521 | MockRead("Content-Length: 2000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5522 | MockRead(SYNCHRONOUS, ERR_FAILED), // Won't be reached. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5523 | }; |
| 5524 | |
| 5525 | // After calling trans->RestartWithAuth() the second time, we should send |
| 5526 | // the credentials for both the proxy and origin server. |
| 5527 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5528 | MockWrite( |
| 5529 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5530 | "Host: www.example.org\r\n" |
| 5531 | "Proxy-Connection: keep-alive\r\n" |
| 5532 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n" |
| 5533 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5534 | }; |
| 5535 | |
| 5536 | // Lastly we get the desired content. |
| 5537 | MockRead data_reads3[] = { |
| 5538 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5539 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5540 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5541 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5542 | }; |
| 5543 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5544 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5545 | data_writes1, arraysize(data_writes1)); |
| 5546 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5547 | data_writes2, arraysize(data_writes2)); |
| 5548 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 5549 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5550 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5551 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 5552 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5553 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5554 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5555 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5556 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5557 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5558 | |
| 5559 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5560 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5561 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5562 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5563 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5564 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5565 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5566 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5567 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5568 | rv = trans->RestartWithAuth( |
| 5569 | AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5570 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5571 | |
| 5572 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5573 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5574 | |
| 5575 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5576 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5577 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5578 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5579 | TestCompletionCallback callback3; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5580 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5581 | rv = trans->RestartWithAuth( |
| 5582 | AuthCredentials(kFoo2, kBar2), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5583 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5584 | |
| 5585 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5586 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5587 | |
| 5588 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5589 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5590 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5591 | } |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5592 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 5593 | // For the NTLM implementation using SSPI, we skip the NTLM tests since we |
| 5594 | // can't hook into its internals to cause it to generate predictable NTLM |
| 5595 | // authorization headers. |
| 5596 | #if defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5597 | // The NTLM authentication unit tests were generated by capturing the HTTP |
| 5598 | // requests and responses using Fiddler 2 and inspecting the generated random |
| 5599 | // bytes in the debugger. |
| 5600 | |
| 5601 | // Enter the correct password and authenticate successfully. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5602 | TEST_F(HttpNetworkTransactionTest, NTLMAuth1) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5603 | HttpRequestInfo request; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5604 | request.method = "GET"; |
| 5605 | request.url = GURL("http://172.22.68.17/kids/login.aspx"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 5606 | |
| 5607 | // Ensure load is not disrupted by flags which suppress behaviour specific |
| 5608 | // to other auth schemes. |
| 5609 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5610 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5611 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom1, |
| 5612 | MockGetHostName); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5613 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5614 | |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5615 | MockWrite data_writes1[] = { |
| 5616 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5617 | "Host: 172.22.68.17\r\n" |
| 5618 | "Connection: keep-alive\r\n\r\n"), |
| 5619 | }; |
| 5620 | |
| 5621 | MockRead data_reads1[] = { |
| 5622 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 5623 | // Negotiate and NTLM are often requested together. However, we only want |
| 5624 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 5625 | // the header that requests Negotiate for this test. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5626 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 5627 | MockRead("Connection: close\r\n"), |
| 5628 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 5629 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5630 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5631 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5632 | }; |
| 5633 | |
| 5634 | MockWrite data_writes2[] = { |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5635 | // After restarting with a null identity, this is the |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5636 | // request we should be issuing -- the final header line contains a Type |
| 5637 | // 1 message. |
| 5638 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5639 | "Host: 172.22.68.17\r\n" |
| 5640 | "Connection: keep-alive\r\n" |
| 5641 | "Authorization: NTLM " |
| 5642 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
| 5643 | |
| 5644 | // After calling trans->RestartWithAuth(), we should send a Type 3 message |
| 5645 | // (the credentials for the origin server). The second request continues |
| 5646 | // on the same connection. |
| 5647 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5648 | "Host: 172.22.68.17\r\n" |
| 5649 | "Connection: keep-alive\r\n" |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5650 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 5651 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 5652 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwBVKW" |
| 5653 | "Yma5xzVAAAAAAAAAAAAAAAAAAAAACH+gWcm+YsP9Tqb9zCR3WAeZZX" |
| 5654 | "ahlhx5I=\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5655 | }; |
| 5656 | |
| 5657 | MockRead data_reads2[] = { |
| 5658 | // The origin server responds with a Type 2 message. |
| 5659 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 5660 | MockRead("WWW-Authenticate: NTLM " |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5661 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCjGpMpPGlYKkAAAAAAAAAALo" |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5662 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 5663 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 5664 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 5665 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 5666 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 5667 | "BtAAAAAAA=\r\n"), |
| 5668 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 5669 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5670 | MockRead("You are not authorized to view this page\r\n"), |
| 5671 | |
| 5672 | // Lastly we get the desired content. |
| 5673 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5674 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 5675 | MockRead("Content-Length: 13\r\n\r\n"), |
| 5676 | MockRead("Please Login\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5677 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5678 | }; |
| 5679 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5680 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5681 | data_writes1, arraysize(data_writes1)); |
| 5682 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5683 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5684 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5685 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5686 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5687 | TestCompletionCallback callback1; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5688 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5689 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5690 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5691 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5692 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5693 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5694 | |
| 5695 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5696 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5697 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5698 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5699 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5700 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5701 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5702 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[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 callback2; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5705 | |
[email protected] | f3cf980 | 2011-10-28 18:44:58 | [diff] [blame] | 5706 | rv = trans->RestartWithAuth(AuthCredentials(kTestingNTLM, kTestingNTLM), |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5707 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5708 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5709 | |
| 5710 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5711 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5712 | |
| 5713 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 5714 | |
| 5715 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5716 | ASSERT_TRUE(response); |
| 5717 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5718 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5719 | TestCompletionCallback callback3; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5720 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5721 | rv = trans->RestartWithAuth(AuthCredentials(), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5722 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5723 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5724 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5725 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5726 | |
| 5727 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5728 | ASSERT_TRUE(response); |
| 5729 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5730 | EXPECT_EQ(13, response->headers->GetContentLength()); |
| 5731 | } |
| 5732 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5733 | // Enter a wrong password, and then the correct one. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5734 | TEST_F(HttpNetworkTransactionTest, NTLMAuth2) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5735 | HttpRequestInfo request; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5736 | request.method = "GET"; |
| 5737 | request.url = GURL("http://172.22.68.17/kids/login.aspx"); |
| 5738 | request.load_flags = 0; |
| 5739 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5740 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom2, |
| 5741 | MockGetHostName); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5742 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5743 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5744 | MockWrite data_writes1[] = { |
| 5745 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5746 | "Host: 172.22.68.17\r\n" |
| 5747 | "Connection: keep-alive\r\n\r\n"), |
| 5748 | }; |
| 5749 | |
| 5750 | MockRead data_reads1[] = { |
| 5751 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 5752 | // Negotiate and NTLM are often requested together. However, we only want |
| 5753 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 5754 | // the header that requests Negotiate for this test. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5755 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 5756 | MockRead("Connection: close\r\n"), |
| 5757 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 5758 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5759 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5760 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5761 | }; |
| 5762 | |
| 5763 | MockWrite data_writes2[] = { |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5764 | // After restarting with a null identity, this is the |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5765 | // request we should be issuing -- the final header line contains a Type |
| 5766 | // 1 message. |
| 5767 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5768 | "Host: 172.22.68.17\r\n" |
| 5769 | "Connection: keep-alive\r\n" |
| 5770 | "Authorization: NTLM " |
| 5771 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
| 5772 | |
| 5773 | // After calling trans->RestartWithAuth(), we should send a Type 3 message |
| 5774 | // (the credentials for the origin server). The second request continues |
| 5775 | // on the same connection. |
| 5776 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5777 | "Host: 172.22.68.17\r\n" |
| 5778 | "Connection: keep-alive\r\n" |
| 5779 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 5780 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 5781 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwCWeY" |
| 5782 | "XnSZNwoQAAAAAAAAAAAAAAAAAAAADLa34/phTTKzNTWdub+uyFleOj" |
| 5783 | "4Ww7b7E=\r\n\r\n"), |
| 5784 | }; |
| 5785 | |
| 5786 | MockRead data_reads2[] = { |
| 5787 | // The origin server responds with a Type 2 message. |
| 5788 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 5789 | MockRead("WWW-Authenticate: NTLM " |
| 5790 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCbVWUZezVGpAAAAAAAAAAALo" |
| 5791 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 5792 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 5793 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 5794 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 5795 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 5796 | "BtAAAAAAA=\r\n"), |
| 5797 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 5798 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5799 | MockRead("You are not authorized to view this page\r\n"), |
| 5800 | |
| 5801 | // Wrong password. |
| 5802 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5803 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 5804 | MockRead("Connection: close\r\n"), |
| 5805 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 5806 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5807 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5808 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5809 | }; |
| 5810 | |
| 5811 | MockWrite data_writes3[] = { |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5812 | // After restarting with a null identity, this is the |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5813 | // request we should be issuing -- the final header line contains a Type |
| 5814 | // 1 message. |
| 5815 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5816 | "Host: 172.22.68.17\r\n" |
| 5817 | "Connection: keep-alive\r\n" |
| 5818 | "Authorization: NTLM " |
| 5819 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
| 5820 | |
| 5821 | // After calling trans->RestartWithAuth(), we should send a Type 3 message |
| 5822 | // (the credentials for the origin server). The second request continues |
| 5823 | // on the same connection. |
| 5824 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5825 | "Host: 172.22.68.17\r\n" |
| 5826 | "Connection: keep-alive\r\n" |
| 5827 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 5828 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 5829 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwBO54" |
| 5830 | "dFMVvTHwAAAAAAAAAAAAAAAAAAAACS7sT6Uzw7L0L//WUqlIaVWpbI" |
| 5831 | "+4MUm7c=\r\n\r\n"), |
| 5832 | }; |
| 5833 | |
| 5834 | MockRead data_reads3[] = { |
| 5835 | // The origin server responds with a Type 2 message. |
| 5836 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 5837 | MockRead("WWW-Authenticate: NTLM " |
| 5838 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCL24VN8dgOR8AAAAAAAAAALo" |
| 5839 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 5840 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 5841 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 5842 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 5843 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 5844 | "BtAAAAAAA=\r\n"), |
| 5845 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 5846 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5847 | MockRead("You are not authorized to view this page\r\n"), |
| 5848 | |
| 5849 | // Lastly we get the desired content. |
| 5850 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5851 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 5852 | MockRead("Content-Length: 13\r\n\r\n"), |
| 5853 | MockRead("Please Login\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5854 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5855 | }; |
| 5856 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5857 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5858 | data_writes1, arraysize(data_writes1)); |
| 5859 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5860 | data_writes2, arraysize(data_writes2)); |
| 5861 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 5862 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5863 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5864 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 5865 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5866 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5867 | TestCompletionCallback callback1; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5868 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5869 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5870 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5871 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5872 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5873 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5874 | |
| 5875 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5876 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5877 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5878 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5879 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5880 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5881 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5882 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5883 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5884 | TestCompletionCallback callback2; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5885 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5886 | // Enter the wrong password. |
[email protected] | f3cf980 | 2011-10-28 18:44:58 | [diff] [blame] | 5887 | rv = trans->RestartWithAuth(AuthCredentials(kTestingNTLM, kWrongPassword), |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5888 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5889 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5890 | |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5891 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5892 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5893 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5894 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5895 | TestCompletionCallback callback3; |
| 5896 | rv = trans->RestartWithAuth(AuthCredentials(), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5897 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5898 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5899 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5900 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5901 | |
| 5902 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5903 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5904 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5905 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5906 | TestCompletionCallback callback4; |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5907 | |
| 5908 | // Now enter the right password. |
[email protected] | f3cf980 | 2011-10-28 18:44:58 | [diff] [blame] | 5909 | rv = trans->RestartWithAuth(AuthCredentials(kTestingNTLM, kTestingNTLM), |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5910 | callback4.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5911 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5912 | |
| 5913 | rv = callback4.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5914 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5915 | |
| 5916 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 5917 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5918 | TestCompletionCallback callback5; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5919 | |
| 5920 | // One more roundtrip |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5921 | rv = trans->RestartWithAuth(AuthCredentials(), callback5.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5922 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5923 | |
| 5924 | rv = callback5.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5925 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5926 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5927 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5928 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5929 | EXPECT_EQ(13, response->headers->GetContentLength()); |
| 5930 | } |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 5931 | #endif // NTLM_PORTABLE |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5932 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5933 | // Test reading a server response which has only headers, and no body. |
| 5934 | // After some maximum number of bytes is consumed, the transaction should |
| 5935 | // fail with ERR_RESPONSE_HEADERS_TOO_BIG. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5936 | TEST_F(HttpNetworkTransactionTest, LargeHeadersNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5937 | HttpRequestInfo request; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5938 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5939 | request.url = GURL("http://www.example.org/"); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5940 | request.load_flags = 0; |
| 5941 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5942 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 5943 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 5944 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5945 | |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 5946 | // Respond with 300 kb of headers (we should fail after 256 kb). |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 5947 | std::string large_headers_string; |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 5948 | FillLargeHeadersString(&large_headers_string, 300 * 1024); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5949 | |
| 5950 | MockRead data_reads[] = { |
| 5951 | MockRead("HTTP/1.0 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5952 | MockRead(ASYNC, large_headers_string.data(), large_headers_string.size()), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5953 | MockRead("\r\nBODY"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5954 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5955 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5956 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5957 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5958 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5959 | TestCompletionCallback callback; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5960 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5961 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5962 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5963 | |
| 5964 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5965 | EXPECT_THAT(rv, IsError(ERR_RESPONSE_HEADERS_TOO_BIG)); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5966 | } |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5967 | |
| 5968 | // Make sure that we don't try to reuse a TCPClientSocket when failing to |
| 5969 | // establish tunnel. |
| 5970 | // http://code.google.com/p/chromium/issues/detail?id=3772 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5971 | TEST_F(HttpNetworkTransactionTest, DontRecycleTransportSocketForSSLTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5972 | HttpRequestInfo request; |
| 5973 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5974 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5975 | request.load_flags = 0; |
| 5976 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5977 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5978 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | db8f44c | 2008-12-13 04:52:01 | [diff] [blame] | 5979 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5980 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5981 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5982 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5983 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5984 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5985 | // Since we have proxy, should try to establish tunnel. |
| 5986 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5987 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5988 | "Host: www.example.org:443\r\n" |
| 5989 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5990 | }; |
| 5991 | |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 5992 | // The proxy responds to the connect with a 404, using a persistent |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5993 | // connection. Usually a proxy would return 501 (not implemented), |
| 5994 | // or 200 (tunnel established). |
| 5995 | MockRead data_reads1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 5996 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 5997 | MockRead("Content-Length: 10\r\n\r\n"), |
| 5998 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5999 | }; |
| 6000 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6001 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6002 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6003 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6004 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6005 | TestCompletionCallback callback1; |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6006 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6007 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6008 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6009 | |
| 6010 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6011 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6012 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6013 | // Empty the current queue. This is necessary because idle sockets are |
| 6014 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6015 | base::RunLoop().RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6016 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6017 | // We now check to make sure the TCPClientSocket was not added back to |
| 6018 | // the pool. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6019 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6020 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6021 | base::RunLoop().RunUntilIdle(); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6022 | // Make sure that the socket didn't get recycled after calling the destructor. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6023 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6024 | } |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6025 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6026 | // Make sure that we recycle a socket after reading all of the response body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6027 | TEST_F(HttpNetworkTransactionTest, RecycleSocket) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6028 | HttpRequestInfo request; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6029 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6030 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6031 | request.load_flags = 0; |
| 6032 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6033 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6034 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6035 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6036 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6037 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6038 | MockRead data_reads[] = { |
| 6039 | // A part of the response body is received with the response headers. |
| 6040 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 6041 | // The rest of the response body is received in two parts. |
| 6042 | MockRead("lo"), |
| 6043 | MockRead(" world"), |
| 6044 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6045 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6046 | }; |
| 6047 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6048 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6049 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6050 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6051 | TestCompletionCallback callback; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6052 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6053 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6054 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6055 | |
| 6056 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6057 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6058 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6059 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6060 | ASSERT_TRUE(response); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6061 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6062 | EXPECT_TRUE(response->headers); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6063 | std::string status_line = response->headers->GetStatusLine(); |
| 6064 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 6065 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6066 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6067 | |
| 6068 | std::string response_data; |
| 6069 | rv = ReadTransaction(trans.get(), &response_data); |
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 | EXPECT_EQ("hello world", response_data); |
| 6072 | |
| 6073 | // Empty the current queue. This is necessary because idle sockets are |
| 6074 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6075 | base::RunLoop().RunUntilIdle(); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6076 | |
| 6077 | // 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] | 6078 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6079 | } |
| 6080 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6081 | // Make sure that we recycle a SSL socket after reading all of the response |
| 6082 | // body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6083 | TEST_F(HttpNetworkTransactionTest, RecycleSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6084 | HttpRequestInfo request; |
| 6085 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6086 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6087 | request.load_flags = 0; |
| 6088 | |
| 6089 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6090 | MockWrite( |
| 6091 | "GET / HTTP/1.1\r\n" |
| 6092 | "Host: www.example.org\r\n" |
| 6093 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6094 | }; |
| 6095 | |
| 6096 | MockRead data_reads[] = { |
| 6097 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6098 | MockRead("Content-Length: 11\r\n\r\n"), |
| 6099 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6100 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6101 | }; |
| 6102 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6103 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6104 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6105 | |
| 6106 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6107 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6108 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6109 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6110 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6111 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6112 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 6113 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6114 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6115 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6116 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6117 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6118 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6119 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6120 | |
| 6121 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6122 | ASSERT_TRUE(response); |
| 6123 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6124 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6125 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6126 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6127 | |
| 6128 | std::string response_data; |
| 6129 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6130 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6131 | EXPECT_EQ("hello world", response_data); |
| 6132 | |
| 6133 | // Empty the current queue. This is necessary because idle sockets are |
| 6134 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6135 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6136 | |
| 6137 | // 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] | 6138 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6139 | } |
| 6140 | |
| 6141 | // Grab a SSL socket, use it, and put it back into the pool. Then, reuse it |
| 6142 | // from the pool and make sure that we recover okay. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6143 | TEST_F(HttpNetworkTransactionTest, RecycleDeadSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6144 | HttpRequestInfo request; |
| 6145 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6146 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6147 | request.load_flags = 0; |
| 6148 | |
| 6149 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6150 | MockWrite( |
| 6151 | "GET / HTTP/1.1\r\n" |
| 6152 | "Host: www.example.org\r\n" |
| 6153 | "Connection: keep-alive\r\n\r\n"), |
| 6154 | MockWrite( |
| 6155 | "GET / HTTP/1.1\r\n" |
| 6156 | "Host: www.example.org\r\n" |
| 6157 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6158 | }; |
| 6159 | |
| 6160 | MockRead data_reads[] = { |
mmenke | 911ee022 | 2015-12-04 03:58:42 | [diff] [blame] | 6161 | MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
| 6162 | MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6163 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6164 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 6165 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6166 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 6167 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6168 | |
| 6169 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6170 | data_writes, arraysize(data_writes)); |
| 6171 | StaticSocketDataProvider data2(data_reads, arraysize(data_reads), |
| 6172 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6173 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6174 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6175 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6176 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6177 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6178 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 6179 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6180 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6181 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6182 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6183 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6184 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6185 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6186 | |
| 6187 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6188 | ASSERT_TRUE(response); |
| 6189 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6190 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6191 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6192 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6193 | |
| 6194 | std::string response_data; |
| 6195 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6196 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6197 | EXPECT_EQ("hello world", response_data); |
| 6198 | |
| 6199 | // Empty the current queue. This is necessary because idle sockets are |
| 6200 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6201 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6202 | |
| 6203 | // 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] | 6204 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6205 | |
| 6206 | // Now start the second transaction, which should reuse the previous socket. |
| 6207 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6208 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6209 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6210 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6211 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6212 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6213 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6214 | |
| 6215 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6216 | ASSERT_TRUE(response); |
| 6217 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6218 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6219 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6220 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6221 | |
| 6222 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6223 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6224 | EXPECT_EQ("hello world", response_data); |
| 6225 | |
| 6226 | // Empty the current queue. This is necessary because idle sockets are |
| 6227 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6228 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6229 | |
| 6230 | // 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] | 6231 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6232 | } |
| 6233 | |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6234 | // Grab a socket, use it, and put it back into the pool. Then, make |
| 6235 | // low memory notification and ensure the socket pool is flushed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6236 | TEST_F(HttpNetworkTransactionTest, FlushSocketPoolOnLowMemoryNotifications) { |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6237 | HttpRequestInfo request; |
| 6238 | request.method = "GET"; |
| 6239 | request.url = GURL("http://www.example.org/"); |
| 6240 | request.load_flags = 0; |
| 6241 | |
| 6242 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 6243 | |
| 6244 | std::unique_ptr<HttpTransaction> trans( |
| 6245 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 6246 | |
| 6247 | MockRead data_reads[] = { |
| 6248 | // A part of the response body is received with the response headers. |
| 6249 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 6250 | // The rest of the response body is received in two parts. |
| 6251 | MockRead("lo"), MockRead(" world"), |
| 6252 | MockRead("junk"), // Should not be read!! |
| 6253 | MockRead(SYNCHRONOUS, OK), |
| 6254 | }; |
| 6255 | |
| 6256 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 6257 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6258 | |
| 6259 | TestCompletionCallback callback; |
| 6260 | |
| 6261 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 6262 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6263 | |
| 6264 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 6265 | |
| 6266 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6267 | ASSERT_TRUE(response); |
| 6268 | EXPECT_TRUE(response->headers); |
| 6269 | std::string status_line = response->headers->GetStatusLine(); |
| 6270 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 6271 | |
| 6272 | // Make memory critical notification and ensure the transaction still has been |
| 6273 | // operating right. |
| 6274 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 6275 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 6276 | base::RunLoop().RunUntilIdle(); |
| 6277 | |
| 6278 | // Socket should not be flushed as long as it is not idle. |
| 6279 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 6280 | |
| 6281 | std::string response_data; |
| 6282 | rv = ReadTransaction(trans.get(), &response_data); |
| 6283 | EXPECT_THAT(rv, IsOk()); |
| 6284 | EXPECT_EQ("hello world", response_data); |
| 6285 | |
| 6286 | // Empty the current queue. This is necessary because idle sockets are |
| 6287 | // added to the connection pool asynchronously with a PostTask. |
| 6288 | base::RunLoop().RunUntilIdle(); |
| 6289 | |
| 6290 | // We now check to make sure the socket was added back to the pool. |
| 6291 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 6292 | |
| 6293 | // Idle sockets should be flushed now. |
| 6294 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 6295 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 6296 | base::RunLoop().RunUntilIdle(); |
| 6297 | |
| 6298 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 6299 | } |
| 6300 | |
| 6301 | // Grab an SSL socket, use it, and put it back into the pool. Then, make |
| 6302 | // low memory notification and ensure the socket pool is flushed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6303 | TEST_F(HttpNetworkTransactionTest, FlushSSLSocketPoolOnLowMemoryNotifications) { |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6304 | HttpRequestInfo request; |
| 6305 | request.method = "GET"; |
| 6306 | request.url = GURL("https://www.example.org/"); |
| 6307 | request.load_flags = 0; |
| 6308 | |
| 6309 | MockWrite data_writes[] = { |
| 6310 | MockWrite("GET / HTTP/1.1\r\n" |
| 6311 | "Host: www.example.org\r\n" |
| 6312 | "Connection: keep-alive\r\n\r\n"), |
| 6313 | }; |
| 6314 | |
| 6315 | MockRead data_reads[] = { |
| 6316 | MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
| 6317 | MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; |
| 6318 | |
| 6319 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 6320 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 6321 | |
| 6322 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 6323 | arraysize(data_writes)); |
| 6324 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6325 | |
| 6326 | TestCompletionCallback callback; |
| 6327 | |
| 6328 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 6329 | std::unique_ptr<HttpTransaction> trans( |
| 6330 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 6331 | |
| 6332 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 6333 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 6334 | |
| 6335 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 6336 | |
| 6337 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6338 | ASSERT_TRUE(response); |
| 6339 | ASSERT_TRUE(response->headers); |
| 6340 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6341 | |
| 6342 | // Make memory critical notification and ensure the transaction still has been |
| 6343 | // operating right. |
| 6344 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 6345 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 6346 | base::RunLoop().RunUntilIdle(); |
| 6347 | |
| 6348 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 6349 | |
| 6350 | std::string response_data; |
| 6351 | rv = ReadTransaction(trans.get(), &response_data); |
| 6352 | EXPECT_THAT(rv, IsOk()); |
| 6353 | EXPECT_EQ("hello world", response_data); |
| 6354 | |
| 6355 | // Empty the current queue. This is necessary because idle sockets are |
| 6356 | // added to the connection pool asynchronously with a PostTask. |
| 6357 | base::RunLoop().RunUntilIdle(); |
| 6358 | |
| 6359 | // We now check to make sure the socket was added back to the pool. |
| 6360 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 6361 | |
| 6362 | // Make memory notification once again and ensure idle socket is closed. |
| 6363 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 6364 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 6365 | base::RunLoop().RunUntilIdle(); |
| 6366 | |
| 6367 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 6368 | } |
| 6369 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6370 | // Make sure that we recycle a socket after a zero-length response. |
| 6371 | // http://crbug.com/9880 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6372 | TEST_F(HttpNetworkTransactionTest, RecycleSocketAfterZeroContentLength) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6373 | HttpRequestInfo request; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6374 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6375 | request.url = GURL( |
| 6376 | "http://www.example.org/csi?v=3&s=web&action=&" |
| 6377 | "tran=undefined&ei=mAXcSeegAo-SMurloeUN&" |
| 6378 | "e=17259,18167,19592,19773,19981,20133,20173,20233&" |
| 6379 | "rt=prt.2642,ol.2649,xjs.2951"); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6380 | request.load_flags = 0; |
| 6381 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6382 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6383 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6384 | MockRead data_reads[] = { |
| 6385 | MockRead("HTTP/1.1 204 No Content\r\n" |
| 6386 | "Content-Length: 0\r\n" |
| 6387 | "Content-Type: text/html\r\n\r\n"), |
| 6388 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6389 | MockRead(SYNCHRONOUS, OK), |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6390 | }; |
| 6391 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6392 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6393 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6394 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 6395 | // Transaction must be created after the MockReads, so it's destroyed before |
| 6396 | // them. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6397 | std::unique_ptr<HttpTransaction> trans( |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 6398 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 6399 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6400 | TestCompletionCallback callback; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6401 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6402 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6403 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6404 | |
| 6405 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6406 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6407 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6408 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6409 | ASSERT_TRUE(response); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6410 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6411 | EXPECT_TRUE(response->headers); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6412 | std::string status_line = response->headers->GetStatusLine(); |
| 6413 | EXPECT_EQ("HTTP/1.1 204 No Content", status_line); |
| 6414 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6415 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6416 | |
| 6417 | std::string response_data; |
| 6418 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6419 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6420 | EXPECT_EQ("", response_data); |
| 6421 | |
| 6422 | // Empty the current queue. This is necessary because idle sockets are |
| 6423 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6424 | base::RunLoop().RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6425 | |
| 6426 | // 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] | 6427 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6428 | } |
| 6429 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6430 | TEST_F(HttpNetworkTransactionTest, ResendRequestOnWriteBodyError) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6431 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 6432 | element_readers.push_back( |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6433 | base::WrapUnique(new UploadBytesElementReader("foo", 3))); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 6434 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 6435 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6436 | HttpRequestInfo request[2]; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6437 | // Transaction 1: a GET request that succeeds. The socket is recycled |
| 6438 | // after use. |
| 6439 | request[0].method = "GET"; |
| 6440 | request[0].url = GURL("http://www.google.com/"); |
| 6441 | request[0].load_flags = 0; |
| 6442 | // Transaction 2: a POST request. Reuses the socket kept alive from |
| 6443 | // transaction 1. The first attempts fails when writing the POST data. |
| 6444 | // This causes the transaction to retry with a new socket. The second |
| 6445 | // attempt succeeds. |
| 6446 | request[1].method = "POST"; |
| 6447 | request[1].url = GURL("http://www.google.com/login.cgi"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 6448 | request[1].upload_data_stream = &upload_data_stream; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6449 | request[1].load_flags = 0; |
| 6450 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6451 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6452 | |
| 6453 | // The first socket is used for transaction 1 and the first attempt of |
| 6454 | // transaction 2. |
| 6455 | |
| 6456 | // The response of transaction 1. |
| 6457 | MockRead data_reads1[] = { |
| 6458 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\n"), |
| 6459 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6460 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6461 | }; |
| 6462 | // The mock write results of transaction 1 and the first attempt of |
| 6463 | // transaction 2. |
| 6464 | MockWrite data_writes1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6465 | MockWrite(SYNCHRONOUS, 64), // GET |
| 6466 | MockWrite(SYNCHRONOUS, 93), // POST |
| 6467 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_ABORTED), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6468 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6469 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6470 | data_writes1, arraysize(data_writes1)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6471 | |
| 6472 | // The second socket is used for the second attempt of transaction 2. |
| 6473 | |
| 6474 | // The response of transaction 2. |
| 6475 | MockRead data_reads2[] = { |
| 6476 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 7\r\n\r\n"), |
| 6477 | MockRead("welcome"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6478 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6479 | }; |
| 6480 | // The mock write results of the second attempt of transaction 2. |
| 6481 | MockWrite data_writes2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6482 | MockWrite(SYNCHRONOUS, 93), // POST |
| 6483 | MockWrite(SYNCHRONOUS, 3), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6484 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6485 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6486 | data_writes2, arraysize(data_writes2)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6487 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6488 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6489 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6490 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 6491 | const char* const kExpectedResponseData[] = { |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6492 | "hello world", "welcome" |
| 6493 | }; |
| 6494 | |
| 6495 | for (int i = 0; i < 2; ++i) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6496 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6497 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6498 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6499 | TestCompletionCallback callback; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6500 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6501 | int rv = trans->Start(&request[i], callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6502 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6503 | |
| 6504 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6505 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6506 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6507 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6508 | ASSERT_TRUE(response); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6509 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6510 | EXPECT_TRUE(response->headers); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6511 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6512 | |
| 6513 | std::string response_data; |
| 6514 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6515 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6516 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
| 6517 | } |
| 6518 | } |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6519 | |
| 6520 | // Test the request-challenge-retry sequence for basic auth when there is |
| 6521 | // 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] | 6522 | // it fails the identity from the URL is used to answer the challenge. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6523 | TEST_F(HttpNetworkTransactionTest, AuthIdentityInURL) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6524 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6525 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6526 | request.url = GURL("http://foo:b@[email protected]/"); |
[email protected] | 7b08ba6 | 2012-02-10 20:19:41 | [diff] [blame] | 6527 | request.load_flags = LOAD_NORMAL; |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 6528 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6529 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 6530 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6531 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6532 | |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 6533 | // The password contains an escaped character -- for this test to pass it |
| 6534 | // will need to be unescaped by HttpNetworkTransaction. |
| 6535 | EXPECT_EQ("b%40r", request.url.password()); |
| 6536 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6537 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6538 | MockWrite( |
| 6539 | "GET / HTTP/1.1\r\n" |
| 6540 | "Host: www.example.org\r\n" |
| 6541 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6542 | }; |
| 6543 | |
| 6544 | MockRead data_reads1[] = { |
| 6545 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6546 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6547 | MockRead("Content-Length: 10\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6548 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6549 | }; |
| 6550 | |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6551 | // After the challenge above, the transaction will be restarted using the |
| 6552 | // identity from the url (foo, b@r) to answer the challenge. |
| 6553 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6554 | MockWrite( |
| 6555 | "GET / HTTP/1.1\r\n" |
| 6556 | "Host: www.example.org\r\n" |
| 6557 | "Connection: keep-alive\r\n" |
| 6558 | "Authorization: Basic Zm9vOmJAcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6559 | }; |
| 6560 | |
| 6561 | MockRead data_reads2[] = { |
| 6562 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6563 | MockRead("Content-Length: 100\r\n\r\n"), |
| 6564 | MockRead(SYNCHRONOUS, OK), |
| 6565 | }; |
| 6566 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6567 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6568 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6569 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6570 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6571 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6572 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6573 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6574 | TestCompletionCallback callback1; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6575 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6576 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6577 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6578 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6579 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 6580 | |
| 6581 | TestCompletionCallback callback2; |
| 6582 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6583 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6584 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6585 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6586 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 6587 | |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6588 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6589 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6590 | |
| 6591 | // There is no challenge info, since the identity in URL worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6592 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6593 | |
| 6594 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6595 | |
| 6596 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6597 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6598 | } |
| 6599 | |
| 6600 | // Test the request-challenge-retry sequence for basic auth when there is an |
| 6601 | // incorrect identity in the URL. The identity from the URL should be used only |
| 6602 | // once. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6603 | TEST_F(HttpNetworkTransactionTest, WrongAuthIdentityInURL) { |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6604 | HttpRequestInfo request; |
| 6605 | request.method = "GET"; |
| 6606 | // Note: the URL has a username:password in it. The password "baz" is |
| 6607 | // wrong (should be "bar"). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6608 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6609 | |
| 6610 | request.load_flags = LOAD_NORMAL; |
| 6611 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6612 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 6613 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6614 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6615 | |
| 6616 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6617 | MockWrite( |
| 6618 | "GET / HTTP/1.1\r\n" |
| 6619 | "Host: www.example.org\r\n" |
| 6620 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6621 | }; |
| 6622 | |
| 6623 | MockRead data_reads1[] = { |
| 6624 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6625 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6626 | MockRead("Content-Length: 10\r\n\r\n"), |
| 6627 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 6628 | }; |
| 6629 | |
| 6630 | // After the challenge above, the transaction will be restarted using the |
| 6631 | // identity from the url (foo, baz) to answer the challenge. |
| 6632 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6633 | MockWrite( |
| 6634 | "GET / HTTP/1.1\r\n" |
| 6635 | "Host: www.example.org\r\n" |
| 6636 | "Connection: keep-alive\r\n" |
| 6637 | "Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6638 | }; |
| 6639 | |
| 6640 | MockRead data_reads2[] = { |
| 6641 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6642 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6643 | MockRead("Content-Length: 10\r\n\r\n"), |
| 6644 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 6645 | }; |
| 6646 | |
| 6647 | // After the challenge above, the transaction will be restarted using the |
| 6648 | // identity supplied by the user (foo, bar) to answer the challenge. |
| 6649 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6650 | MockWrite( |
| 6651 | "GET / HTTP/1.1\r\n" |
| 6652 | "Host: www.example.org\r\n" |
| 6653 | "Connection: keep-alive\r\n" |
| 6654 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6655 | }; |
| 6656 | |
| 6657 | MockRead data_reads3[] = { |
| 6658 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6659 | MockRead("Content-Length: 100\r\n\r\n"), |
| 6660 | MockRead(SYNCHRONOUS, OK), |
| 6661 | }; |
| 6662 | |
| 6663 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6664 | data_writes1, arraysize(data_writes1)); |
| 6665 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6666 | data_writes2, arraysize(data_writes2)); |
| 6667 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 6668 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6669 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6670 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 6671 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6672 | |
| 6673 | TestCompletionCallback callback1; |
| 6674 | |
| 6675 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6676 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6677 | |
| 6678 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6679 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6680 | |
| 6681 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 6682 | TestCompletionCallback callback2; |
| 6683 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6684 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6685 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6686 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6687 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 6688 | |
| 6689 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6690 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6691 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 6692 | |
| 6693 | TestCompletionCallback callback3; |
| 6694 | rv = trans->RestartWithAuth( |
| 6695 | AuthCredentials(kFoo, kBar), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6696 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6697 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6698 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6699 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 6700 | |
| 6701 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6702 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6703 | |
| 6704 | // There is no challenge info, since the identity worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6705 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6706 | |
| 6707 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6708 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 6709 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6710 | base::RunLoop().RunUntilIdle(); |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 6711 | } |
| 6712 | |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6713 | |
| 6714 | // Test the request-challenge-retry sequence for basic auth when there is a |
| 6715 | // correct identity in the URL, but its use is being suppressed. The identity |
| 6716 | // from the URL should never be used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6717 | TEST_F(HttpNetworkTransactionTest, AuthIdentityInURLSuppressed) { |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6718 | HttpRequestInfo request; |
| 6719 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6720 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6721 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
| 6722 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6723 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 6724 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6725 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6726 | |
| 6727 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6728 | MockWrite( |
| 6729 | "GET / HTTP/1.1\r\n" |
| 6730 | "Host: www.example.org\r\n" |
| 6731 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6732 | }; |
| 6733 | |
| 6734 | MockRead data_reads1[] = { |
| 6735 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6736 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6737 | MockRead("Content-Length: 10\r\n\r\n"), |
| 6738 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 6739 | }; |
| 6740 | |
| 6741 | // After the challenge above, the transaction will be restarted using the |
| 6742 | // identity supplied by the user, not the one in the URL, to answer the |
| 6743 | // challenge. |
| 6744 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6745 | MockWrite( |
| 6746 | "GET / HTTP/1.1\r\n" |
| 6747 | "Host: www.example.org\r\n" |
| 6748 | "Connection: keep-alive\r\n" |
| 6749 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6750 | }; |
| 6751 | |
| 6752 | MockRead data_reads3[] = { |
| 6753 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6754 | MockRead("Content-Length: 100\r\n\r\n"), |
| 6755 | MockRead(SYNCHRONOUS, OK), |
| 6756 | }; |
| 6757 | |
| 6758 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6759 | data_writes1, arraysize(data_writes1)); |
| 6760 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 6761 | data_writes3, arraysize(data_writes3)); |
| 6762 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6763 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 6764 | |
| 6765 | TestCompletionCallback callback1; |
| 6766 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6767 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6768 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6769 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6770 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 6771 | |
| 6772 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6773 | ASSERT_TRUE(response); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6774 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 6775 | |
| 6776 | TestCompletionCallback callback3; |
| 6777 | rv = trans->RestartWithAuth( |
| 6778 | AuthCredentials(kFoo, kBar), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6779 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6780 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6781 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6782 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 6783 | |
| 6784 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6785 | ASSERT_TRUE(response); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6786 | |
| 6787 | // There is no challenge info, since the identity worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6788 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6789 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6790 | |
| 6791 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6792 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6793 | } |
| 6794 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6795 | // Test that previously tried username/passwords for a realm get re-used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6796 | TEST_F(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6797 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6798 | |
| 6799 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 6800 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6801 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6802 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6803 | request.url = GURL("http://www.example.org/x/y/z"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6804 | request.load_flags = 0; |
| 6805 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6806 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6807 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6808 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6809 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6810 | MockWrite( |
| 6811 | "GET /x/y/z HTTP/1.1\r\n" |
| 6812 | "Host: www.example.org\r\n" |
| 6813 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6814 | }; |
| 6815 | |
| 6816 | MockRead data_reads1[] = { |
| 6817 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6818 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6819 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6820 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6821 | }; |
| 6822 | |
| 6823 | // Resend with authorization (username=foo, password=bar) |
| 6824 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6825 | MockWrite( |
| 6826 | "GET /x/y/z HTTP/1.1\r\n" |
| 6827 | "Host: www.example.org\r\n" |
| 6828 | "Connection: keep-alive\r\n" |
| 6829 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6830 | }; |
| 6831 | |
| 6832 | // Sever accepts the authorization. |
| 6833 | MockRead data_reads2[] = { |
| 6834 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6835 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6836 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6837 | }; |
| 6838 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6839 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6840 | data_writes1, arraysize(data_writes1)); |
| 6841 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6842 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6843 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6844 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6845 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6846 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6847 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6848 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6849 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6850 | |
| 6851 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6852 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6853 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6854 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6855 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6856 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6857 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6858 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6859 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6860 | rv = trans->RestartWithAuth( |
| 6861 | AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6862 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6863 | |
| 6864 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6865 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6866 | |
| 6867 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6868 | ASSERT_TRUE(response); |
| 6869 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6870 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6871 | } |
| 6872 | |
| 6873 | // ------------------------------------------------------------------------ |
| 6874 | |
| 6875 | // Transaction 2: authenticate (foo2, bar2) on MyRealm2 |
| 6876 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6877 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6878 | request.method = "GET"; |
| 6879 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 6880 | // protection space as MyRealm1. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6881 | request.url = GURL("http://www.example.org/x/y/a/b"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6882 | request.load_flags = 0; |
| 6883 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6884 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6885 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6886 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6887 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6888 | MockWrite( |
| 6889 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 6890 | "Host: www.example.org\r\n" |
| 6891 | "Connection: keep-alive\r\n" |
| 6892 | // Send preemptive authorization for MyRealm1 |
| 6893 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6894 | }; |
| 6895 | |
| 6896 | // The server didn't like the preemptive authorization, and |
| 6897 | // challenges us for a different realm (MyRealm2). |
| 6898 | MockRead data_reads1[] = { |
| 6899 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6900 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm2\"\r\n"), |
| 6901 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6902 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6903 | }; |
| 6904 | |
| 6905 | // Resend with authorization for MyRealm2 (username=foo2, password=bar2) |
| 6906 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6907 | MockWrite( |
| 6908 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 6909 | "Host: www.example.org\r\n" |
| 6910 | "Connection: keep-alive\r\n" |
| 6911 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6912 | }; |
| 6913 | |
| 6914 | // Sever accepts the authorization. |
| 6915 | MockRead data_reads2[] = { |
| 6916 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6917 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6918 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6919 | }; |
| 6920 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6921 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6922 | data_writes1, arraysize(data_writes1)); |
| 6923 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6924 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6925 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6926 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6927 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6928 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6929 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6930 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6931 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6932 | |
| 6933 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6934 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6935 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6936 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6937 | ASSERT_TRUE(response); |
| 6938 | ASSERT_TRUE(response->auth_challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6939 | EXPECT_FALSE(response->auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 6940 | EXPECT_EQ("http://www.example.org", |
| 6941 | response->auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6942 | EXPECT_EQ("MyRealm2", response->auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 6943 | EXPECT_EQ(kBasicAuthScheme, response->auth_challenge->scheme); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6944 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6945 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6946 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6947 | rv = trans->RestartWithAuth( |
| 6948 | AuthCredentials(kFoo2, kBar2), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6949 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6950 | |
| 6951 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6952 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6953 | |
| 6954 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6955 | ASSERT_TRUE(response); |
| 6956 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6957 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6958 | } |
| 6959 | |
| 6960 | // ------------------------------------------------------------------------ |
| 6961 | |
| 6962 | // Transaction 3: Resend a request in MyRealm's protection space -- |
| 6963 | // succeed with preemptive authorization. |
| 6964 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6965 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6966 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6967 | request.url = GURL("http://www.example.org/x/y/z2"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6968 | request.load_flags = 0; |
| 6969 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6970 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6971 | new HttpNetworkTransaction(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 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [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 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [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 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7019 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7020 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7021 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7022 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7023 | MockWrite( |
| 7024 | "GET /x/1 HTTP/1.1\r\n" |
| 7025 | "Host: www.example.org\r\n" |
| 7026 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7027 | }; |
| 7028 | |
| 7029 | MockRead data_reads1[] = { |
| 7030 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7031 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7032 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7033 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7034 | }; |
| 7035 | |
| 7036 | // Resend with authorization from MyRealm's cache. |
| 7037 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7038 | MockWrite( |
| 7039 | "GET /x/1 HTTP/1.1\r\n" |
| 7040 | "Host: www.example.org\r\n" |
| 7041 | "Connection: keep-alive\r\n" |
| 7042 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7043 | }; |
| 7044 | |
| 7045 | // Sever accepts the authorization. |
| 7046 | MockRead data_reads2[] = { |
| 7047 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7048 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7049 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7050 | }; |
| 7051 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7052 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7053 | data_writes1, arraysize(data_writes1)); |
| 7054 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7055 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7056 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7057 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7058 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7059 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7060 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7061 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7062 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7063 | |
| 7064 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7065 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7066 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7067 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7068 | TestCompletionCallback callback2; |
| 7069 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7070 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7071 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7072 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7073 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 7074 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7075 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7076 | ASSERT_TRUE(response); |
| 7077 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7078 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7079 | } |
| 7080 | |
| 7081 | // ------------------------------------------------------------------------ |
| 7082 | |
| 7083 | // Transaction 5: request a URL in MyRealm, but the server rejects the |
| 7084 | // cached identity. Should invalidate and re-prompt. |
| 7085 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7086 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7087 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7088 | request.url = GURL("http://www.example.org/p/q/t"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7089 | request.load_flags = 0; |
| 7090 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7091 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7092 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7093 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7094 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7095 | MockWrite( |
| 7096 | "GET /p/q/t HTTP/1.1\r\n" |
| 7097 | "Host: www.example.org\r\n" |
| 7098 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7099 | }; |
| 7100 | |
| 7101 | MockRead data_reads1[] = { |
| 7102 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7103 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7104 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7105 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7106 | }; |
| 7107 | |
| 7108 | // Resend with authorization from cache for MyRealm. |
| 7109 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7110 | MockWrite( |
| 7111 | "GET /p/q/t HTTP/1.1\r\n" |
| 7112 | "Host: www.example.org\r\n" |
| 7113 | "Connection: keep-alive\r\n" |
| 7114 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7115 | }; |
| 7116 | |
| 7117 | // Sever rejects the authorization. |
| 7118 | MockRead data_reads2[] = { |
| 7119 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7120 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7121 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7122 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7123 | }; |
| 7124 | |
| 7125 | // At this point we should prompt for new credentials for MyRealm. |
| 7126 | // Restart with username=foo3, password=foo4. |
| 7127 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7128 | MockWrite( |
| 7129 | "GET /p/q/t HTTP/1.1\r\n" |
| 7130 | "Host: www.example.org\r\n" |
| 7131 | "Connection: keep-alive\r\n" |
| 7132 | "Authorization: Basic Zm9vMzpiYXIz\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7133 | }; |
| 7134 | |
| 7135 | // Sever accepts the authorization. |
| 7136 | MockRead data_reads3[] = { |
| 7137 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7138 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7139 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7140 | }; |
| 7141 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7142 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7143 | data_writes1, arraysize(data_writes1)); |
| 7144 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7145 | data_writes2, arraysize(data_writes2)); |
| 7146 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 7147 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7148 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7149 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 7150 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7151 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7152 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7153 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7154 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7155 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7156 | |
| 7157 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7158 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7159 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7160 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7161 | TestCompletionCallback callback2; |
| 7162 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7163 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7164 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7165 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7166 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 7167 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7168 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7169 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7170 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7171 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7172 | TestCompletionCallback callback3; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7173 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7174 | rv = trans->RestartWithAuth( |
| 7175 | AuthCredentials(kFoo3, kBar3), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7176 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7177 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7178 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7179 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7180 | |
| 7181 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7182 | ASSERT_TRUE(response); |
| 7183 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7184 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7185 | } |
| 7186 | } |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7187 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7188 | // Tests that nonce count increments when multiple auth attempts |
| 7189 | // are started with the same nonce. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7190 | TEST_F(HttpNetworkTransactionTest, DigestPreAuthNonceCount) { |
[email protected] | 54fea256 | 2010-11-17 14:40:44 | [diff] [blame] | 7191 | HttpAuthHandlerDigest::Factory* digest_factory = |
| 7192 | new HttpAuthHandlerDigest::Factory(); |
| 7193 | HttpAuthHandlerDigest::FixedNonceGenerator* nonce_generator = |
| 7194 | new HttpAuthHandlerDigest::FixedNonceGenerator("0123456789abcdef"); |
| 7195 | digest_factory->set_nonce_generator(nonce_generator); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7196 | session_deps_.http_auth_handler_factory.reset(digest_factory); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7197 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7198 | |
| 7199 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 7200 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7201 | HttpRequestInfo request; |
| 7202 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7203 | request.url = GURL("http://www.example.org/x/y/z"); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7204 | request.load_flags = 0; |
| 7205 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7206 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7207 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7208 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7209 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7210 | MockWrite( |
| 7211 | "GET /x/y/z HTTP/1.1\r\n" |
| 7212 | "Host: www.example.org\r\n" |
| 7213 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7214 | }; |
| 7215 | |
| 7216 | MockRead data_reads1[] = { |
| 7217 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7218 | MockRead("WWW-Authenticate: Digest realm=\"digestive\", nonce=\"OU812\", " |
| 7219 | "algorithm=MD5, qop=\"auth\"\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7220 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7221 | }; |
| 7222 | |
| 7223 | // Resend with authorization (username=foo, password=bar) |
| 7224 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7225 | MockWrite( |
| 7226 | "GET /x/y/z HTTP/1.1\r\n" |
| 7227 | "Host: www.example.org\r\n" |
| 7228 | "Connection: keep-alive\r\n" |
| 7229 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 7230 | "nonce=\"OU812\", uri=\"/x/y/z\", algorithm=MD5, " |
| 7231 | "response=\"03ffbcd30add722589c1de345d7a927f\", qop=auth, " |
| 7232 | "nc=00000001, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7233 | }; |
| 7234 | |
| 7235 | // Sever accepts the authorization. |
| 7236 | MockRead data_reads2[] = { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 7237 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7238 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7239 | }; |
| 7240 | |
| 7241 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7242 | data_writes1, arraysize(data_writes1)); |
| 7243 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7244 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7245 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7246 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7247 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7248 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7249 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7250 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7251 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7252 | |
| 7253 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7254 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7255 | |
| 7256 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7257 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7258 | EXPECT_TRUE(CheckDigestServerAuth(response->auth_challenge.get())); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7259 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7260 | TestCompletionCallback callback2; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7261 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7262 | rv = trans->RestartWithAuth( |
| 7263 | AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7264 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7265 | |
| 7266 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7267 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7268 | |
| 7269 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7270 | ASSERT_TRUE(response); |
| 7271 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7272 | } |
| 7273 | |
| 7274 | // ------------------------------------------------------------------------ |
| 7275 | |
| 7276 | // Transaction 2: Request another resource in digestive's protection space. |
| 7277 | // This will preemptively add an Authorization header which should have an |
| 7278 | // "nc" value of 2 (as compared to 1 in the first use. |
| 7279 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7280 | HttpRequestInfo request; |
| 7281 | request.method = "GET"; |
| 7282 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 7283 | // protection space as digest. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7284 | request.url = GURL("http://www.example.org/x/y/a/b"); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7285 | request.load_flags = 0; |
| 7286 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7287 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7288 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7289 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7290 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7291 | MockWrite( |
| 7292 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 7293 | "Host: www.example.org\r\n" |
| 7294 | "Connection: keep-alive\r\n" |
| 7295 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 7296 | "nonce=\"OU812\", uri=\"/x/y/a/b\", algorithm=MD5, " |
| 7297 | "response=\"d6f9a2c07d1c5df7b89379dca1269b35\", qop=auth, " |
| 7298 | "nc=00000002, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7299 | }; |
| 7300 | |
| 7301 | // Sever accepts the authorization. |
| 7302 | MockRead data_reads1[] = { |
| 7303 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7304 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7305 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7306 | }; |
| 7307 | |
| 7308 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7309 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7310 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7311 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7312 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7313 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7314 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7315 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7316 | |
| 7317 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7318 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7319 | |
| 7320 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7321 | ASSERT_TRUE(response); |
| 7322 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7323 | } |
| 7324 | } |
| 7325 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7326 | // Test the ResetStateForRestart() private method. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7327 | TEST_F(HttpNetworkTransactionTest, ResetStateForRestart) { |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7328 | // Create a transaction (the dependencies aren't important). |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7329 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 7330 | std::unique_ptr<HttpNetworkTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7331 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7332 | |
| 7333 | // Setup some state (which we expect ResetStateForRestart() will clear). |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7334 | trans->read_buf_ = new IOBuffer(15); |
| 7335 | trans->read_buf_len_ = 15; |
[email protected] | b94f92d | 2010-10-27 16:45:20 | [diff] [blame] | 7336 | trans->request_headers_.SetHeader("Authorization", "NTLM"); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7337 | |
| 7338 | // Setup state in response_ |
[email protected] | a7e4131 | 2009-12-16 23:18:14 | [diff] [blame] | 7339 | HttpResponseInfo* response = &trans->response_; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7340 | response->auth_challenge = new AuthChallengeInfo(); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 7341 | response->ssl_info.cert_status = static_cast<CertStatus>(-1); // Nonsensical. |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7342 | response->response_time = base::Time::Now(); |
| 7343 | response->was_cached = true; // (Wouldn't ever actually be true...) |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7344 | |
| 7345 | { // Setup state for response_.vary_data |
| 7346 | HttpRequestInfo request; |
| 7347 | std::string temp("HTTP/1.1 200 OK\nVary: foo, bar\n\n"); |
| 7348 | std::replace(temp.begin(), temp.end(), '\n', '\0'); |
[email protected] | ad8e04a | 2010-11-01 04:16:27 | [diff] [blame] | 7349 | scoped_refptr<HttpResponseHeaders> headers(new HttpResponseHeaders(temp)); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 7350 | request.extra_headers.SetHeader("Foo", "1"); |
| 7351 | request.extra_headers.SetHeader("bar", "23"); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7352 | EXPECT_TRUE(response->vary_data.Init(request, *headers.get())); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7353 | } |
| 7354 | |
| 7355 | // Cause the above state to be reset. |
| 7356 | trans->ResetStateForRestart(); |
| 7357 | |
| 7358 | // Verify that the state that needed to be reset, has been reset. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7359 | EXPECT_FALSE(trans->read_buf_); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7360 | EXPECT_EQ(0, trans->read_buf_len_); |
[email protected] | b94f92d | 2010-10-27 16:45:20 | [diff] [blame] | 7361 | EXPECT_TRUE(trans->request_headers_.IsEmpty()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7362 | EXPECT_FALSE(response->auth_challenge); |
| 7363 | EXPECT_FALSE(response->headers); |
[email protected] | 34f4094 | 2010-10-04 00:34:04 | [diff] [blame] | 7364 | EXPECT_FALSE(response->was_cached); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 7365 | EXPECT_EQ(0U, response->ssl_info.cert_status); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7366 | EXPECT_FALSE(response->vary_data.is_valid()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7367 | } |
| 7368 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7369 | // Test HTTPS connections to a site with a bad certificate |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7370 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificate) { |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7371 | HttpRequestInfo request; |
| 7372 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7373 | request.url = GURL("https://www.example.org/"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7374 | request.load_flags = 0; |
| 7375 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7376 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 7377 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7378 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7379 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7380 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7381 | MockWrite( |
| 7382 | "GET / HTTP/1.1\r\n" |
| 7383 | "Host: www.example.org\r\n" |
| 7384 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7385 | }; |
| 7386 | |
| 7387 | MockRead data_reads[] = { |
| 7388 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7389 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7390 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7391 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7392 | }; |
| 7393 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 7394 | StaticSocketDataProvider ssl_bad_certificate; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7395 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7396 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7397 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 7398 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7399 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7400 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 7401 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7402 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 7403 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7404 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7405 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7406 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7407 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
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, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7412 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7413 | rv = trans->RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7414 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7415 | |
| 7416 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7417 | EXPECT_THAT(rv, IsOk()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7418 | |
| 7419 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7420 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7421 | ASSERT_TRUE(response); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7422 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7423 | } |
| 7424 | |
| 7425 | // Test HTTPS connections to a site with a bad certificate, going through a |
| 7426 | // proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7427 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7428 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7429 | |
| 7430 | HttpRequestInfo request; |
| 7431 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7432 | request.url = GURL("https://www.example.org/"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7433 | request.load_flags = 0; |
| 7434 | |
| 7435 | MockWrite proxy_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7436 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7437 | "Host: www.example.org:443\r\n" |
| 7438 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7439 | }; |
| 7440 | |
| 7441 | MockRead proxy_reads[] = { |
| 7442 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7443 | MockRead(SYNCHRONOUS, OK) |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7444 | }; |
| 7445 | |
| 7446 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7447 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7448 | "Host: www.example.org:443\r\n" |
| 7449 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 7450 | MockWrite("GET / HTTP/1.1\r\n" |
| 7451 | "Host: www.example.org\r\n" |
| 7452 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7453 | }; |
| 7454 | |
| 7455 | MockRead data_reads[] = { |
| 7456 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 7457 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7458 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7459 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7460 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7461 | }; |
| 7462 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7463 | StaticSocketDataProvider ssl_bad_certificate( |
| 7464 | proxy_reads, arraysize(proxy_reads), |
| 7465 | proxy_writes, arraysize(proxy_writes)); |
| 7466 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7467 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7468 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 7469 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7470 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7471 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 7472 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7473 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 7474 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7475 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7476 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7477 | |
| 7478 | for (int i = 0; i < 2; i++) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7479 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7480 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7481 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 7482 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7483 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7484 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7485 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7486 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7487 | |
| 7488 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7489 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7490 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7491 | rv = trans->RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7492 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7493 | |
| 7494 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7495 | EXPECT_THAT(rv, IsOk()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7496 | |
| 7497 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7498 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7499 | ASSERT_TRUE(response); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7500 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7501 | } |
| 7502 | } |
| 7503 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7504 | |
| 7505 | // Test HTTPS connections to a site, going through an HTTPS proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7506 | TEST_F(HttpNetworkTransactionTest, HTTPSViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7507 | session_deps_.proxy_service = |
| 7508 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7509 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7510 | session_deps_.net_log = &net_log; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7511 | |
| 7512 | HttpRequestInfo request; |
| 7513 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7514 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7515 | request.load_flags = 0; |
| 7516 | |
| 7517 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7518 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7519 | "Host: www.example.org:443\r\n" |
| 7520 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 7521 | MockWrite("GET / HTTP/1.1\r\n" |
| 7522 | "Host: www.example.org\r\n" |
| 7523 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7524 | }; |
| 7525 | |
| 7526 | MockRead data_reads[] = { |
| 7527 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 7528 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 7529 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7530 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7531 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7532 | }; |
| 7533 | |
| 7534 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7535 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7536 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
| 7537 | SSLSocketDataProvider tunnel_ssl(ASYNC, OK); // SSL through the tunnel |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7538 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7539 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7540 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
| 7541 | session_deps_.socket_factory->AddSSLSocketDataProvider(&tunnel_ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7542 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7543 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7544 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7545 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 7546 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7547 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7548 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7549 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7550 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7551 | |
| 7552 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7553 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7554 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7555 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7556 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7557 | |
| 7558 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 7559 | EXPECT_EQ(200, response->headers->response_code()); |
| 7560 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7561 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7562 | |
| 7563 | LoadTimingInfo load_timing_info; |
| 7564 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7565 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 7566 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7567 | } |
| 7568 | |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7569 | // Test an HTTPS Proxy's ability to redirect a CONNECT request |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7570 | TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7571 | session_deps_.proxy_service = |
| 7572 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7573 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7574 | session_deps_.net_log = &net_log; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7575 | |
| 7576 | HttpRequestInfo request; |
| 7577 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7578 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7579 | request.load_flags = 0; |
| 7580 | |
| 7581 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7582 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7583 | "Host: www.example.org:443\r\n" |
| 7584 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7585 | }; |
| 7586 | |
| 7587 | MockRead data_reads[] = { |
| 7588 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 7589 | MockRead("Location: http://login.example.com/\r\n"), |
| 7590 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7591 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7592 | }; |
| 7593 | |
| 7594 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7595 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7596 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7597 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7598 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7599 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7600 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7601 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7602 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7603 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 7604 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7605 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7606 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7607 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7608 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7609 | |
| 7610 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7611 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7612 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7613 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7614 | ASSERT_TRUE(response); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7615 | |
| 7616 | EXPECT_EQ(302, response->headers->response_code()); |
| 7617 | std::string url; |
| 7618 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 7619 | EXPECT_EQ("http://login.example.com/", url); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7620 | |
| 7621 | // In the case of redirects from proxies, HttpNetworkTransaction returns |
| 7622 | // timing for the proxy connection instead of the connection to the host, |
| 7623 | // and no send / receive times. |
| 7624 | // See HttpNetworkTransaction::OnHttpsProxyTunnelResponse. |
| 7625 | LoadTimingInfo load_timing_info; |
| 7626 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7627 | |
| 7628 | EXPECT_FALSE(load_timing_info.socket_reused); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 7629 | EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7630 | |
| 7631 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 7632 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 7633 | load_timing_info.proxy_resolve_end); |
| 7634 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 7635 | load_timing_info.connect_timing.connect_start); |
| 7636 | ExpectConnectTimingHasTimes( |
| 7637 | load_timing_info.connect_timing, |
| 7638 | CONNECT_TIMING_HAS_DNS_TIMES | CONNECT_TIMING_HAS_SSL_TIMES); |
| 7639 | |
| 7640 | EXPECT_TRUE(load_timing_info.send_start.is_null()); |
| 7641 | EXPECT_TRUE(load_timing_info.send_end.is_null()); |
| 7642 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7643 | } |
| 7644 | |
| 7645 | // Test an HTTPS (SPDY) Proxy's ability to redirect a CONNECT request |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7646 | TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaSpdyProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7647 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7648 | |
| 7649 | HttpRequestInfo request; |
| 7650 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7651 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7652 | request.load_flags = 0; |
| 7653 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7654 | SpdySerializedFrame conn(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7655 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7656 | SpdySerializedFrame goaway( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 7657 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7658 | MockWrite data_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7659 | CreateMockWrite(conn, 0, SYNCHRONOUS), |
| 7660 | CreateMockWrite(goaway, 2, SYNCHRONOUS), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7661 | }; |
| 7662 | |
| 7663 | static const char* const kExtraHeaders[] = { |
| 7664 | "location", |
| 7665 | "http://login.example.com/", |
| 7666 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 7667 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7668 | "302 Redirect", kExtraHeaders, arraysize(kExtraHeaders) / 2, 1)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7669 | MockRead data_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7670 | CreateMockRead(resp, 1), MockRead(ASYNC, 0, 3), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7671 | }; |
| 7672 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7673 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 7674 | arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7675 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 7676 | proxy_ssl.next_proto = kProtoHTTP2; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7677 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7678 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7679 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7680 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7681 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7682 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7683 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 7684 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7685 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7686 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7687 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7688 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7689 | |
| 7690 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7691 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7692 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7693 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7694 | ASSERT_TRUE(response); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7695 | |
| 7696 | EXPECT_EQ(302, response->headers->response_code()); |
| 7697 | std::string url; |
| 7698 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 7699 | EXPECT_EQ("http://login.example.com/", url); |
| 7700 | } |
| 7701 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 7702 | // Test that an HTTPS proxy's response to a CONNECT request is filtered. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7703 | TEST_F(HttpNetworkTransactionTest, ErrorResponseToHttpsConnectViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7704 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7705 | |
| 7706 | HttpRequestInfo request; |
| 7707 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7708 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7709 | request.load_flags = 0; |
| 7710 | |
| 7711 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7712 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7713 | "Host: www.example.org:443\r\n" |
| 7714 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7715 | }; |
| 7716 | |
| 7717 | MockRead data_reads[] = { |
| 7718 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 7719 | MockRead("Content-Length: 23\r\n\r\n"), |
| 7720 | MockRead("The host does not exist"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7721 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7722 | }; |
| 7723 | |
| 7724 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7725 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7726 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7727 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7728 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7729 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7730 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7731 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7732 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7733 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 7734 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7735 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7736 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7737 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7738 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7739 | |
| 7740 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7741 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7742 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 7743 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7744 | } |
| 7745 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 7746 | // Test that a SPDY proxy's response to a CONNECT request is filtered. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7747 | TEST_F(HttpNetworkTransactionTest, ErrorResponseToHttpsConnectViaSpdyProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7748 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7749 | |
| 7750 | HttpRequestInfo request; |
| 7751 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7752 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7753 | request.load_flags = 0; |
| 7754 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7755 | SpdySerializedFrame conn(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7756 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7757 | SpdySerializedFrame rst( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 7758 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7759 | MockWrite data_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7760 | CreateMockWrite(conn, 0), CreateMockWrite(rst, 3), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7761 | }; |
| 7762 | |
| 7763 | static const char* const kExtraHeaders[] = { |
| 7764 | "location", |
| 7765 | "http://login.example.com/", |
| 7766 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 7767 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7768 | "404 Not Found", kExtraHeaders, arraysize(kExtraHeaders) / 2, 1)); |
| 7769 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 7770 | 1, "The host does not exist", 23, true)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7771 | MockRead data_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7772 | CreateMockRead(resp, 1), CreateMockRead(body, 2), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7773 | MockRead(ASYNC, 0, 4), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7774 | }; |
| 7775 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7776 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 7777 | arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7778 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 7779 | proxy_ssl.next_proto = kProtoHTTP2; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7780 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7781 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7782 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7783 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7784 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7785 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7786 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 7787 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7788 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7789 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7790 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7791 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7792 | |
| 7793 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7794 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7795 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 7796 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7797 | } |
| 7798 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7799 | // Test the request-challenge-retry sequence for basic auth, through |
| 7800 | // a SPDY proxy over a single SPDY session. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7801 | TEST_F(HttpNetworkTransactionTest, BasicAuthSpdyProxy) { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7802 | HttpRequestInfo request; |
| 7803 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7804 | request.url = GURL("https://www.example.org/"); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7805 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 7806 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7807 | |
| 7808 | // Configure against https proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7809 | session_deps_.proxy_service = |
| 7810 | ProxyService::CreateFixedFromPacResult("HTTPS myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7811 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7812 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7813 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7814 | |
| 7815 | // Since we have proxy, should try to establish tunnel. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7816 | SpdySerializedFrame req(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7817 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7818 | SpdySerializedFrame rst( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 7819 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 7820 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7821 | |
| 7822 | // After calling trans->RestartWithAuth(), this is the request we should |
| 7823 | // be issuing -- the final header line contains the credentials. |
| 7824 | const char* const kAuthCredentials[] = { |
| 7825 | "proxy-authorization", "Basic Zm9vOmJhcg==", |
| 7826 | }; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7827 | SpdySerializedFrame connect2(spdy_util_.ConstructSpdyConnect( |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 7828 | kAuthCredentials, arraysize(kAuthCredentials) / 2, 3, LOWEST, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7829 | HostPortPair("www.example.org", 443))); |
| 7830 | // fetch https://www.example.org/ via HTTP |
| 7831 | const char get[] = |
| 7832 | "GET / HTTP/1.1\r\n" |
| 7833 | "Host: www.example.org\r\n" |
| 7834 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7835 | SpdySerializedFrame wrapped_get( |
| 7836 | spdy_util_.ConstructSpdyDataFrame(3, get, strlen(get), false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7837 | |
| 7838 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7839 | CreateMockWrite(req, 0, ASYNC), CreateMockWrite(rst, 2, ASYNC), |
| 7840 | CreateMockWrite(connect2, 3), CreateMockWrite(wrapped_get, 5), |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7841 | }; |
| 7842 | |
| 7843 | // The proxy responds to the connect with a 407, using a persistent |
| 7844 | // connection. |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 7845 | const char kAuthStatus[] = "407"; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7846 | const char* const kAuthChallenge[] = { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7847 | "proxy-authenticate", "Basic realm=\"MyRealm1\"", |
| 7848 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 7849 | SpdySerializedFrame conn_auth_resp(spdy_util_.ConstructSpdyReplyError( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7850 | kAuthStatus, kAuthChallenge, arraysize(kAuthChallenge) / 2, 1)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7851 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 7852 | SpdySerializedFrame conn_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7853 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 7854 | "Content-Length: 5\r\n\r\n"; |
| 7855 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7856 | SpdySerializedFrame wrapped_get_resp( |
| 7857 | spdy_util_.ConstructSpdyDataFrame(3, resp, strlen(resp), false)); |
| 7858 | SpdySerializedFrame wrapped_body( |
| 7859 | spdy_util_.ConstructSpdyDataFrame(3, "hello", 5, false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7860 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7861 | CreateMockRead(conn_auth_resp, 1, ASYNC), |
| 7862 | CreateMockRead(conn_resp, 4, ASYNC), |
| 7863 | CreateMockRead(wrapped_get_resp, 6, ASYNC), |
| 7864 | CreateMockRead(wrapped_body, 7, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7865 | MockRead(ASYNC, OK, 8), // EOF. May or may not be read. |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7866 | }; |
| 7867 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7868 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 7869 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7870 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7871 | // Negotiate SPDY to the proxy |
| 7872 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 7873 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7874 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7875 | // Vanilla SSL to the server |
| 7876 | SSLSocketDataProvider server(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7877 | session_deps_.socket_factory->AddSSLSocketDataProvider(&server); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7878 | |
| 7879 | TestCompletionCallback callback1; |
| 7880 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7881 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7882 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7883 | |
| 7884 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7885 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7886 | |
| 7887 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7888 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 7889 | TestNetLogEntry::List entries; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7890 | log.GetEntries(&entries); |
| 7891 | size_t pos = ExpectLogContainsSomewhere( |
| 7892 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 7893 | NetLog::PHASE_NONE); |
| 7894 | ExpectLogContainsSomewhere( |
| 7895 | entries, pos, |
| 7896 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 7897 | NetLog::PHASE_NONE); |
| 7898 | |
| 7899 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7900 | ASSERT_TRUE(response); |
| 7901 | ASSERT_TRUE(response->headers); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7902 | EXPECT_EQ(407, response->headers->response_code()); |
| 7903 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7904 | EXPECT_TRUE(response->auth_challenge); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 7905 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7906 | |
| 7907 | TestCompletionCallback callback2; |
| 7908 | |
| 7909 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 7910 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7911 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7912 | |
| 7913 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7914 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7915 | |
| 7916 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7917 | ASSERT_TRUE(response); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7918 | |
| 7919 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 7920 | EXPECT_EQ(200, response->headers->response_code()); |
| 7921 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 7922 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 7923 | |
| 7924 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7925 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7926 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7927 | LoadTimingInfo load_timing_info; |
| 7928 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7929 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 7930 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 7931 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7932 | trans.reset(); |
| 7933 | session->CloseAllConnections(); |
| 7934 | } |
| 7935 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7936 | // Test that an explicitly trusted SPDY proxy can push a resource from an |
| 7937 | // origin that is different from that of its associated resource. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7938 | TEST_F(HttpNetworkTransactionTest, CrossOriginSPDYProxyPush) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 7939 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7940 | std::unique_ptr<TestProxyDelegate> proxy_delegate(new TestProxyDelegate()); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 7941 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 7942 | "https://myproxy:443", net::ProxyServer::SCHEME_HTTP)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7943 | HttpRequestInfo request; |
| 7944 | HttpRequestInfo push_request; |
| 7945 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7946 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7947 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7948 | push_request.method = "GET"; |
| 7949 | push_request.url = GURL("http://www.another-origin.com/foo.dat"); |
| 7950 | |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 7951 | // Configure against https proxy server "myproxy:443". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7952 | session_deps_.proxy_service = |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 7953 | ProxyService::CreateFixedFromPacResult("HTTPS myproxy:443"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7954 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7955 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 7956 | |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 7957 | session_deps_.proxy_delegate.reset(proxy_delegate.release()); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 7958 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7959 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7960 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7961 | SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 7962 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7963 | |
| 7964 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7965 | CreateMockWrite(stream1_syn, 0, ASYNC), |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7966 | }; |
| 7967 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7968 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 7969 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7970 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7971 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7972 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7973 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 7974 | NULL, 0, 2, 1, "http://www.another-origin.com/foo.dat")); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 7975 | const char kPushedData[] = "pushed"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7976 | SpdySerializedFrame stream2_body(spdy_util_.ConstructSpdyDataFrame( |
| 7977 | 2, kPushedData, strlen(kPushedData), true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7978 | |
| 7979 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7980 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 7981 | CreateMockRead(stream2_syn, 2, ASYNC), |
| 7982 | CreateMockRead(stream1_body, 3, ASYNC), |
| 7983 | CreateMockRead(stream2_body, 4, ASYNC), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 7984 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), // Force a hang |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7985 | }; |
| 7986 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7987 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 7988 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7989 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7990 | // Negotiate SPDY to the proxy |
| 7991 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 7992 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7993 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7994 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7995 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7996 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7997 | TestCompletionCallback callback; |
| 7998 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7999 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8000 | |
| 8001 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8002 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8003 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8004 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8005 | std::unique_ptr<HttpTransaction> push_trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8006 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 8007 | rv = push_trans->Start(&push_request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8008 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8009 | |
| 8010 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8011 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8012 | const HttpResponseInfo* push_response = push_trans->GetResponseInfo(); |
| 8013 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8014 | ASSERT_TRUE(response); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8015 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 8016 | |
| 8017 | EXPECT_EQ(200, response->headers->response_code()); |
| 8018 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 8019 | |
| 8020 | std::string response_data; |
| 8021 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8022 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8023 | EXPECT_EQ("hello!", response_data); |
| 8024 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8025 | LoadTimingInfo load_timing_info; |
| 8026 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 8027 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8028 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 8029 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8030 | // Verify the pushed stream. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8031 | EXPECT_TRUE(push_response->headers); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8032 | EXPECT_EQ(200, push_response->headers->response_code()); |
| 8033 | |
| 8034 | rv = ReadTransaction(push_trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8035 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8036 | EXPECT_EQ("pushed", response_data); |
| 8037 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8038 | LoadTimingInfo push_load_timing_info; |
| 8039 | EXPECT_TRUE(push_trans->GetLoadTimingInfo(&push_load_timing_info)); |
| 8040 | TestLoadTimingReusedWithPac(push_load_timing_info); |
| 8041 | // The transactions should share a socket ID, despite being for different |
| 8042 | // origins. |
| 8043 | EXPECT_EQ(load_timing_info.socket_log_id, |
| 8044 | push_load_timing_info.socket_log_id); |
| 8045 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8046 | trans.reset(); |
| 8047 | push_trans.reset(); |
| 8048 | session->CloseAllConnections(); |
| 8049 | } |
| 8050 | |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8051 | // Test that an explicitly trusted SPDY proxy cannot push HTTPS content. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8052 | TEST_F(HttpNetworkTransactionTest, CrossOriginProxyPushCorrectness) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8053 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8054 | std::unique_ptr<TestProxyDelegate> proxy_delegate(new TestProxyDelegate()); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8055 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 8056 | "https://myproxy:443", net::ProxyServer::SCHEME_HTTP)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8057 | HttpRequestInfo request; |
| 8058 | |
| 8059 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8060 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8061 | |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8062 | session_deps_.proxy_service = |
| 8063 | ProxyService::CreateFixed("https://myproxy:443"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8064 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8065 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 8066 | |
| 8067 | // Enable cross-origin push. |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8068 | session_deps_.proxy_delegate.reset(proxy_delegate.release()); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 8069 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8070 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8071 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8072 | SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 8073 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8074 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8075 | SpdySerializedFrame push_rst( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 8076 | spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_REFUSED_STREAM)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8077 | |
| 8078 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8079 | CreateMockWrite(stream1_syn, 0, ASYNC), CreateMockWrite(push_rst, 3), |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8080 | }; |
| 8081 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8082 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8083 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8084 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8085 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8086 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8087 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 8088 | NULL, 0, 2, 1, "https://www.another-origin.com/foo.dat")); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8089 | |
| 8090 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8091 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 8092 | CreateMockRead(stream2_syn, 2, ASYNC), |
| 8093 | CreateMockRead(stream1_body, 4, ASYNC), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 8094 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), // Force a hang |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8095 | }; |
| 8096 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8097 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 8098 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8099 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8100 | // Negotiate SPDY to the proxy |
| 8101 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8102 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8103 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8104 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8105 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8106 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8107 | TestCompletionCallback callback; |
| 8108 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8109 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8110 | |
| 8111 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8112 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8113 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8114 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8115 | ASSERT_TRUE(response); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8116 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 8117 | |
| 8118 | EXPECT_EQ(200, response->headers->response_code()); |
| 8119 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 8120 | |
| 8121 | std::string response_data; |
| 8122 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8123 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8124 | EXPECT_EQ("hello!", response_data); |
| 8125 | |
| 8126 | trans.reset(); |
| 8127 | session->CloseAllConnections(); |
| 8128 | } |
| 8129 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8130 | // Test that an explicitly trusted SPDY proxy can push same-origin HTTPS |
| 8131 | // resources. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8132 | TEST_F(HttpNetworkTransactionTest, SameOriginProxyPushCorrectness) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8133 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8134 | std::unique_ptr<TestProxyDelegate> proxy_delegate(new TestProxyDelegate()); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8135 | proxy_delegate->set_trusted_spdy_proxy( |
| 8136 | net::ProxyServer::FromURI("myproxy:70", net::ProxyServer::SCHEME_HTTP)); |
| 8137 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8138 | HttpRequestInfo request; |
| 8139 | |
| 8140 | request.method = "GET"; |
| 8141 | request.url = GURL("http://www.example.org/"); |
| 8142 | |
| 8143 | // Configure against https proxy server "myproxy:70". |
| 8144 | session_deps_.proxy_service = ProxyService::CreateFixed("https://myproxy:70"); |
| 8145 | BoundTestNetLog log; |
| 8146 | session_deps_.net_log = log.bound().net_log(); |
| 8147 | |
| 8148 | // Enable cross-origin push. |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8149 | session_deps_.proxy_delegate.reset(proxy_delegate.release()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8150 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8151 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8152 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8153 | SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 8154 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8155 | |
| 8156 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8157 | CreateMockWrite(stream1_syn, 0, ASYNC), |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8158 | }; |
| 8159 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8160 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8161 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8162 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8163 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 8164 | nullptr, 0, 2, 1, "https://myproxy:70/foo.dat")); |
| 8165 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8166 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8167 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8168 | SpdySerializedFrame stream2_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8169 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8170 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8171 | SpdySerializedFrame stream2_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8172 | |
| 8173 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8174 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 8175 | CreateMockRead(stream2_syn, 2, ASYNC), |
| 8176 | CreateMockRead(stream1_body, 3, ASYNC), |
| 8177 | CreateMockRead(stream2_body, 4, ASYNC), |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8178 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), // Force a hang |
| 8179 | }; |
| 8180 | |
| 8181 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 8182 | arraysize(spdy_writes)); |
| 8183 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 8184 | // Negotiate SPDY to the proxy |
| 8185 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8186 | proxy.next_proto = kProtoHTTP2; |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8187 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
| 8188 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8189 | std::unique_ptr<HttpTransaction> trans( |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8190 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 8191 | TestCompletionCallback callback; |
| 8192 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8193 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8194 | |
| 8195 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8196 | EXPECT_THAT(rv, IsOk()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8197 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8198 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8199 | ASSERT_TRUE(response); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8200 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 8201 | |
| 8202 | EXPECT_EQ(200, response->headers->response_code()); |
| 8203 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 8204 | |
| 8205 | std::string response_data; |
| 8206 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8207 | EXPECT_THAT(rv, IsOk()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8208 | EXPECT_EQ("hello!", response_data); |
| 8209 | |
| 8210 | trans.reset(); |
| 8211 | session->CloseAllConnections(); |
| 8212 | } |
| 8213 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8214 | // Test HTTPS connections to a site with a bad certificate, going through an |
| 8215 | // HTTPS proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8216 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8217 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8218 | |
| 8219 | HttpRequestInfo request; |
| 8220 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8221 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8222 | request.load_flags = 0; |
| 8223 | |
| 8224 | // Attempt to fetch the URL from a server with a bad cert |
| 8225 | MockWrite bad_cert_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"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8229 | }; |
| 8230 | |
| 8231 | MockRead bad_cert_reads[] = { |
| 8232 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8233 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8234 | }; |
| 8235 | |
| 8236 | // Attempt to fetch the URL with a good cert |
| 8237 | MockWrite good_data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8238 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8239 | "Host: www.example.org:443\r\n" |
| 8240 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 8241 | MockWrite("GET / HTTP/1.1\r\n" |
| 8242 | "Host: www.example.org\r\n" |
| 8243 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8244 | }; |
| 8245 | |
| 8246 | MockRead good_cert_reads[] = { |
| 8247 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 8248 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8249 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8250 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8251 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8252 | }; |
| 8253 | |
| 8254 | StaticSocketDataProvider ssl_bad_certificate( |
| 8255 | bad_cert_reads, arraysize(bad_cert_reads), |
| 8256 | bad_cert_writes, arraysize(bad_cert_writes)); |
| 8257 | StaticSocketDataProvider data(good_cert_reads, arraysize(good_cert_reads), |
| 8258 | good_data_writes, arraysize(good_data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8259 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 8260 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8261 | |
| 8262 | // SSL to the proxy, then CONNECT request, then SSL with bad certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8263 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 8264 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 8265 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8266 | |
| 8267 | // SSL to the proxy, then CONNECT request, then valid SSL certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8268 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 8269 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8270 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8271 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8272 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8273 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8274 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8275 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8276 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8277 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8278 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8279 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8280 | |
| 8281 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8282 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8283 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8284 | rv = trans->RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8285 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8286 | |
| 8287 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8288 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8289 | |
| 8290 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8291 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8292 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8293 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8294 | } |
| 8295 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8296 | TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgent) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8297 | HttpRequestInfo request; |
| 8298 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8299 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 8300 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 8301 | "Chromium Ultra Awesome X Edition"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8302 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8303 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8304 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8305 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8306 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8307 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8308 | MockWrite( |
| 8309 | "GET / HTTP/1.1\r\n" |
| 8310 | "Host: www.example.org\r\n" |
| 8311 | "Connection: keep-alive\r\n" |
| 8312 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8313 | }; |
| 8314 | |
| 8315 | // Lastly, the server responds with the actual content. |
| 8316 | MockRead data_reads[] = { |
| 8317 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8318 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8319 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8320 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8321 | }; |
| 8322 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8323 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8324 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8325 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8326 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8327 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8328 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8329 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8330 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8331 | |
| 8332 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8333 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8334 | } |
| 8335 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8336 | TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgentOverTunnel) { |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8337 | HttpRequestInfo request; |
| 8338 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8339 | request.url = GURL("https://www.example.org/"); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8340 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 8341 | "Chromium Ultra Awesome X Edition"); |
| 8342 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8343 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8344 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8345 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8346 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8347 | |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8348 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8349 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8350 | "Host: www.example.org:443\r\n" |
| 8351 | "Proxy-Connection: keep-alive\r\n" |
| 8352 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8353 | }; |
| 8354 | MockRead data_reads[] = { |
| 8355 | // Return an error, so the transaction stops here (this test isn't |
| 8356 | // interested in the rest). |
| 8357 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 8358 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8359 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 8360 | }; |
| 8361 | |
| 8362 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8363 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8364 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8365 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8366 | TestCompletionCallback callback; |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8367 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8368 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8369 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8370 | |
| 8371 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8372 | EXPECT_THAT(rv, IsOk()); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8373 | } |
| 8374 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8375 | TEST_F(HttpNetworkTransactionTest, BuildRequest_Referer) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8376 | HttpRequestInfo request; |
| 8377 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8378 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8379 | request.load_flags = 0; |
[email protected] | c1045010 | 2011-06-27 09:06:16 | [diff] [blame] | 8380 | request.extra_headers.SetHeader(HttpRequestHeaders::kReferer, |
| 8381 | "http://the.previous.site.com/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8382 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8383 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8384 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8385 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8386 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8387 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8388 | MockWrite( |
| 8389 | "GET / HTTP/1.1\r\n" |
| 8390 | "Host: www.example.org\r\n" |
| 8391 | "Connection: keep-alive\r\n" |
| 8392 | "Referer: http://the.previous.site.com/\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8393 | }; |
| 8394 | |
| 8395 | // Lastly, the server responds with the actual content. |
| 8396 | MockRead data_reads[] = { |
| 8397 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8398 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8399 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8400 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8401 | }; |
| 8402 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8403 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8404 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8405 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8406 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8407 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8408 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8409 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8410 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8411 | |
| 8412 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8413 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8414 | } |
| 8415 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8416 | TEST_F(HttpNetworkTransactionTest, BuildRequest_PostContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8417 | HttpRequestInfo request; |
| 8418 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8419 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8420 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8421 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8422 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8423 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8424 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8425 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8426 | MockWrite( |
| 8427 | "POST / HTTP/1.1\r\n" |
| 8428 | "Host: www.example.org\r\n" |
| 8429 | "Connection: keep-alive\r\n" |
| 8430 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8431 | }; |
| 8432 | |
| 8433 | // Lastly, the server responds with the actual content. |
| 8434 | MockRead data_reads[] = { |
| 8435 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8436 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8437 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8438 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8439 | }; |
| 8440 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8441 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8442 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8443 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8444 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8445 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8446 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8447 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8448 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8449 | |
| 8450 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8451 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8452 | } |
| 8453 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8454 | TEST_F(HttpNetworkTransactionTest, BuildRequest_PutContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8455 | HttpRequestInfo request; |
| 8456 | request.method = "PUT"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8457 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8458 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8459 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8460 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8461 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8462 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8463 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8464 | MockWrite( |
| 8465 | "PUT / HTTP/1.1\r\n" |
| 8466 | "Host: www.example.org\r\n" |
| 8467 | "Connection: keep-alive\r\n" |
| 8468 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8469 | }; |
| 8470 | |
| 8471 | // Lastly, the server responds with the actual content. |
| 8472 | MockRead data_reads[] = { |
| 8473 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8474 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8475 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8476 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8477 | }; |
| 8478 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8479 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8480 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8481 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8482 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8483 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8484 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8485 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8486 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8487 | |
| 8488 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8489 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8490 | } |
| 8491 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8492 | TEST_F(HttpNetworkTransactionTest, BuildRequest_HeadContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8493 | HttpRequestInfo request; |
| 8494 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8495 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8496 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8497 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8498 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8499 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8500 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8501 | MockWrite data_writes[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 8502 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 8503 | "Host: www.example.org\r\n" |
| 8504 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8505 | }; |
| 8506 | |
| 8507 | // Lastly, the server responds with the actual content. |
| 8508 | MockRead data_reads[] = { |
| 8509 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8510 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8511 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8512 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8513 | }; |
| 8514 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8515 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8516 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8517 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8518 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8519 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8520 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8521 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8522 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8523 | |
| 8524 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8525 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8526 | } |
| 8527 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8528 | TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlNoCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8529 | HttpRequestInfo request; |
| 8530 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8531 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8532 | request.load_flags = LOAD_BYPASS_CACHE; |
| 8533 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8534 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8535 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8536 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8537 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8538 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8539 | MockWrite( |
| 8540 | "GET / HTTP/1.1\r\n" |
| 8541 | "Host: www.example.org\r\n" |
| 8542 | "Connection: keep-alive\r\n" |
| 8543 | "Pragma: no-cache\r\n" |
| 8544 | "Cache-Control: no-cache\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8545 | }; |
| 8546 | |
| 8547 | // Lastly, the server responds with the actual content. |
| 8548 | MockRead data_reads[] = { |
| 8549 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8550 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8551 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8552 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8553 | }; |
| 8554 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8555 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8556 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8557 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8558 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8559 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8560 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8561 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8562 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8563 | |
| 8564 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8565 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8566 | } |
| 8567 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8568 | TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlValidateCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8569 | HttpRequestInfo request; |
| 8570 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8571 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8572 | request.load_flags = LOAD_VALIDATE_CACHE; |
| 8573 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8574 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8575 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8576 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8577 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8578 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8579 | MockWrite( |
| 8580 | "GET / HTTP/1.1\r\n" |
| 8581 | "Host: www.example.org\r\n" |
| 8582 | "Connection: keep-alive\r\n" |
| 8583 | "Cache-Control: max-age=0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8584 | }; |
| 8585 | |
| 8586 | // Lastly, the server responds with the actual content. |
| 8587 | MockRead data_reads[] = { |
| 8588 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8589 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8590 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8591 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8592 | }; |
| 8593 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8594 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8595 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8596 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8597 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8598 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8599 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8600 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8601 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8602 | |
| 8603 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8604 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8605 | } |
| 8606 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8607 | TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeaders) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8608 | HttpRequestInfo request; |
| 8609 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8610 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 8611 | request.extra_headers.SetHeader("FooHeader", "Bar"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8612 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8613 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8614 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8615 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8616 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8617 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8618 | MockWrite( |
| 8619 | "GET / HTTP/1.1\r\n" |
| 8620 | "Host: www.example.org\r\n" |
| 8621 | "Connection: keep-alive\r\n" |
| 8622 | "FooHeader: Bar\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8623 | }; |
| 8624 | |
| 8625 | // Lastly, the server responds with the actual content. |
| 8626 | MockRead data_reads[] = { |
| 8627 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8628 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8629 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8630 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8631 | }; |
| 8632 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8633 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8634 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8635 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8636 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8637 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8638 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8639 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8640 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8641 | |
| 8642 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8643 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8644 | } |
| 8645 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8646 | TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeadersStripped) { |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8647 | HttpRequestInfo request; |
| 8648 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8649 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 8650 | request.extra_headers.SetHeader("referer", "www.foo.com"); |
| 8651 | request.extra_headers.SetHeader("hEllo", "Kitty"); |
| 8652 | request.extra_headers.SetHeader("FoO", "bar"); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8653 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8654 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8655 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8656 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8657 | |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8658 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8659 | MockWrite( |
| 8660 | "GET / HTTP/1.1\r\n" |
| 8661 | "Host: www.example.org\r\n" |
| 8662 | "Connection: keep-alive\r\n" |
| 8663 | "referer: www.foo.com\r\n" |
| 8664 | "hEllo: Kitty\r\n" |
| 8665 | "FoO: bar\r\n\r\n"), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8666 | }; |
| 8667 | |
| 8668 | // Lastly, the server responds with the actual content. |
| 8669 | MockRead data_reads[] = { |
| 8670 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8671 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8672 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8673 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8674 | }; |
| 8675 | |
| 8676 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8677 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8678 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8679 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8680 | TestCompletionCallback callback; |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8681 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8682 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8683 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8684 | |
| 8685 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8686 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8687 | } |
| 8688 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8689 | TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8690 | HttpRequestInfo request; |
| 8691 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8692 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8693 | request.load_flags = 0; |
| 8694 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8695 | session_deps_.proxy_service = |
| 8696 | ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8697 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8698 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8699 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8700 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8701 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8702 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8703 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8704 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 8705 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 8706 | |
| 8707 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8708 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
| 8709 | MockWrite( |
| 8710 | "GET / HTTP/1.1\r\n" |
| 8711 | "Host: www.example.org\r\n" |
| 8712 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8713 | |
| 8714 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8715 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8716 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8717 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 8718 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8719 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8720 | }; |
| 8721 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8722 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8723 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8724 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8725 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8726 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8727 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8728 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8729 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8730 | |
| 8731 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8732 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8733 | |
| 8734 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8735 | ASSERT_TRUE(response); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8736 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8737 | LoadTimingInfo load_timing_info; |
| 8738 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 8739 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8740 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 8741 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8742 | std::string response_text; |
| 8743 | rv = ReadTransaction(trans.get(), &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8744 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8745 | EXPECT_EQ("Payload", response_text); |
| 8746 | } |
| 8747 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8748 | TEST_F(HttpNetworkTransactionTest, SOCKS4_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8749 | HttpRequestInfo request; |
| 8750 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8751 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8752 | request.load_flags = 0; |
| 8753 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8754 | session_deps_.proxy_service = |
| 8755 | ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8756 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8757 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8758 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8759 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8760 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8761 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8762 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8763 | unsigned char write_buffer[] = { 0x04, 0x01, 0x01, 0xBB, 127, 0, 0, 1, 0 }; |
| 8764 | unsigned char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 8765 | |
| 8766 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8767 | MockWrite(ASYNC, reinterpret_cast<char*>(write_buffer), |
| 8768 | arraysize(write_buffer)), |
| 8769 | MockWrite( |
| 8770 | "GET / HTTP/1.1\r\n" |
| 8771 | "Host: www.example.org\r\n" |
| 8772 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8773 | |
| 8774 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 8775 | MockRead(ASYNC, reinterpret_cast<char*>(read_buffer), |
| 8776 | arraysize(read_buffer)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8777 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8778 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 8779 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8780 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8781 | }; |
| 8782 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8783 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8784 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8785 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8786 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8787 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8788 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8789 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8790 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8791 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8792 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8793 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8794 | |
| 8795 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8796 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8797 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8798 | LoadTimingInfo load_timing_info; |
| 8799 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 8800 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8801 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 8802 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8803 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8804 | ASSERT_TRUE(response); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8805 | |
| 8806 | std::string response_text; |
| 8807 | rv = ReadTransaction(trans.get(), &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8808 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8809 | EXPECT_EQ("Payload", response_text); |
| 8810 | } |
| 8811 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8812 | TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET_no_PAC) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8813 | HttpRequestInfo request; |
| 8814 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8815 | request.url = GURL("http://www.example.org/"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8816 | request.load_flags = 0; |
| 8817 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8818 | session_deps_.proxy_service = |
| 8819 | ProxyService::CreateFixed("socks4://myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8820 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8821 | session_deps_.net_log = &net_log; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8822 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8823 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8824 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8825 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8826 | |
| 8827 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 8828 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 8829 | |
| 8830 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8831 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
| 8832 | MockWrite( |
| 8833 | "GET / HTTP/1.1\r\n" |
| 8834 | "Host: www.example.org\r\n" |
| 8835 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8836 | |
| 8837 | MockRead data_reads[] = { |
| 8838 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
| 8839 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8840 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 8841 | MockRead("Payload"), |
| 8842 | MockRead(SYNCHRONOUS, OK) |
| 8843 | }; |
| 8844 | |
| 8845 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8846 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8847 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8848 | |
| 8849 | TestCompletionCallback callback; |
| 8850 | |
| 8851 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8852 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8853 | |
| 8854 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8855 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8856 | |
| 8857 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8858 | ASSERT_TRUE(response); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8859 | |
| 8860 | LoadTimingInfo load_timing_info; |
| 8861 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 8862 | TestLoadTimingNotReused(load_timing_info, |
| 8863 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 8864 | |
| 8865 | std::string response_text; |
| 8866 | rv = ReadTransaction(trans.get(), &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8867 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8868 | EXPECT_EQ("Payload", response_text); |
| 8869 | } |
| 8870 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8871 | TEST_F(HttpNetworkTransactionTest, SOCKS5_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8872 | HttpRequestInfo request; |
| 8873 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8874 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8875 | request.load_flags = 0; |
| 8876 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8877 | session_deps_.proxy_service = |
| 8878 | ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8879 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8880 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8881 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8882 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8883 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8884 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8885 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8886 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 8887 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 8888 | const char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8889 | 0x05, // Version |
| 8890 | 0x01, // Command (CONNECT) |
| 8891 | 0x00, // Reserved. |
| 8892 | 0x03, // Address type (DOMAINNAME). |
| 8893 | 0x0F, // Length of domain (15) |
| 8894 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 8895 | '.', 'o', 'r', 'g', 0x00, 0x50, // 16-bit port (80) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 8896 | }; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8897 | const char kSOCKS5OkResponse[] = |
| 8898 | { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; |
| 8899 | |
| 8900 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8901 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 8902 | MockWrite(ASYNC, kSOCKS5OkRequest, arraysize(kSOCKS5OkRequest)), |
| 8903 | MockWrite( |
| 8904 | "GET / HTTP/1.1\r\n" |
| 8905 | "Host: www.example.org\r\n" |
| 8906 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8907 | |
| 8908 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 8909 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 8910 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8911 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8912 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 8913 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8914 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8915 | }; |
| 8916 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8917 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8918 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8919 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8920 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8921 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8922 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8923 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8924 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8925 | |
| 8926 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8927 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8928 | |
| 8929 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8930 | ASSERT_TRUE(response); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8931 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8932 | LoadTimingInfo load_timing_info; |
| 8933 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 8934 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8935 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 8936 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8937 | std::string response_text; |
| 8938 | rv = ReadTransaction(trans.get(), &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8939 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8940 | EXPECT_EQ("Payload", response_text); |
| 8941 | } |
| 8942 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8943 | TEST_F(HttpNetworkTransactionTest, SOCKS5_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8944 | HttpRequestInfo request; |
| 8945 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8946 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8947 | request.load_flags = 0; |
| 8948 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8949 | session_deps_.proxy_service = |
| 8950 | ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8951 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8952 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8953 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8954 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8955 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8956 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8957 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8958 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 8959 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 8960 | const unsigned char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8961 | 0x05, // Version |
| 8962 | 0x01, // Command (CONNECT) |
| 8963 | 0x00, // Reserved. |
| 8964 | 0x03, // Address type (DOMAINNAME). |
| 8965 | 0x0F, // Length of domain (15) |
| 8966 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 8967 | '.', 'o', 'r', 'g', 0x01, 0xBB, // 16-bit port (443) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 8968 | }; |
| 8969 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8970 | const char kSOCKS5OkResponse[] = |
| 8971 | { 0x05, 0x00, 0x00, 0x01, 0, 0, 0, 0, 0x00, 0x00 }; |
| 8972 | |
| 8973 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8974 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 8975 | MockWrite(ASYNC, reinterpret_cast<const char*>(kSOCKS5OkRequest), |
| 8976 | arraysize(kSOCKS5OkRequest)), |
| 8977 | MockWrite( |
| 8978 | "GET / HTTP/1.1\r\n" |
| 8979 | "Host: www.example.org\r\n" |
| 8980 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8981 | |
| 8982 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 8983 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 8984 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8985 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8986 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 8987 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8988 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8989 | }; |
| 8990 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8991 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8992 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8993 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8994 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8995 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8996 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8997 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8998 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8999 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9000 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9001 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9002 | |
| 9003 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9004 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9005 | |
| 9006 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9007 | ASSERT_TRUE(response); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9008 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9009 | LoadTimingInfo load_timing_info; |
| 9010 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 9011 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9012 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 9013 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9014 | std::string response_text; |
| 9015 | rv = ReadTransaction(trans.get(), &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9016 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9017 | EXPECT_EQ("Payload", response_text); |
| 9018 | } |
| 9019 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9020 | namespace { |
| 9021 | |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9022 | // Tests that for connection endpoints the group names are correctly set. |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9023 | |
| 9024 | struct GroupNameTest { |
| 9025 | std::string proxy_server; |
| 9026 | std::string url; |
| 9027 | std::string expected_group_name; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9028 | bool ssl; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9029 | }; |
| 9030 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9031 | std::unique_ptr<HttpNetworkSession> SetupSessionForGroupNameTests( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9032 | SpdySessionDependencies* session_deps_) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9033 | std::unique_ptr<HttpNetworkSession> session(CreateSession(session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9034 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 9035 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 9036 | session->http_server_properties(); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9037 | AlternativeService alternative_service( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 9038 | AlternateProtocolFromNextProto(kProtoHTTP2), "", 444); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9039 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9040 | http_server_properties->SetAlternativeService( |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 9041 | url::SchemeHostPort("https", "host.with.alternate", 443), |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 9042 | alternative_service, expiration); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9043 | |
| 9044 | return session; |
| 9045 | } |
| 9046 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9047 | int GroupNameTransactionHelper(const std::string& url, |
| 9048 | HttpNetworkSession* session) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9049 | HttpRequestInfo request; |
| 9050 | request.method = "GET"; |
| 9051 | request.url = GURL(url); |
| 9052 | request.load_flags = 0; |
| 9053 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9054 | std::unique_ptr<HttpTransaction> trans( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9055 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9056 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9057 | TestCompletionCallback callback; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9058 | |
| 9059 | // We do not complete this request, the dtor will clean the transaction up. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9060 | return trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9061 | } |
| 9062 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9063 | } // namespace |
| 9064 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9065 | TEST_F(HttpNetworkTransactionTest, GroupNameForDirectConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9066 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9067 | { |
| 9068 | "", // unused |
| 9069 | "http://www.example.org/direct", |
| 9070 | "www.example.org:80", |
| 9071 | false, |
| 9072 | }, |
| 9073 | { |
| 9074 | "", // unused |
| 9075 | "http://[2001:1418:13:1::25]/direct", |
| 9076 | "[2001:1418:13:1::25]:80", |
| 9077 | false, |
| 9078 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9079 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9080 | // SSL Tests |
| 9081 | { |
| 9082 | "", // unused |
| 9083 | "https://www.example.org/direct_ssl", |
| 9084 | "ssl/www.example.org:443", |
| 9085 | true, |
| 9086 | }, |
| 9087 | { |
| 9088 | "", // unused |
| 9089 | "https://[2001:1418:13:1::25]/direct", |
| 9090 | "ssl/[2001:1418:13:1::25]:443", |
| 9091 | true, |
| 9092 | }, |
| 9093 | { |
| 9094 | "", // unused |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 9095 | "https://host.with.alternate/direct", |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9096 | "ssl/host.with.alternate:443", |
| 9097 | true, |
| 9098 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9099 | }; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9100 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 9101 | for (size_t i = 0; i < arraysize(tests); ++i) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9102 | session_deps_.proxy_service = |
| 9103 | ProxyService::CreateFixed(tests[i].proxy_server); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9104 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 9105 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9106 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9107 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 9108 | CaptureGroupNameTransportSocketPool* transport_conn_pool = |
| 9109 | new CaptureGroupNameTransportSocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 9110 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 9111 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9112 | std::unique_ptr<MockClientSocketPoolManager> mock_pool_manager( |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 9113 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 9114 | mock_pool_manager->SetTransportSocketPool(transport_conn_pool); |
| 9115 | mock_pool_manager->SetSSLSocketPool(ssl_conn_pool); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 9116 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9117 | |
| 9118 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9119 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9120 | if (tests[i].ssl) |
| 9121 | EXPECT_EQ(tests[i].expected_group_name, |
| 9122 | ssl_conn_pool->last_group_name_received()); |
| 9123 | else |
| 9124 | EXPECT_EQ(tests[i].expected_group_name, |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 9125 | transport_conn_pool->last_group_name_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9126 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9127 | } |
| 9128 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9129 | TEST_F(HttpNetworkTransactionTest, GroupNameForHTTPProxyConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9130 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9131 | { |
| 9132 | "http_proxy", |
| 9133 | "http://www.example.org/http_proxy_normal", |
| 9134 | "www.example.org:80", |
| 9135 | false, |
| 9136 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9137 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9138 | // SSL Tests |
| 9139 | { |
| 9140 | "http_proxy", |
| 9141 | "https://www.example.org/http_connect_ssl", |
| 9142 | "ssl/www.example.org:443", |
| 9143 | true, |
| 9144 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 9145 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9146 | { |
| 9147 | "http_proxy", |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 9148 | "https://host.with.alternate/direct", |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9149 | "ssl/host.with.alternate:443", |
| 9150 | true, |
| 9151 | }, |
[email protected] | 4549925 | 2013-01-23 17:12:56 | [diff] [blame] | 9152 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9153 | { |
| 9154 | "http_proxy", |
| 9155 | "ftp://ftp.google.com/http_proxy_normal", |
| 9156 | "ftp/ftp.google.com:21", |
| 9157 | false, |
| 9158 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9159 | }; |
| 9160 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 9161 | for (size_t i = 0; i < arraysize(tests); ++i) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9162 | session_deps_.proxy_service = |
| 9163 | ProxyService::CreateFixed(tests[i].proxy_server); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9164 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 9165 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9166 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9167 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9168 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9169 | HostPortPair proxy_host("http_proxy", 80); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 9170 | CaptureGroupNameHttpProxySocketPool* http_proxy_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 9171 | new CaptureGroupNameHttpProxySocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 9172 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 9173 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 9174 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9175 | std::unique_ptr<MockClientSocketPoolManager> mock_pool_manager( |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 9176 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 9177 | mock_pool_manager->SetSocketPoolForHTTPProxy(proxy_host, http_proxy_pool); |
| 9178 | mock_pool_manager->SetSocketPoolForSSLWithProxy(proxy_host, ssl_conn_pool); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 9179 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9180 | |
| 9181 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9182 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9183 | if (tests[i].ssl) |
| 9184 | EXPECT_EQ(tests[i].expected_group_name, |
| 9185 | ssl_conn_pool->last_group_name_received()); |
| 9186 | else |
| 9187 | EXPECT_EQ(tests[i].expected_group_name, |
| 9188 | http_proxy_pool->last_group_name_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9189 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9190 | } |
| 9191 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9192 | TEST_F(HttpNetworkTransactionTest, GroupNameForSOCKSConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9193 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9194 | { |
| 9195 | "socks4://socks_proxy:1080", |
| 9196 | "http://www.example.org/socks4_direct", |
| 9197 | "socks4/www.example.org:80", |
| 9198 | false, |
| 9199 | }, |
| 9200 | { |
| 9201 | "socks5://socks_proxy:1080", |
| 9202 | "http://www.example.org/socks5_direct", |
| 9203 | "socks5/www.example.org:80", |
| 9204 | false, |
| 9205 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9206 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9207 | // SSL Tests |
| 9208 | { |
| 9209 | "socks4://socks_proxy:1080", |
| 9210 | "https://www.example.org/socks4_ssl", |
| 9211 | "socks4/ssl/www.example.org:443", |
| 9212 | true, |
| 9213 | }, |
| 9214 | { |
| 9215 | "socks5://socks_proxy:1080", |
| 9216 | "https://www.example.org/socks5_ssl", |
| 9217 | "socks5/ssl/www.example.org:443", |
| 9218 | true, |
| 9219 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 9220 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9221 | { |
| 9222 | "socks4://socks_proxy:1080", |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 9223 | "https://host.with.alternate/direct", |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9224 | "socks4/ssl/host.with.alternate:443", |
| 9225 | true, |
| 9226 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9227 | }; |
| 9228 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 9229 | for (size_t i = 0; i < arraysize(tests); ++i) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9230 | session_deps_.proxy_service = |
| 9231 | ProxyService::CreateFixed(tests[i].proxy_server); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9232 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 9233 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 9234 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9235 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9236 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9237 | HostPortPair proxy_host("socks_proxy", 1080); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 9238 | CaptureGroupNameSOCKSSocketPool* socks_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 9239 | new CaptureGroupNameSOCKSSocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 9240 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 9241 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 9242 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9243 | std::unique_ptr<MockClientSocketPoolManager> mock_pool_manager( |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 9244 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 9245 | mock_pool_manager->SetSocketPoolForSOCKSProxy(proxy_host, socks_conn_pool); |
| 9246 | mock_pool_manager->SetSocketPoolForSSLWithProxy(proxy_host, ssl_conn_pool); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 9247 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9248 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9249 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9250 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9251 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9252 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9253 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9254 | if (tests[i].ssl) |
| 9255 | EXPECT_EQ(tests[i].expected_group_name, |
| 9256 | ssl_conn_pool->last_group_name_received()); |
| 9257 | else |
| 9258 | EXPECT_EQ(tests[i].expected_group_name, |
| 9259 | socks_conn_pool->last_group_name_received()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9260 | } |
| 9261 | } |
| 9262 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9263 | TEST_F(HttpNetworkTransactionTest, ReconsiderProxyAfterFailedConnection) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9264 | HttpRequestInfo request; |
| 9265 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9266 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9267 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9268 | session_deps_.proxy_service = |
| 9269 | ProxyService::CreateFixed("myproxy:70;foobar:80"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 9270 | |
[email protected] | 6971906 | 2010-01-05 20:09:21 | [diff] [blame] | 9271 | // This simulates failure resolving all hostnames; that means we will fail |
| 9272 | // connecting to both proxies (myproxy:70 and foobar:80). |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9273 | session_deps_.host_resolver->rules()->AddSimulatedFailure("*"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 9274 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9275 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 9276 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 9277 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 9278 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9279 | TestCompletionCallback callback; |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 9280 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9281 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9282 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 9283 | |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 9284 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9285 | EXPECT_THAT(rv, IsError(ERR_PROXY_CONNECTION_FAILED)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 9286 | } |
| 9287 | |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9288 | // Base test to make sure that when the load flags for a request specify to |
| 9289 | // bypass the cache, the DNS cache is not used. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9290 | void HttpNetworkTransactionTest::BypassHostCacheOnRefreshHelper( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9291 | int load_flags) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9292 | // Issue a request, asking to bypass the cache(s). |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 9293 | HttpRequestInfo request_info; |
| 9294 | request_info.method = "GET"; |
| 9295 | request_info.load_flags = load_flags; |
| 9296 | request_info.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9297 | |
[email protected] | a2c2fb9 | 2009-07-18 07:31:04 | [diff] [blame] | 9298 | // Select a host resolver that does caching. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9299 | session_deps_.host_resolver.reset(new MockCachingHostResolver); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 9300 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9301 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 9302 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 9303 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9304 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9305 | // 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] | 9306 | AddressList addrlist; |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 9307 | TestCompletionCallback callback; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 9308 | std::unique_ptr<HostResolver::Request> request1; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9309 | int rv = session_deps_.host_resolver->Resolve( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9310 | HostResolver::RequestInfo(HostPortPair("www.example.org", 80)), |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 9311 | DEFAULT_PRIORITY, &addrlist, callback.callback(), &request1, |
| 9312 | BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9313 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 9314 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9315 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9316 | |
| 9317 | // Verify that it was added to host cache, by doing a subsequent async lookup |
| 9318 | // and confirming it completes synchronously. |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 9319 | std::unique_ptr<HostResolver::Request> request2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9320 | rv = session_deps_.host_resolver->Resolve( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9321 | HostResolver::RequestInfo(HostPortPair("www.example.org", 80)), |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 9322 | DEFAULT_PRIORITY, &addrlist, callback.callback(), &request2, |
| 9323 | BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9324 | ASSERT_THAT(rv, IsOk()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9325 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9326 | // 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] | 9327 | // we can tell if the next lookup hit the cache, or the "network". |
| 9328 | // (cache --> success, "network" --> failure). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9329 | session_deps_.host_resolver->rules()->AddSimulatedFailure("www.example.org"); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9330 | |
| 9331 | // Connect up a mock socket which will fail with ERR_UNEXPECTED during the |
| 9332 | // 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] | 9333 | MockRead data_reads[] = { MockRead(SYNCHRONOUS, ERR_UNEXPECTED) }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9334 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9335 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9336 | |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9337 | // Run the request. |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 9338 | rv = trans->Start(&request_info, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9339 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9340 | rv = callback.WaitForResult(); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9341 | |
| 9342 | // If we bypassed the cache, we would have gotten a failure while resolving |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9343 | // "www.example.org". |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9344 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9345 | } |
| 9346 | |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9347 | // There are multiple load flags that should trigger the host cache bypass. |
| 9348 | // Test each in isolation: |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9349 | TEST_F(HttpNetworkTransactionTest, BypassHostCacheOnRefresh1) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9350 | BypassHostCacheOnRefreshHelper(LOAD_BYPASS_CACHE); |
| 9351 | } |
| 9352 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9353 | TEST_F(HttpNetworkTransactionTest, BypassHostCacheOnRefresh2) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9354 | BypassHostCacheOnRefreshHelper(LOAD_VALIDATE_CACHE); |
| 9355 | } |
| 9356 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9357 | TEST_F(HttpNetworkTransactionTest, BypassHostCacheOnRefresh3) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9358 | BypassHostCacheOnRefreshHelper(LOAD_DISABLE_CACHE); |
| 9359 | } |
| 9360 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9361 | // Make sure we can handle an error when writing the request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9362 | TEST_F(HttpNetworkTransactionTest, RequestWriteError) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9363 | HttpRequestInfo request; |
| 9364 | request.method = "GET"; |
| 9365 | request.url = GURL("http://www.foo.com/"); |
| 9366 | request.load_flags = 0; |
| 9367 | |
| 9368 | MockWrite write_failure[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9369 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9370 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9371 | StaticSocketDataProvider data(NULL, 0, |
| 9372 | write_failure, arraysize(write_failure)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9373 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9374 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9375 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9376 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9377 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9378 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 9379 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9380 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9381 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9382 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9383 | |
| 9384 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9385 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 9386 | |
| 9387 | IPEndPoint endpoint; |
| 9388 | EXPECT_TRUE(trans->GetRemoteEndpoint(&endpoint)); |
| 9389 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9390 | } |
| 9391 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9392 | // Check that a connection closed after the start of the headers finishes ok. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9393 | TEST_F(HttpNetworkTransactionTest, ConnectionClosedAfterStartOfHeaders) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9394 | HttpRequestInfo request; |
| 9395 | request.method = "GET"; |
| 9396 | request.url = GURL("http://www.foo.com/"); |
| 9397 | request.load_flags = 0; |
| 9398 | |
| 9399 | MockRead data_reads[] = { |
| 9400 | MockRead("HTTP/1."), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9401 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9402 | }; |
| 9403 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9404 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9405 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9406 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9407 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9408 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9409 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9410 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 9411 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9412 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9413 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9414 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9415 | |
| 9416 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9417 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9418 | |
| 9419 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9420 | ASSERT_TRUE(response); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9421 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9422 | EXPECT_TRUE(response->headers); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9423 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 9424 | |
| 9425 | std::string response_data; |
| 9426 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9427 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9428 | EXPECT_EQ("", response_data); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 9429 | |
| 9430 | IPEndPoint endpoint; |
| 9431 | EXPECT_TRUE(trans->GetRemoteEndpoint(&endpoint)); |
| 9432 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9433 | } |
| 9434 | |
| 9435 | // Make sure that a dropped connection while draining the body for auth |
| 9436 | // restart does the right thing. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9437 | TEST_F(HttpNetworkTransactionTest, DrainResetOK) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9438 | HttpRequestInfo request; |
| 9439 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9440 | request.url = GURL("http://www.example.org/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9441 | request.load_flags = 0; |
| 9442 | |
| 9443 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9444 | MockWrite( |
| 9445 | "GET / HTTP/1.1\r\n" |
| 9446 | "Host: www.example.org\r\n" |
| 9447 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9448 | }; |
| 9449 | |
| 9450 | MockRead data_reads1[] = { |
| 9451 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 9452 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 9453 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9454 | MockRead("Content-Length: 14\r\n\r\n"), |
| 9455 | MockRead("Unauth"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9456 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9457 | }; |
| 9458 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9459 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 9460 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9461 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9462 | |
| 9463 | // After calling trans->RestartWithAuth(), this is the request we should |
| 9464 | // be issuing -- the final header line contains the credentials. |
| 9465 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9466 | MockWrite( |
| 9467 | "GET / HTTP/1.1\r\n" |
| 9468 | "Host: www.example.org\r\n" |
| 9469 | "Connection: keep-alive\r\n" |
| 9470 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9471 | }; |
| 9472 | |
| 9473 | // Lastly, the server responds with the actual content. |
| 9474 | MockRead data_reads2[] = { |
| 9475 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9476 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9477 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9478 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9479 | }; |
| 9480 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9481 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 9482 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9483 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9484 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9485 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9486 | TestCompletionCallback callback1; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9487 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9488 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9489 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 9490 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9491 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9492 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9493 | |
| 9494 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9495 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9496 | |
| 9497 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9498 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9499 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9500 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9501 | TestCompletionCallback callback2; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9502 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9503 | rv = trans->RestartWithAuth( |
| 9504 | AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9505 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9506 | |
| 9507 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9508 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9509 | |
| 9510 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9511 | ASSERT_TRUE(response); |
| 9512 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9513 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9514 | } |
| 9515 | |
| 9516 | // Test HTTPS connections going through a proxy that sends extra data. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9517 | TEST_F(HttpNetworkTransactionTest, HTTPSViaProxyWithExtraData) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9518 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9519 | |
| 9520 | HttpRequestInfo request; |
| 9521 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9522 | request.url = GURL("https://www.example.org/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9523 | request.load_flags = 0; |
| 9524 | |
| 9525 | MockRead proxy_reads[] = { |
| 9526 | MockRead("HTTP/1.0 200 Connected\r\n\r\nExtra data"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9527 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9528 | }; |
| 9529 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9530 | StaticSocketDataProvider data(proxy_reads, arraysize(proxy_reads), NULL, 0); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9531 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9532 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9533 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9534 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9535 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9536 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9537 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9538 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9539 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9540 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 9541 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 9542 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9543 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9544 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9545 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9546 | |
| 9547 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9548 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9549 | } |
| 9550 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9551 | TEST_F(HttpNetworkTransactionTest, LargeContentLengthThenClose) { |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9552 | HttpRequestInfo request; |
| 9553 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9554 | request.url = GURL("http://www.example.org/"); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9555 | request.load_flags = 0; |
| 9556 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9557 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 9558 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 9559 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9560 | |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 9561 | MockRead data_reads[] = { |
| 9562 | 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] | 9563 | MockRead(SYNCHRONOUS, OK), |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 9564 | }; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9565 | |
| 9566 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9567 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9568 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9569 | TestCompletionCallback callback; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9570 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9571 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9572 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9573 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9574 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9575 | |
| 9576 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9577 | ASSERT_TRUE(response); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9578 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9579 | EXPECT_TRUE(response->headers); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9580 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 9581 | |
| 9582 | std::string response_data; |
| 9583 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9584 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 9585 | } |
| 9586 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9587 | TEST_F(HttpNetworkTransactionTest, UploadFileSmallerThanLength) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 9588 | base::FilePath temp_file_path; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 9589 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file_path)); |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 9590 | const uint64_t kFakeSize = 100000; // file is actually blank |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 9591 | UploadFileElementReader::ScopedOverridingContentLengthForTests |
| 9592 | overriding_content_length(kFakeSize); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9593 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9594 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
| 9595 | element_readers.push_back(base::WrapUnique(new UploadFileElementReader( |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 9596 | base::ThreadTaskRunnerHandle::Get().get(), temp_file_path, 0, |
| 9597 | std::numeric_limits<uint64_t>::max(), base::Time()))); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 9598 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9599 | |
| 9600 | HttpRequestInfo request; |
| 9601 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9602 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9603 | request.upload_data_stream = &upload_data_stream; |
| 9604 | request.load_flags = 0; |
| 9605 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9606 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 9607 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 9608 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9609 | |
| 9610 | MockRead data_reads[] = { |
| 9611 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 9612 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9613 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9614 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9615 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9616 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9617 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9618 | TestCompletionCallback callback; |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9619 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9620 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9621 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9622 | |
| 9623 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9624 | EXPECT_THAT(rv, IsError(ERR_UPLOAD_FILE_CHANGED)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9625 | |
| 9626 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9627 | ASSERT_TRUE(response); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9628 | |
maksim.sisov | e869bf5 | 2016-06-23 17:11:52 | [diff] [blame] | 9629 | EXPECT_FALSE(response->headers); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9630 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 9631 | base::DeleteFile(temp_file_path, false); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9632 | } |
| 9633 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9634 | TEST_F(HttpNetworkTransactionTest, UploadUnreadableFile) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 9635 | base::FilePath temp_file; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 9636 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9637 | std::string temp_file_content("Unreadable file."); |
[email protected] | e5c2a22e | 2014-03-06 20:42:30 | [diff] [blame] | 9638 | ASSERT_TRUE(base::WriteFile(temp_file, temp_file_content.c_str(), |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9639 | temp_file_content.length())); |
[email protected] | 92be8eb | 2014-08-07 22:57:11 | [diff] [blame] | 9640 | ASSERT_TRUE(base::MakeFileUnreadable(temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9641 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9642 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
| 9643 | element_readers.push_back(base::WrapUnique(new UploadFileElementReader( |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 9644 | base::ThreadTaskRunnerHandle::Get().get(), temp_file, 0, |
| 9645 | std::numeric_limits<uint64_t>::max(), base::Time()))); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 9646 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9647 | |
| 9648 | HttpRequestInfo request; |
| 9649 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9650 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9651 | request.upload_data_stream = &upload_data_stream; |
| 9652 | request.load_flags = 0; |
| 9653 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 9654 | // If we try to upload an unreadable file, the transaction should fail. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9655 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 9656 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 9657 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9658 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 9659 | StaticSocketDataProvider data(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9660 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9661 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9662 | TestCompletionCallback callback; |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9663 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9664 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9665 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9666 | |
| 9667 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9668 | EXPECT_THAT(rv, IsError(ERR_ACCESS_DENIED)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9669 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 9670 | base::DeleteFile(temp_file, false); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9671 | } |
| 9672 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9673 | TEST_F(HttpNetworkTransactionTest, CancelDuringInitRequestBody) { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9674 | class FakeUploadElementReader : public UploadElementReader { |
| 9675 | public: |
| 9676 | FakeUploadElementReader() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9677 | ~FakeUploadElementReader() override {} |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9678 | |
| 9679 | const CompletionCallback& callback() const { return callback_; } |
| 9680 | |
| 9681 | // UploadElementReader overrides: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9682 | int Init(const CompletionCallback& callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9683 | callback_ = callback; |
| 9684 | return ERR_IO_PENDING; |
| 9685 | } |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 9686 | uint64_t GetContentLength() const override { return 0; } |
| 9687 | uint64_t BytesRemaining() const override { return 0; } |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9688 | int Read(IOBuffer* buf, |
| 9689 | int buf_length, |
| 9690 | const CompletionCallback& callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9691 | return ERR_FAILED; |
| 9692 | } |
| 9693 | |
| 9694 | private: |
| 9695 | CompletionCallback callback_; |
| 9696 | }; |
| 9697 | |
| 9698 | FakeUploadElementReader* fake_reader = new FakeUploadElementReader; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9699 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
| 9700 | element_readers.push_back(base::WrapUnique(fake_reader)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 9701 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9702 | |
| 9703 | HttpRequestInfo request; |
| 9704 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9705 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9706 | request.upload_data_stream = &upload_data_stream; |
| 9707 | request.load_flags = 0; |
| 9708 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9709 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 9710 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 9711 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9712 | |
| 9713 | StaticSocketDataProvider data; |
| 9714 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9715 | |
| 9716 | TestCompletionCallback callback; |
| 9717 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9718 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 9719 | base::RunLoop().RunUntilIdle(); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9720 | |
| 9721 | // Transaction is pending on request body initialization. |
| 9722 | ASSERT_FALSE(fake_reader->callback().is_null()); |
| 9723 | |
| 9724 | // Return Init()'s result after the transaction gets destroyed. |
| 9725 | trans.reset(); |
| 9726 | fake_reader->callback().Run(OK); // Should not crash. |
| 9727 | } |
| 9728 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9729 | // Tests that changes to Auth realms are treated like auth rejections. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9730 | TEST_F(HttpNetworkTransactionTest, ChangeAuthRealms) { |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9731 | HttpRequestInfo request; |
| 9732 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9733 | request.url = GURL("http://www.example.org/"); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9734 | request.load_flags = 0; |
| 9735 | |
| 9736 | // First transaction will request a resource and receive a Basic challenge |
| 9737 | // with realm="first_realm". |
| 9738 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9739 | MockWrite( |
| 9740 | "GET / HTTP/1.1\r\n" |
| 9741 | "Host: www.example.org\r\n" |
| 9742 | "Connection: keep-alive\r\n" |
| 9743 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9744 | }; |
| 9745 | MockRead data_reads1[] = { |
| 9746 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 9747 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 9748 | "\r\n"), |
| 9749 | }; |
| 9750 | |
| 9751 | // After calling trans->RestartWithAuth(), provide an Authentication header |
| 9752 | // for first_realm. The server will reject and provide a challenge with |
| 9753 | // second_realm. |
| 9754 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9755 | MockWrite( |
| 9756 | "GET / HTTP/1.1\r\n" |
| 9757 | "Host: www.example.org\r\n" |
| 9758 | "Connection: keep-alive\r\n" |
| 9759 | "Authorization: Basic Zmlyc3Q6YmF6\r\n" |
| 9760 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9761 | }; |
| 9762 | MockRead data_reads2[] = { |
| 9763 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 9764 | "WWW-Authenticate: Basic realm=\"second_realm\"\r\n" |
| 9765 | "\r\n"), |
| 9766 | }; |
| 9767 | |
| 9768 | // This again fails, and goes back to first_realm. Make sure that the |
| 9769 | // entry is removed from cache. |
| 9770 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9771 | MockWrite( |
| 9772 | "GET / HTTP/1.1\r\n" |
| 9773 | "Host: www.example.org\r\n" |
| 9774 | "Connection: keep-alive\r\n" |
| 9775 | "Authorization: Basic c2Vjb25kOmZvdQ==\r\n" |
| 9776 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9777 | }; |
| 9778 | MockRead data_reads3[] = { |
| 9779 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 9780 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 9781 | "\r\n"), |
| 9782 | }; |
| 9783 | |
| 9784 | // Try one last time (with the correct password) and get the resource. |
| 9785 | MockWrite data_writes4[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9786 | MockWrite( |
| 9787 | "GET / HTTP/1.1\r\n" |
| 9788 | "Host: www.example.org\r\n" |
| 9789 | "Connection: keep-alive\r\n" |
| 9790 | "Authorization: Basic Zmlyc3Q6YmFy\r\n" |
| 9791 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9792 | }; |
| 9793 | MockRead data_reads4[] = { |
| 9794 | MockRead("HTTP/1.1 200 OK\r\n" |
| 9795 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 9796 | "Content-Length: 5\r\n" |
| 9797 | "\r\n" |
| 9798 | "hello"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9799 | }; |
| 9800 | |
| 9801 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 9802 | data_writes1, arraysize(data_writes1)); |
| 9803 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 9804 | data_writes2, arraysize(data_writes2)); |
| 9805 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 9806 | data_writes3, arraysize(data_writes3)); |
| 9807 | StaticSocketDataProvider data4(data_reads4, arraysize(data_reads4), |
| 9808 | data_writes4, arraysize(data_writes4)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9809 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 9810 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 9811 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 9812 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9813 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9814 | TestCompletionCallback callback1; |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9815 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9816 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 9817 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 9818 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 9819 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9820 | // Issue the first request with Authorize headers. There should be a |
| 9821 | // password prompt for first_realm waiting to be filled in after the |
| 9822 | // transaction completes. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9823 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9824 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9825 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9826 | EXPECT_THAT(rv, IsOk()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9827 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9828 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9829 | const AuthChallengeInfo* challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9830 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9831 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 9832 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9833 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 9834 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9835 | |
| 9836 | // Issue the second request with an incorrect password. There should be a |
| 9837 | // password prompt for second_realm waiting to be filled in after the |
| 9838 | // transaction completes. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9839 | TestCompletionCallback callback2; |
| 9840 | rv = trans->RestartWithAuth( |
| 9841 | AuthCredentials(kFirst, kBaz), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9842 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9843 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9844 | EXPECT_THAT(rv, IsOk()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9845 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9846 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9847 | challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9848 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9849 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 9850 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9851 | EXPECT_EQ("second_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 9852 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9853 | |
| 9854 | // Issue the third request with another incorrect password. There should be |
| 9855 | // a password prompt for first_realm waiting to be filled in. If the password |
| 9856 | // prompt is not present, it indicates that the HttpAuthCacheEntry for |
| 9857 | // first_realm was not correctly removed. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9858 | TestCompletionCallback callback3; |
| 9859 | rv = trans->RestartWithAuth( |
| 9860 | AuthCredentials(kSecond, kFou), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9861 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9862 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9863 | EXPECT_THAT(rv, IsOk()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9864 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9865 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9866 | challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9867 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9868 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 9869 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9870 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 9871 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9872 | |
| 9873 | // Issue the fourth request with the correct password and username. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9874 | TestCompletionCallback callback4; |
| 9875 | rv = trans->RestartWithAuth( |
| 9876 | AuthCredentials(kFirst, kBar), callback4.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9877 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9878 | rv = callback4.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9879 | EXPECT_THAT(rv, IsOk()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9880 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9881 | ASSERT_TRUE(response); |
| 9882 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9883 | } |
| 9884 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9885 | TEST_F(HttpNetworkTransactionTest, HonorAlternativeServiceHeader) { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9886 | MockRead data_reads[] = { |
| 9887 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 9888 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9889 | MockRead("\r\n"), |
| 9890 | MockRead("hello world"), |
| 9891 | MockRead(SYNCHRONOUS, OK), |
| 9892 | }; |
| 9893 | |
| 9894 | HttpRequestInfo request; |
| 9895 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 9896 | request.url = GURL("https://www.example.org/"); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9897 | request.load_flags = 0; |
| 9898 | |
| 9899 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9900 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9901 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 9902 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 9903 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 9904 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9905 | TestCompletionCallback callback; |
| 9906 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9907 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 9908 | std::unique_ptr<HttpTransaction> trans( |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9909 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 9910 | |
| 9911 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9912 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9913 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 9914 | url::SchemeHostPort test_server(request.url); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 9915 | HttpServerProperties* http_server_properties = |
| 9916 | session->http_server_properties(); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9917 | AlternativeServiceVector alternative_service_vector = |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 9918 | http_server_properties->GetAlternativeServices(test_server); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9919 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 9920 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9921 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9922 | |
| 9923 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9924 | ASSERT_TRUE(response); |
| 9925 | ASSERT_TRUE(response->headers); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9926 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9927 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9928 | EXPECT_FALSE(response->was_npn_negotiated); |
| 9929 | |
| 9930 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9931 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9932 | EXPECT_EQ("hello world", response_data); |
| 9933 | |
| 9934 | alternative_service_vector = |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 9935 | http_server_properties->GetAlternativeServices(test_server); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9936 | ASSERT_EQ(1u, alternative_service_vector.size()); |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 9937 | EXPECT_EQ(AlternateProtocolFromNextProto(kProtoHTTP2), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9938 | alternative_service_vector[0].protocol); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 9939 | EXPECT_EQ("mail.example.org", alternative_service_vector[0].host); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9940 | EXPECT_EQ(443, alternative_service_vector[0].port); |
| 9941 | } |
| 9942 | |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 9943 | // Regression test for https://crbug.com/615497. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9944 | TEST_F(HttpNetworkTransactionTest, |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 9945 | DoNotParseAlternativeServiceHeaderOnInsecureRequest) { |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 9946 | MockRead data_reads[] = { |
| 9947 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 9948 | MockRead(kAlternativeServiceHttpHeader), |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 9949 | MockRead("\r\n"), |
| 9950 | MockRead("hello world"), |
| 9951 | MockRead(SYNCHRONOUS, OK), |
| 9952 | }; |
| 9953 | |
| 9954 | HttpRequestInfo request; |
| 9955 | request.method = "GET"; |
| 9956 | request.url = GURL("http://www.example.org/"); |
| 9957 | request.load_flags = 0; |
| 9958 | |
| 9959 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 9960 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9961 | |
| 9962 | TestCompletionCallback callback; |
| 9963 | |
| 9964 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 9965 | std::unique_ptr<HttpTransaction> trans( |
| 9966 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 9967 | |
| 9968 | url::SchemeHostPort test_server(request.url); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 9969 | HttpServerProperties* http_server_properties = |
| 9970 | session->http_server_properties(); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 9971 | AlternativeServiceVector alternative_service_vector = |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 9972 | http_server_properties->GetAlternativeServices(test_server); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 9973 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 9974 | |
| 9975 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9976 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 9977 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 9978 | |
| 9979 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9980 | ASSERT_TRUE(response); |
| 9981 | ASSERT_TRUE(response->headers); |
| 9982 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9983 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9984 | EXPECT_FALSE(response->was_npn_negotiated); |
| 9985 | |
| 9986 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9987 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 9988 | EXPECT_EQ("hello world", response_data); |
| 9989 | |
| 9990 | alternative_service_vector = |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 9991 | http_server_properties->GetAlternativeServices(test_server); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 9992 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 9993 | } |
| 9994 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 9995 | // HTTP/2 Alternative Services should be disabled if alternative service |
| 9996 | // hostname is different from that of origin. |
| 9997 | // TODO(bnc): Remove when https://crbug.com/615413 is fixed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9998 | TEST_F(HttpNetworkTransactionTest, |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 9999 | DisableHTTP2AlternativeServicesWithDifferentHost) { |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10000 | session_deps_.enable_http2_alternative_service_with_different_host = false; |
| 10001 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10002 | HttpRequestInfo request; |
| 10003 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10004 | request.url = GURL("https://www.example.org/"); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10005 | request.load_flags = 0; |
| 10006 | |
| 10007 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 10008 | StaticSocketDataProvider first_data; |
| 10009 | first_data.set_connect_data(mock_connect); |
| 10010 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10011 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10012 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10013 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10014 | |
| 10015 | MockRead data_reads[] = { |
| 10016 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 10017 | MockRead(ASYNC, OK), |
| 10018 | }; |
| 10019 | StaticSocketDataProvider second_data(data_reads, arraysize(data_reads), NULL, |
| 10020 | 0); |
| 10021 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 10022 | |
| 10023 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 10024 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10025 | HttpServerProperties* http_server_properties = |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10026 | session->http_server_properties(); |
| 10027 | AlternativeService alternative_service( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 10028 | AlternateProtocolFromNextProto(kProtoHTTP2), "different.example.org", |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10029 | 444); |
| 10030 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 10031 | http_server_properties->SetAlternativeService( |
| 10032 | url::SchemeHostPort(request.url), alternative_service, expiration); |
| 10033 | |
| 10034 | std::unique_ptr<HttpTransaction> trans( |
| 10035 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 10036 | TestCompletionCallback callback; |
| 10037 | |
| 10038 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 10039 | // Alternative service is not used, request fails. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10040 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10041 | } |
| 10042 | |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10043 | // Regression test for https://crbug.com/615497: |
| 10044 | // Alternative Services should be disabled for http origin. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10045 | TEST_F(HttpNetworkTransactionTest, |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10046 | DisableAlternativeServicesForInsecureOrigin) { |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10047 | HttpRequestInfo request; |
| 10048 | request.method = "GET"; |
| 10049 | request.url = GURL("http://www.example.org/"); |
| 10050 | request.load_flags = 0; |
| 10051 | |
| 10052 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 10053 | StaticSocketDataProvider first_data; |
| 10054 | first_data.set_connect_data(mock_connect); |
| 10055 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
| 10056 | |
| 10057 | MockRead data_reads[] = { |
| 10058 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 10059 | MockRead(ASYNC, OK), |
| 10060 | }; |
| 10061 | StaticSocketDataProvider second_data(data_reads, arraysize(data_reads), NULL, |
| 10062 | 0); |
| 10063 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 10064 | |
| 10065 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 10066 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10067 | HttpServerProperties* http_server_properties = |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10068 | session->http_server_properties(); |
| 10069 | AlternativeService alternative_service( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 10070 | AlternateProtocolFromNextProto(kProtoHTTP2), "", 444); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10071 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 10072 | http_server_properties->SetAlternativeService( |
| 10073 | url::SchemeHostPort(request.url), alternative_service, expiration); |
| 10074 | |
| 10075 | std::unique_ptr<HttpTransaction> trans( |
| 10076 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 10077 | TestCompletionCallback callback; |
| 10078 | |
| 10079 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 10080 | // Alternative service is not used, request fails. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10081 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10082 | } |
| 10083 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10084 | TEST_F(HttpNetworkTransactionTest, ClearAlternativeServices) { |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10085 | // Set an alternative service for origin. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10086 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10087 | HttpServerProperties* http_server_properties = |
| 10088 | session->http_server_properties(); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10089 | url::SchemeHostPort test_server("https", "www.example.org", 443); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10090 | AlternativeService alternative_service(QUIC, "", 80); |
| 10091 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10092 | http_server_properties->SetAlternativeService( |
| 10093 | test_server, alternative_service, expiration); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10094 | AlternativeServiceVector alternative_service_vector = |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10095 | http_server_properties->GetAlternativeServices(test_server); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10096 | EXPECT_EQ(1u, alternative_service_vector.size()); |
| 10097 | |
| 10098 | // Send a clear header. |
| 10099 | MockRead data_reads[] = { |
| 10100 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10101 | MockRead("Alt-Svc: clear\r\n"), |
| 10102 | MockRead("\r\n"), |
| 10103 | MockRead("hello world"), |
| 10104 | MockRead(SYNCHRONOUS, OK), |
| 10105 | }; |
| 10106 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), nullptr, 0); |
| 10107 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10108 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10109 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 10110 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10111 | |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10112 | HttpRequestInfo request; |
| 10113 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10114 | request.url = GURL("https://www.example.org/"); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10115 | request.load_flags = 0; |
| 10116 | |
| 10117 | TestCompletionCallback callback; |
| 10118 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10119 | std::unique_ptr<HttpTransaction> trans( |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10120 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 10121 | |
| 10122 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10123 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10124 | |
| 10125 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10126 | ASSERT_TRUE(response); |
| 10127 | ASSERT_TRUE(response->headers); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10128 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10129 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 10130 | EXPECT_FALSE(response->was_npn_negotiated); |
| 10131 | |
| 10132 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10133 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10134 | EXPECT_EQ("hello world", response_data); |
| 10135 | |
| 10136 | alternative_service_vector = |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10137 | http_server_properties->GetAlternativeServices(test_server); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10138 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 10139 | } |
| 10140 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10141 | TEST_F(HttpNetworkTransactionTest, HonorMultipleAlternativeServiceHeaders) { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10142 | MockRead data_reads[] = { |
| 10143 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 10144 | MockRead("Alt-Svc: h2=\"www.example.com:443\","), |
| 10145 | MockRead("h2=\":1234\"\r\n\r\n"), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10146 | MockRead("hello world"), |
| 10147 | MockRead(SYNCHRONOUS, OK), |
| 10148 | }; |
| 10149 | |
| 10150 | HttpRequestInfo request; |
| 10151 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10152 | request.url = GURL("https://www.example.org/"); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10153 | request.load_flags = 0; |
| 10154 | |
| 10155 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10156 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10157 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10158 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 10159 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10160 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10161 | TestCompletionCallback callback; |
| 10162 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10163 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 10164 | std::unique_ptr<HttpTransaction> trans( |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10165 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 10166 | |
| 10167 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10168 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10169 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10170 | url::SchemeHostPort test_server("https", "www.example.org", 443); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10171 | HttpServerProperties* http_server_properties = |
| 10172 | session->http_server_properties(); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10173 | AlternativeServiceVector alternative_service_vector = |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10174 | http_server_properties->GetAlternativeServices(test_server); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10175 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 10176 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10177 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10178 | |
| 10179 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10180 | ASSERT_TRUE(response); |
| 10181 | ASSERT_TRUE(response->headers); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10182 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10183 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 10184 | EXPECT_FALSE(response->was_npn_negotiated); |
| 10185 | |
| 10186 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10187 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10188 | EXPECT_EQ("hello world", response_data); |
| 10189 | |
| 10190 | alternative_service_vector = |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10191 | http_server_properties->GetAlternativeServices(test_server); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10192 | ASSERT_EQ(2u, alternative_service_vector.size()); |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 10193 | EXPECT_EQ(AlternateProtocolFromNextProto(kProtoHTTP2), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10194 | alternative_service_vector[0].protocol); |
| 10195 | EXPECT_EQ("www.example.com", alternative_service_vector[0].host); |
| 10196 | EXPECT_EQ(443, alternative_service_vector[0].port); |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 10197 | EXPECT_EQ(AlternateProtocolFromNextProto(kProtoHTTP2), |
bnc | 3f0118e | 2016-02-02 15:42:22 | [diff] [blame] | 10198 | alternative_service_vector[1].protocol); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10199 | EXPECT_EQ("www.example.org", alternative_service_vector[1].host); |
| 10200 | EXPECT_EQ(1234, alternative_service_vector[1].port); |
| 10201 | } |
| 10202 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10203 | TEST_F(HttpNetworkTransactionTest, IdentifyQuicBroken) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10204 | url::SchemeHostPort server("https", "origin.example.org", 443); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10205 | HostPortPair alternative("alternative.example.org", 443); |
| 10206 | std::string origin_url = "https://origin.example.org:443"; |
| 10207 | std::string alternative_url = "https://alternative.example.org:443"; |
| 10208 | |
| 10209 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 10210 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10211 | ssl.next_proto = kProtoHTTP11; |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10212 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10213 | |
| 10214 | // HTTP/1.1 data for request. |
| 10215 | MockWrite http_writes[] = { |
| 10216 | MockWrite("GET / HTTP/1.1\r\n" |
| 10217 | "Host: alternative.example.org\r\n" |
| 10218 | "Connection: keep-alive\r\n\r\n"), |
| 10219 | }; |
| 10220 | |
| 10221 | MockRead http_reads[] = { |
| 10222 | MockRead("HTTP/1.1 200 OK\r\n" |
| 10223 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 10224 | "Content-Length: 40\r\n\r\n" |
| 10225 | "first HTTP/1.1 response from alternative"), |
| 10226 | }; |
| 10227 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 10228 | http_writes, arraysize(http_writes)); |
| 10229 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 10230 | |
| 10231 | StaticSocketDataProvider data_refused; |
| 10232 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 10233 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 10234 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10235 | // Set up a QUIC alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10236 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10237 | HttpServerProperties* http_server_properties = |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10238 | session->http_server_properties(); |
| 10239 | AlternativeService alternative_service(QUIC, alternative); |
| 10240 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10241 | http_server_properties->SetAlternativeService(server, alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10242 | expiration); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10243 | // Mark the QUIC alternative service as broken. |
| 10244 | http_server_properties->MarkAlternativeServiceBroken(alternative_service); |
| 10245 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10246 | std::unique_ptr<HttpTransaction> trans( |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10247 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 10248 | HttpRequestInfo request; |
| 10249 | request.method = "GET"; |
| 10250 | request.url = GURL(origin_url); |
| 10251 | request.load_flags = 0; |
| 10252 | TestCompletionCallback callback; |
| 10253 | NetErrorDetails details; |
| 10254 | EXPECT_FALSE(details.quic_broken); |
| 10255 | |
| 10256 | trans->Start(&request, callback.callback(), BoundNetLog()); |
| 10257 | trans->PopulateNetErrorDetails(&details); |
| 10258 | EXPECT_TRUE(details.quic_broken); |
| 10259 | } |
| 10260 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10261 | TEST_F(HttpNetworkTransactionTest, IdentifyQuicNotBroken) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10262 | url::SchemeHostPort server("https", "origin.example.org", 443); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10263 | HostPortPair alternative1("alternative1.example.org", 443); |
| 10264 | HostPortPair alternative2("alternative2.example.org", 443); |
| 10265 | std::string origin_url = "https://origin.example.org:443"; |
| 10266 | std::string alternative_url1 = "https://alternative1.example.org:443"; |
| 10267 | std::string alternative_url2 = "https://alternative2.example.org:443"; |
| 10268 | |
| 10269 | // Negotiate HTTP/1.1 with alternative1.example.org. |
| 10270 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10271 | ssl.next_proto = kProtoHTTP11; |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10272 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10273 | |
| 10274 | // HTTP/1.1 data for request. |
| 10275 | MockWrite http_writes[] = { |
| 10276 | MockWrite("GET / HTTP/1.1\r\n" |
| 10277 | "Host: alternative1.example.org\r\n" |
| 10278 | "Connection: keep-alive\r\n\r\n"), |
| 10279 | }; |
| 10280 | |
| 10281 | MockRead http_reads[] = { |
| 10282 | MockRead("HTTP/1.1 200 OK\r\n" |
| 10283 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 10284 | "Content-Length: 40\r\n\r\n" |
| 10285 | "first HTTP/1.1 response from alternative1"), |
| 10286 | }; |
| 10287 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 10288 | http_writes, arraysize(http_writes)); |
| 10289 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 10290 | |
| 10291 | StaticSocketDataProvider data_refused; |
| 10292 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 10293 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 10294 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10295 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10296 | HttpServerProperties* http_server_properties = |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10297 | session->http_server_properties(); |
| 10298 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10299 | // Set up two QUIC alternative services for server. |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10300 | AlternativeServiceInfoVector alternative_service_info_vector; |
| 10301 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 10302 | |
| 10303 | AlternativeService alternative_service1(QUIC, alternative1); |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10304 | AlternativeServiceInfo alternative_service_info1(alternative_service1, |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10305 | expiration); |
| 10306 | alternative_service_info_vector.push_back(alternative_service_info1); |
| 10307 | AlternativeService alternative_service2(QUIC, alternative2); |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10308 | AlternativeServiceInfo alternative_service_info2(alternative_service2, |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10309 | expiration); |
| 10310 | alternative_service_info_vector.push_back(alternative_service_info2); |
| 10311 | |
| 10312 | http_server_properties->SetAlternativeServices( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10313 | server, alternative_service_info_vector); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10314 | |
| 10315 | // Mark one of the QUIC alternative service as broken. |
| 10316 | http_server_properties->MarkAlternativeServiceBroken(alternative_service1); |
| 10317 | |
| 10318 | const AlternativeServiceVector alternative_service_vector = |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10319 | http_server_properties->GetAlternativeServices(server); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10320 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10321 | std::unique_ptr<HttpTransaction> trans( |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10322 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 10323 | HttpRequestInfo request; |
| 10324 | request.method = "GET"; |
| 10325 | request.url = GURL(origin_url); |
| 10326 | request.load_flags = 0; |
| 10327 | TestCompletionCallback callback; |
| 10328 | NetErrorDetails details; |
| 10329 | EXPECT_FALSE(details.quic_broken); |
| 10330 | |
| 10331 | trans->Start(&request, callback.callback(), BoundNetLog()); |
| 10332 | trans->PopulateNetErrorDetails(&details); |
| 10333 | EXPECT_FALSE(details.quic_broken); |
| 10334 | } |
| 10335 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10336 | TEST_F(HttpNetworkTransactionTest, MarkBrokenAlternateProtocolAndFallback) { |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10337 | HttpRequestInfo request; |
| 10338 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10339 | request.url = GURL("https://www.example.org/"); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10340 | request.load_flags = 0; |
| 10341 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10342 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10343 | StaticSocketDataProvider first_data; |
| 10344 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10345 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10346 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10347 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10348 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10349 | |
| 10350 | MockRead data_reads[] = { |
| 10351 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10352 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10353 | MockRead(ASYNC, OK), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10354 | }; |
| 10355 | StaticSocketDataProvider second_data( |
| 10356 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10357 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10358 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10359 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10360 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10361 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10362 | session->http_server_properties(); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10363 | const url::SchemeHostPort server(request.url); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10364 | // Port must be < 1024, or the header will be ignored (since initial port was |
| 10365 | // port 80 (another restricted port). |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 10366 | const AlternativeService alternative_service( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 10367 | AlternateProtocolFromNextProto(kProtoHTTP2), "www.example.org", |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 10368 | 666); // Port is ignored by MockConnect anyway. |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10369 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10370 | http_server_properties->SetAlternativeService(server, alternative_service, |
| 10371 | expiration); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10372 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10373 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10374 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10375 | TestCompletionCallback callback; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10376 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10377 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10378 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 10379 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10380 | |
| 10381 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10382 | ASSERT_TRUE(response); |
| 10383 | ASSERT_TRUE(response->headers); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10384 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10385 | |
| 10386 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10387 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10388 | EXPECT_EQ("hello world", response_data); |
| 10389 | |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 10390 | const AlternativeServiceVector alternative_service_vector = |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10391 | http_server_properties->GetAlternativeServices(server); |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 10392 | ASSERT_EQ(1u, alternative_service_vector.size()); |
| 10393 | EXPECT_EQ(alternative_service, alternative_service_vector[0]); |
| 10394 | EXPECT_TRUE(http_server_properties->IsAlternativeServiceBroken( |
| 10395 | alternative_service_vector[0])); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10396 | } |
| 10397 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10398 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10399 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 10400 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 10401 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10402 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedBlocked) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10403 | HttpRequestInfo restricted_port_request; |
| 10404 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10405 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10406 | restricted_port_request.load_flags = 0; |
| 10407 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10408 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10409 | StaticSocketDataProvider first_data; |
| 10410 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10411 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10412 | |
| 10413 | MockRead data_reads[] = { |
| 10414 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10415 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10416 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10417 | }; |
| 10418 | StaticSocketDataProvider second_data( |
| 10419 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10420 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10421 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10422 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10423 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10424 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10425 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10426 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10427 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10428 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10429 | const int kUnrestrictedAlternatePort = 1024; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10430 | AlternativeService alternative_service( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 10431 | AlternateProtocolFromNextProto(kProtoHTTP2), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10432 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10433 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10434 | http_server_properties->SetAlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10435 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10436 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10437 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10438 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10439 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10440 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10441 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10442 | int rv = trans->Start( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10443 | &restricted_port_request, |
| 10444 | callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10445 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10446 | // Invalid change to unrestricted port should fail. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10447 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_REFUSED)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10448 | } |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10449 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10450 | // Ensure that we are allowed to redirect traffic via an alternate protocol to |
| 10451 | // an unrestricted (port >= 1024) when the original traffic was on a restricted |
| 10452 | // port (port < 1024) if we set |enable_user_alternate_protocol_ports|. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10453 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedPermitted) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10454 | session_deps_.enable_user_alternate_protocol_ports = true; |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10455 | |
| 10456 | HttpRequestInfo restricted_port_request; |
| 10457 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10458 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10459 | restricted_port_request.load_flags = 0; |
| 10460 | |
| 10461 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 10462 | StaticSocketDataProvider first_data; |
| 10463 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10464 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10465 | |
| 10466 | MockRead data_reads[] = { |
| 10467 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10468 | MockRead("hello world"), |
| 10469 | MockRead(ASYNC, OK), |
| 10470 | }; |
| 10471 | StaticSocketDataProvider second_data( |
| 10472 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10473 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10474 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10475 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10476 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10477 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10478 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10479 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10480 | HttpServerProperties* http_server_properties = |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10481 | session->http_server_properties(); |
| 10482 | const int kUnrestrictedAlternatePort = 1024; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10483 | AlternativeService alternative_service( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 10484 | AlternateProtocolFromNextProto(kProtoHTTP2), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10485 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10486 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10487 | http_server_properties->SetAlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10488 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10489 | expiration); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10490 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10491 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10492 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10493 | TestCompletionCallback callback; |
| 10494 | |
| 10495 | EXPECT_EQ(ERR_IO_PENDING, trans->Start( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10496 | &restricted_port_request, |
| 10497 | callback.callback(), BoundNetLog())); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10498 | // Change to unrestricted port should succeed. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10499 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10500 | } |
| 10501 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10502 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10503 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 10504 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 10505 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10506 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedAllowed) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10507 | HttpRequestInfo restricted_port_request; |
| 10508 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10509 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10510 | restricted_port_request.load_flags = 0; |
| 10511 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10512 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10513 | StaticSocketDataProvider first_data; |
| 10514 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10515 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10516 | |
| 10517 | MockRead data_reads[] = { |
| 10518 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10519 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10520 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10521 | }; |
| 10522 | StaticSocketDataProvider second_data( |
| 10523 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10524 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10525 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10526 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 10527 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10528 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10529 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10530 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10531 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10532 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10533 | const int kRestrictedAlternatePort = 80; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10534 | AlternativeService alternative_service( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 10535 | AlternateProtocolFromNextProto(kProtoHTTP2), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10536 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10537 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10538 | http_server_properties->SetAlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10539 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10540 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10541 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10542 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10543 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10544 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10545 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10546 | int rv = trans->Start( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10547 | &restricted_port_request, |
| 10548 | callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10549 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10550 | // Valid change to restricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10551 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10552 | } |
| 10553 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10554 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10555 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 10556 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 10557 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10558 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortUnrestrictedAllowed1) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10559 | HttpRequestInfo unrestricted_port_request; |
| 10560 | unrestricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10561 | unrestricted_port_request.url = GURL("https://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10562 | unrestricted_port_request.load_flags = 0; |
| 10563 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10564 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10565 | StaticSocketDataProvider first_data; |
| 10566 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10567 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10568 | |
| 10569 | MockRead data_reads[] = { |
| 10570 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10571 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10572 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10573 | }; |
| 10574 | StaticSocketDataProvider second_data( |
| 10575 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10576 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10577 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10578 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10579 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10580 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10581 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10582 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10583 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10584 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10585 | const int kRestrictedAlternatePort = 80; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10586 | AlternativeService alternative_service( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 10587 | AlternateProtocolFromNextProto(kProtoHTTP2), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10588 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10589 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10590 | http_server_properties->SetAlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10591 | url::SchemeHostPort(unrestricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10592 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10593 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10594 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10595 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10596 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10597 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10598 | int rv = trans->Start( |
| 10599 | &unrestricted_port_request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10600 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10601 | // Valid change to restricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10602 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10603 | } |
| 10604 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10605 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10606 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 10607 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 10608 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10609 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortUnrestrictedAllowed2) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10610 | HttpRequestInfo unrestricted_port_request; |
| 10611 | unrestricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10612 | unrestricted_port_request.url = GURL("https://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10613 | unrestricted_port_request.load_flags = 0; |
| 10614 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10615 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10616 | StaticSocketDataProvider first_data; |
| 10617 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10618 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10619 | |
| 10620 | MockRead data_reads[] = { |
| 10621 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10622 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10623 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10624 | }; |
| 10625 | StaticSocketDataProvider second_data( |
| 10626 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10627 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10628 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10629 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 10630 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10631 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10632 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10633 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10634 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10635 | session->http_server_properties(); |
bnc | 0bbb0262 | 2015-07-23 10:06:22 | [diff] [blame] | 10636 | const int kUnrestrictedAlternatePort = 1025; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10637 | AlternativeService alternative_service( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 10638 | AlternateProtocolFromNextProto(kProtoHTTP2), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10639 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10640 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10641 | http_server_properties->SetAlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10642 | url::SchemeHostPort(unrestricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10643 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10644 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10645 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10646 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10647 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10648 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10649 | int rv = trans->Start( |
| 10650 | &unrestricted_port_request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10651 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10652 | // Valid change to an unrestricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10653 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10654 | } |
| 10655 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10656 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10657 | // to an unsafe port, and that we resume the second HttpStreamFactoryImpl::Job |
| 10658 | // once the alternate protocol request fails. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10659 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolUnsafeBlocked) { |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10660 | HttpRequestInfo request; |
| 10661 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10662 | request.url = GURL("http://www.example.org/"); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10663 | request.load_flags = 0; |
| 10664 | |
| 10665 | // The alternate protocol request will error out before we attempt to connect, |
| 10666 | // so only the standard HTTP request will try to connect. |
| 10667 | MockRead data_reads[] = { |
| 10668 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10669 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10670 | MockRead(ASYNC, OK), |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10671 | }; |
| 10672 | StaticSocketDataProvider data( |
| 10673 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10674 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10675 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10676 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10677 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10678 | HttpServerProperties* http_server_properties = |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10679 | session->http_server_properties(); |
| 10680 | const int kUnsafePort = 7; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10681 | AlternativeService alternative_service( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 10682 | AlternateProtocolFromNextProto(kProtoHTTP2), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10683 | kUnsafePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10684 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10685 | http_server_properties->SetAlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10686 | url::SchemeHostPort(request.url), alternative_service, expiration); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10687 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10688 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10689 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10690 | TestCompletionCallback callback; |
| 10691 | |
| 10692 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10693 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10694 | // The HTTP request should succeed. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10695 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10696 | |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10697 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10698 | ASSERT_TRUE(response); |
| 10699 | ASSERT_TRUE(response->headers); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10700 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10701 | |
| 10702 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10703 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10704 | EXPECT_EQ("hello world", response_data); |
| 10705 | } |
| 10706 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10707 | TEST_F(HttpNetworkTransactionTest, UseAlternateProtocolForNpnSpdy) { |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10708 | HttpRequestInfo request; |
| 10709 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10710 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10711 | request.load_flags = 0; |
| 10712 | |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10713 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10714 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 10715 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10716 | MockRead("\r\n"), |
| 10717 | MockRead("hello world"), |
| 10718 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 10719 | MockRead(ASYNC, OK)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10720 | |
| 10721 | StaticSocketDataProvider first_transaction( |
| 10722 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10723 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10724 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10725 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10726 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10727 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10728 | SSLSocketDataProvider ssl_http2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10729 | ssl_http2.next_proto = kProtoHTTP2; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10730 | ssl_http2.cert = |
| 10731 | ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 10732 | ASSERT_TRUE(ssl_http2.cert.get()); |
| 10733 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http2); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10734 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10735 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10736 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10737 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10738 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 10739 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10740 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10741 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10742 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10743 | }; |
| 10744 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10745 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 10746 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10747 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10748 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10749 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10750 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 10751 | NULL, 0, NULL, 0); |
| 10752 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 10753 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10754 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10755 | &hanging_non_alternate_protocol_socket); |
| 10756 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10757 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10758 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10759 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 10760 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10761 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10762 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10763 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10764 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 10765 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10766 | |
| 10767 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10768 | ASSERT_TRUE(response); |
| 10769 | ASSERT_TRUE(response->headers); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10770 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10771 | |
| 10772 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10773 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10774 | EXPECT_EQ("hello world", response_data); |
| 10775 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10776 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10777 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10778 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10779 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 10780 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10781 | |
| 10782 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10783 | ASSERT_TRUE(response); |
| 10784 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 10785 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10786 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 10787 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10788 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10789 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10790 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10791 | } |
| 10792 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10793 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolWithSpdyLateBinding) { |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10794 | HttpRequestInfo request; |
| 10795 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10796 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10797 | request.load_flags = 0; |
| 10798 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10799 | // First transaction receives Alt-Svc header over HTTP/1.1. |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10800 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10801 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 10802 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10803 | MockRead("\r\n"), |
| 10804 | MockRead("hello world"), |
| 10805 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 10806 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10807 | }; |
| 10808 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10809 | StaticSocketDataProvider http11_data(data_reads, arraysize(data_reads), NULL, |
| 10810 | 0); |
| 10811 | session_deps_.socket_factory->AddSocketDataProvider(&http11_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10812 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10813 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
| 10814 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
| 10815 | |
| 10816 | // Second transaction starts an alternative and a non-alternative Job. |
| 10817 | // Both sockets hang. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10818 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 10819 | StaticSocketDataProvider hanging_socket1(NULL, 0, NULL, 0); |
| 10820 | hanging_socket1.set_connect_data(never_finishing_connect); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 10821 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket1); |
| 10822 | |
| 10823 | StaticSocketDataProvider hanging_socket2(NULL, 0, NULL, 0); |
| 10824 | hanging_socket2.set_connect_data(never_finishing_connect); |
| 10825 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket2); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10826 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10827 | // Third transaction starts an alternative and a non-alternative job. |
| 10828 | // The non-alternative job hangs, but the alternative one succeeds. |
| 10829 | // The second transaction, still pending, binds to this socket. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10830 | SpdySerializedFrame req1( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10831 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10832 | SpdySerializedFrame req2( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10833 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 3, LOWEST)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10834 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10835 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 1), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10836 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 10837 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10838 | SpdySerializedFrame data1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 10839 | SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10840 | SpdySerializedFrame data2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10841 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10842 | CreateMockRead(resp1, 2), CreateMockRead(data1, 3), |
| 10843 | CreateMockRead(resp2, 4), CreateMockRead(data2, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10844 | MockRead(ASYNC, 0, 6), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10845 | }; |
| 10846 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10847 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 10848 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10849 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10850 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10851 | SSLSocketDataProvider ssl_http2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10852 | ssl_http2.next_proto = kProtoHTTP2; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10853 | ssl_http2.cert = |
| 10854 | ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 10855 | ASSERT_TRUE(ssl_http2.cert); |
| 10856 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http2); |
| 10857 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 10858 | StaticSocketDataProvider hanging_socket3(NULL, 0, NULL, 0); |
| 10859 | hanging_socket3.set_connect_data(never_finishing_connect); |
| 10860 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket3); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10861 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10862 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10863 | TestCompletionCallback callback1; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10864 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10865 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10866 | int rv = trans1.Start(&request, callback1.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10867 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 10868 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10869 | |
| 10870 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10871 | ASSERT_TRUE(response); |
| 10872 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10873 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10874 | |
| 10875 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10876 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10877 | EXPECT_EQ("hello world", response_data); |
| 10878 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10879 | TestCompletionCallback callback2; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10880 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10881 | rv = trans2.Start(&request, callback2.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10882 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10883 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10884 | TestCompletionCallback callback3; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10885 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10886 | rv = trans3.Start(&request, callback3.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10887 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10888 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10889 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
| 10890 | EXPECT_THAT(callback3.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10891 | |
| 10892 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10893 | ASSERT_TRUE(response); |
| 10894 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 10895 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10896 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 10897 | EXPECT_TRUE(response->was_npn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10898 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10899 | EXPECT_EQ("hello!", response_data); |
| 10900 | |
| 10901 | response = trans3.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10902 | ASSERT_TRUE(response); |
| 10903 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 10904 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10905 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 10906 | EXPECT_TRUE(response->was_npn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10907 | ASSERT_THAT(ReadTransaction(&trans3, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10908 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10909 | } |
| 10910 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10911 | TEST_F(HttpNetworkTransactionTest, StallAlternativeServiceForNpnSpdy) { |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10912 | HttpRequestInfo request; |
| 10913 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10914 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10915 | request.load_flags = 0; |
| 10916 | |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10917 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10918 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 10919 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10920 | MockRead("\r\n"), |
| 10921 | MockRead("hello world"), |
| 10922 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 10923 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10924 | }; |
| 10925 | |
| 10926 | StaticSocketDataProvider first_transaction( |
| 10927 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10928 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10929 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10930 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10931 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10932 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10933 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10934 | StaticSocketDataProvider hanging_alternate_protocol_socket( |
| 10935 | NULL, 0, NULL, 0); |
| 10936 | hanging_alternate_protocol_socket.set_connect_data( |
| 10937 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10938 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10939 | &hanging_alternate_protocol_socket); |
| 10940 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10941 | // 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] | 10942 | StaticSocketDataProvider second_transaction(data_reads, arraysize(data_reads), |
| 10943 | NULL, 0); |
| 10944 | session_deps_.socket_factory->AddSocketDataProvider(&second_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10945 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10946 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10947 | TestCompletionCallback callback; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10948 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10949 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 10950 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10951 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10952 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10953 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10954 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 10955 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10956 | |
| 10957 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10958 | ASSERT_TRUE(response); |
| 10959 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10960 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10961 | |
| 10962 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10963 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10964 | EXPECT_EQ("hello world", response_data); |
| 10965 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10966 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10967 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10968 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10969 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 10970 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10971 | |
| 10972 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10973 | ASSERT_TRUE(response); |
| 10974 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10975 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10976 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 10977 | EXPECT_FALSE(response->was_npn_negotiated); |
| 10978 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10979 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10980 | EXPECT_EQ("hello world", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10981 | } |
| 10982 | |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10983 | class CapturingProxyResolver : public ProxyResolver { |
| 10984 | public: |
sammc | e90c921 | 2015-05-27 23:43:35 | [diff] [blame] | 10985 | CapturingProxyResolver() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 10986 | ~CapturingProxyResolver() override {} |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10987 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 10988 | int GetProxyForURL(const GURL& url, |
| 10989 | ProxyInfo* results, |
| 10990 | const CompletionCallback& callback, |
eroman | 9c8f424 | 2016-02-29 21:16:54 | [diff] [blame] | 10991 | RequestHandle* request, |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 10992 | const BoundNetLog& net_log) override { |
[email protected] | fae7669f | 2010-08-02 21:49:40 | [diff] [blame] | 10993 | ProxyServer proxy_server(ProxyServer::SCHEME_HTTP, |
| 10994 | HostPortPair("myproxy", 80)); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 10995 | results->UseProxyServer(proxy_server); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10996 | resolved_.push_back(url); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 10997 | return OK; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10998 | } |
| 10999 | |
eroman | 9c8f424 | 2016-02-29 21:16:54 | [diff] [blame] | 11000 | void CancelRequest(RequestHandle request) override { NOTREACHED(); } |
| 11001 | |
| 11002 | LoadState GetLoadState(RequestHandle request) const override { |
| 11003 | NOTREACHED(); |
| 11004 | return LOAD_STATE_IDLE; |
| 11005 | } |
| 11006 | |
[email protected] | 2447640 | 2010-07-20 20:55:17 | [diff] [blame] | 11007 | const std::vector<GURL>& resolved() const { return resolved_; } |
| 11008 | |
| 11009 | private: |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11010 | std::vector<GURL> resolved_; |
| 11011 | |
| 11012 | DISALLOW_COPY_AND_ASSIGN(CapturingProxyResolver); |
| 11013 | }; |
| 11014 | |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 11015 | class CapturingProxyResolverFactory : public ProxyResolverFactory { |
| 11016 | public: |
| 11017 | explicit CapturingProxyResolverFactory(CapturingProxyResolver* resolver) |
| 11018 | : ProxyResolverFactory(false), resolver_(resolver) {} |
| 11019 | |
| 11020 | int CreateProxyResolver( |
| 11021 | const scoped_refptr<ProxyResolverScriptData>& pac_script, |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11022 | std::unique_ptr<ProxyResolver>* resolver, |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 11023 | const net::CompletionCallback& callback, |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11024 | std::unique_ptr<Request>* request) override { |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 11025 | resolver->reset(new ForwardingProxyResolver(resolver_)); |
| 11026 | return OK; |
| 11027 | } |
| 11028 | |
| 11029 | private: |
| 11030 | ProxyResolver* resolver_; |
| 11031 | }; |
| 11032 | |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame^] | 11033 | // Test that proxy is resolved using the origin url, |
| 11034 | // regardless of the alternative server. |
| 11035 | TEST_F(HttpNetworkTransactionTest, UseOriginNotAlternativeForProxy) { |
| 11036 | // Configure proxy to bypass www.example.org, which is the origin URL. |
| 11037 | ProxyConfig proxy_config; |
| 11038 | proxy_config.proxy_rules().ParseFromString("myproxy:70"); |
| 11039 | proxy_config.proxy_rules().bypass_rules.AddRuleFromString("www.example.org"); |
| 11040 | auto proxy_config_service = |
| 11041 | base::MakeUnique<ProxyConfigServiceFixed>(proxy_config); |
| 11042 | |
| 11043 | CapturingProxyResolver capturing_proxy_resolver; |
| 11044 | auto proxy_resolver_factory = base::MakeUnique<CapturingProxyResolverFactory>( |
| 11045 | &capturing_proxy_resolver); |
| 11046 | |
| 11047 | TestNetLog net_log; |
| 11048 | |
| 11049 | session_deps_.proxy_service = base::MakeUnique<ProxyService>( |
| 11050 | std::move(proxy_config_service), std::move(proxy_resolver_factory), |
| 11051 | &net_log); |
| 11052 | |
| 11053 | session_deps_.net_log = &net_log; |
| 11054 | |
| 11055 | // Configure alternative service with a hostname that is not bypassed by the |
| 11056 | // proxy. |
| 11057 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 11058 | HttpServerProperties* http_server_properties = |
| 11059 | session->http_server_properties(); |
| 11060 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 11061 | HostPortPair alternative("www.example.com", 443); |
| 11062 | AlternativeService alternative_service( |
| 11063 | AlternateProtocolFromNextProto(kProtoHTTP2), alternative); |
| 11064 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 11065 | http_server_properties->SetAlternativeService(server, alternative_service, |
| 11066 | expiration); |
| 11067 | |
| 11068 | // Non-alternative job should hang. |
| 11069 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
| 11070 | StaticSocketDataProvider hanging_alternate_protocol_socket(nullptr, 0, |
| 11071 | nullptr, 0); |
| 11072 | hanging_alternate_protocol_socket.set_connect_data(never_finishing_connect); |
| 11073 | session_deps_.socket_factory->AddSocketDataProvider( |
| 11074 | &hanging_alternate_protocol_socket); |
| 11075 | |
| 11076 | SSLSocketDataProvider ssl_http2(ASYNC, OK); |
| 11077 | ssl_http2.next_proto = kProtoHTTP2; |
| 11078 | ssl_http2.cert = |
| 11079 | ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 11080 | ASSERT_TRUE(ssl_http2.cert); |
| 11081 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http2); |
| 11082 | |
| 11083 | HttpRequestInfo request; |
| 11084 | request.method = "GET"; |
| 11085 | request.url = GURL("https://www.example.org/"); |
| 11086 | request.load_flags = 0; |
| 11087 | |
| 11088 | SpdySerializedFrame req( |
| 11089 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
| 11090 | |
| 11091 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
| 11092 | |
| 11093 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 11094 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 11095 | MockRead spdy_reads[] = { |
| 11096 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
| 11097 | }; |
| 11098 | |
| 11099 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 11100 | arraysize(spdy_writes)); |
| 11101 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 11102 | |
| 11103 | TestCompletionCallback callback; |
| 11104 | |
| 11105 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 11106 | |
| 11107 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
| 11108 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 11109 | |
| 11110 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 11111 | ASSERT_TRUE(response); |
| 11112 | ASSERT_TRUE(response->headers); |
| 11113 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 11114 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 11115 | EXPECT_TRUE(response->was_npn_negotiated); |
| 11116 | |
| 11117 | std::string response_data; |
| 11118 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 11119 | EXPECT_EQ("hello!", response_data); |
| 11120 | |
| 11121 | // Origin host bypasses proxy, no resolution should have happened. |
| 11122 | ASSERT_TRUE(capturing_proxy_resolver.resolved().empty()); |
| 11123 | } |
| 11124 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11125 | TEST_F(HttpNetworkTransactionTest, UseAlternativeServiceForTunneledNpnSpdy) { |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11126 | ProxyConfig proxy_config; |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 11127 | proxy_config.set_auto_detect(true); |
| 11128 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 11129 | |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 11130 | CapturingProxyResolver capturing_proxy_resolver; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11131 | session_deps_.proxy_service.reset(new ProxyService( |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11132 | base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), |
| 11133 | base::WrapUnique( |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 11134 | new CapturingProxyResolverFactory(&capturing_proxy_resolver)), |
[email protected] | 66761b95 | 2010-06-25 21:30:38 | [diff] [blame] | 11135 | NULL)); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11136 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11137 | session_deps_.net_log = &net_log; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11138 | |
| 11139 | HttpRequestInfo request; |
| 11140 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11141 | request.url = GURL("https://www.example.org/"); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11142 | request.load_flags = 0; |
| 11143 | |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11144 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11145 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11146 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11147 | MockRead("\r\n"), |
| 11148 | MockRead("hello world"), |
| 11149 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 11150 | MockRead(ASYNC, OK), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11151 | }; |
| 11152 | |
| 11153 | StaticSocketDataProvider first_transaction( |
| 11154 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11155 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11156 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11157 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11158 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11159 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11160 | SSLSocketDataProvider ssl_http2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11161 | ssl_http2.next_proto = kProtoHTTP2; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11162 | ssl_http2.cert = |
| 11163 | ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 11164 | ASSERT_TRUE(ssl_http2.cert); |
| 11165 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http2); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11166 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11167 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11168 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11169 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11170 | MockWrite(ASYNC, 0, |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11171 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 11172 | "Host: www.example.org:443\r\n" |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11173 | "Proxy-Connection: keep-alive\r\n\r\n"), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11174 | CreateMockWrite(req, 2), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11175 | }; |
| 11176 | |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 11177 | const char kCONNECTResponse[] = "HTTP/1.1 200 Connected\r\n\r\n"; |
| 11178 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 11179 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11180 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11181 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11182 | MockRead(ASYNC, 1, kCONNECTResponse), CreateMockRead(resp, 3), |
| 11183 | CreateMockRead(data, 4), MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11184 | }; |
| 11185 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11186 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 11187 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11188 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11189 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11190 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11191 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 11192 | NULL, 0, NULL, 0); |
| 11193 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 11194 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11195 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11196 | &hanging_non_alternate_protocol_socket); |
| 11197 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11198 | TestCompletionCallback callback; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11199 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11200 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 11201 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11202 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11203 | |
mmenke | e2172e4 | 2016-07-15 03:14:32 | [diff] [blame] | 11204 | // HTTP/0.9 should fail. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11205 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
mmenke | e2172e4 | 2016-07-15 03:14:32 | [diff] [blame] | 11206 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_INVALID_HTTP_RESPONSE)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11207 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11208 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11209 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11210 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11211 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11212 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11213 | |
mmenke | e2172e4 | 2016-07-15 03:14:32 | [diff] [blame] | 11214 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11215 | ASSERT_TRUE(response); |
| 11216 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 11217 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11218 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 11219 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11220 | |
mmenke | e2172e4 | 2016-07-15 03:14:32 | [diff] [blame] | 11221 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11222 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11223 | EXPECT_EQ("hello!", response_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11224 | ASSERT_EQ(2u, capturing_proxy_resolver.resolved().size()); |
| 11225 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 11226 | capturing_proxy_resolver.resolved()[0].spec()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11227 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 11228 | capturing_proxy_resolver.resolved()[1].spec()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11229 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11230 | LoadTimingInfo load_timing_info; |
| 11231 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 11232 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 11233 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11234 | } |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11235 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11236 | TEST_F(HttpNetworkTransactionTest, |
bnc | 1c196c6e | 2016-05-28 13:51:48 | [diff] [blame] | 11237 | UseAlternativeServiceForNpnSpdyWithExistingSpdySession) { |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11238 | HttpRequestInfo request; |
| 11239 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11240 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11241 | request.load_flags = 0; |
| 11242 | |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11243 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11244 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11245 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11246 | MockRead("\r\n"), |
| 11247 | MockRead("hello world"), |
| 11248 | MockRead(ASYNC, OK), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11249 | }; |
| 11250 | |
| 11251 | StaticSocketDataProvider first_transaction( |
| 11252 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11253 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11254 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11255 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11256 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11257 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11258 | SSLSocketDataProvider ssl_http2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11259 | ssl_http2.next_proto = kProtoHTTP2; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11260 | ssl_http2.cert = |
| 11261 | ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 11262 | ASSERT_TRUE(ssl_http2.cert); |
| 11263 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http2); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11264 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11265 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11266 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11267 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11268 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 11269 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11270 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11271 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11272 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11273 | }; |
| 11274 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11275 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 11276 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11277 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11278 | |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 11279 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11280 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11281 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11282 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11283 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11284 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11285 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11286 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11287 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11288 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11289 | |
| 11290 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11291 | ASSERT_TRUE(response); |
| 11292 | ASSERT_TRUE(response->headers); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11293 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11294 | |
| 11295 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11296 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11297 | EXPECT_EQ("hello world", response_data); |
| 11298 | |
| 11299 | // Set up an initial SpdySession in the pool to reuse. |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11300 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 11301 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 11302 | PRIVACY_MODE_DISABLED); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 11303 | base::WeakPtr<SpdySession> spdy_session = |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11304 | CreateSecureSpdySession(session.get(), key, BoundNetLog()); |
[email protected] | 02b0c34 | 2010-09-25 21:09:38 | [diff] [blame] | 11305 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11306 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11307 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11308 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11309 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11310 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11311 | |
| 11312 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11313 | ASSERT_TRUE(response); |
| 11314 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 11315 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11316 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 11317 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11318 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11319 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11320 | EXPECT_EQ("hello!", response_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11321 | } |
| 11322 | |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11323 | // GenerateAuthToken is a mighty big test. |
| 11324 | // It tests all permutation of GenerateAuthToken behavior: |
| 11325 | // - Synchronous and Asynchronous completion. |
| 11326 | // - OK or error on completion. |
| 11327 | // - Direct connection, non-authenticating proxy, and authenticating proxy. |
| 11328 | // - HTTP or HTTPS backend (to include proxy tunneling). |
| 11329 | // - Non-authenticating and authenticating backend. |
| 11330 | // |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 11331 | // In all, there are 44 reasonable permuations (for example, if there are |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11332 | // problems generating an auth token for an authenticating proxy, we don't |
| 11333 | // need to test all permutations of the backend server). |
| 11334 | // |
| 11335 | // The test proceeds by going over each of the configuration cases, and |
| 11336 | // potentially running up to three rounds in each of the tests. The TestConfig |
| 11337 | // specifies both the configuration for the test as well as the expectations |
| 11338 | // for the results. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11339 | TEST_F(HttpNetworkTransactionTest, GenerateAuthToken) { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11340 | static const char kServer[] = "http://www.example.com"; |
| 11341 | static const char kSecureServer[] = "https://www.example.com"; |
| 11342 | static const char kProxy[] = "myproxy:70"; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11343 | const int kAuthErr = ERR_INVALID_AUTH_CREDENTIALS; |
| 11344 | |
| 11345 | enum AuthTiming { |
| 11346 | AUTH_NONE, |
| 11347 | AUTH_SYNC, |
| 11348 | AUTH_ASYNC, |
| 11349 | }; |
| 11350 | |
| 11351 | const MockWrite kGet( |
| 11352 | "GET / HTTP/1.1\r\n" |
| 11353 | "Host: www.example.com\r\n" |
| 11354 | "Connection: keep-alive\r\n\r\n"); |
| 11355 | const MockWrite kGetProxy( |
| 11356 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 11357 | "Host: www.example.com\r\n" |
| 11358 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 11359 | const MockWrite kGetAuth( |
| 11360 | "GET / HTTP/1.1\r\n" |
| 11361 | "Host: www.example.com\r\n" |
| 11362 | "Connection: keep-alive\r\n" |
| 11363 | "Authorization: auth_token\r\n\r\n"); |
| 11364 | const MockWrite kGetProxyAuth( |
| 11365 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 11366 | "Host: www.example.com\r\n" |
| 11367 | "Proxy-Connection: keep-alive\r\n" |
| 11368 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 11369 | const MockWrite kGetAuthThroughProxy( |
| 11370 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 11371 | "Host: www.example.com\r\n" |
| 11372 | "Proxy-Connection: keep-alive\r\n" |
| 11373 | "Authorization: auth_token\r\n\r\n"); |
| 11374 | const MockWrite kGetAuthWithProxyAuth( |
| 11375 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 11376 | "Host: www.example.com\r\n" |
| 11377 | "Proxy-Connection: keep-alive\r\n" |
| 11378 | "Proxy-Authorization: auth_token\r\n" |
| 11379 | "Authorization: auth_token\r\n\r\n"); |
| 11380 | const MockWrite kConnect( |
| 11381 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 11382 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11383 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 11384 | const MockWrite kConnectProxyAuth( |
| 11385 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 11386 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11387 | "Proxy-Connection: keep-alive\r\n" |
| 11388 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 11389 | |
| 11390 | const MockRead kSuccess( |
| 11391 | "HTTP/1.1 200 OK\r\n" |
| 11392 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11393 | "Content-Length: 3\r\n\r\n" |
| 11394 | "Yes"); |
| 11395 | const MockRead kFailure( |
| 11396 | "Should not be called."); |
| 11397 | const MockRead kServerChallenge( |
| 11398 | "HTTP/1.1 401 Unauthorized\r\n" |
| 11399 | "WWW-Authenticate: Mock realm=server\r\n" |
| 11400 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11401 | "Content-Length: 14\r\n\r\n" |
| 11402 | "Unauthorized\r\n"); |
| 11403 | const MockRead kProxyChallenge( |
| 11404 | "HTTP/1.1 407 Unauthorized\r\n" |
| 11405 | "Proxy-Authenticate: Mock realm=proxy\r\n" |
| 11406 | "Proxy-Connection: close\r\n" |
| 11407 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11408 | "Content-Length: 14\r\n\r\n" |
| 11409 | "Unauthorized\r\n"); |
| 11410 | const MockRead kProxyConnected( |
| 11411 | "HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 11412 | |
| 11413 | // NOTE(cbentzel): I wanted TestReadWriteRound to be a simple struct with |
| 11414 | // no constructors, but the C++ compiler on Windows warns about |
| 11415 | // unspecified data in compound literals. So, moved to using constructors, |
| 11416 | // and TestRound's created with the default constructor should not be used. |
| 11417 | struct TestRound { |
| 11418 | TestRound() |
| 11419 | : expected_rv(ERR_UNEXPECTED), |
| 11420 | extra_write(NULL), |
| 11421 | extra_read(NULL) { |
| 11422 | } |
| 11423 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 11424 | int expected_rv_arg) |
| 11425 | : write(write_arg), |
| 11426 | read(read_arg), |
| 11427 | expected_rv(expected_rv_arg), |
| 11428 | extra_write(NULL), |
| 11429 | extra_read(NULL) { |
| 11430 | } |
| 11431 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 11432 | int expected_rv_arg, const MockWrite* extra_write_arg, |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 11433 | const MockRead* extra_read_arg) |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11434 | : write(write_arg), |
| 11435 | read(read_arg), |
| 11436 | expected_rv(expected_rv_arg), |
| 11437 | extra_write(extra_write_arg), |
| 11438 | extra_read(extra_read_arg) { |
| 11439 | } |
| 11440 | MockWrite write; |
| 11441 | MockRead read; |
| 11442 | int expected_rv; |
| 11443 | const MockWrite* extra_write; |
| 11444 | const MockRead* extra_read; |
| 11445 | }; |
| 11446 | |
| 11447 | static const int kNoSSL = 500; |
| 11448 | |
| 11449 | struct TestConfig { |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 11450 | const char* const proxy_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11451 | AuthTiming proxy_auth_timing; |
| 11452 | int proxy_auth_rv; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 11453 | const char* const server_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11454 | AuthTiming server_auth_timing; |
| 11455 | int server_auth_rv; |
| 11456 | int num_auth_rounds; |
| 11457 | int first_ssl_round; |
| 11458 | TestRound rounds[3]; |
| 11459 | } test_configs[] = { |
| 11460 | // Non-authenticating HTTP server with a direct connection. |
| 11461 | { NULL, AUTH_NONE, OK, kServer, AUTH_NONE, OK, 1, kNoSSL, |
| 11462 | { TestRound(kGet, kSuccess, OK)}}, |
| 11463 | // Authenticating HTTP server with a direct connection. |
| 11464 | { NULL, AUTH_NONE, OK, kServer, AUTH_SYNC, OK, 2, kNoSSL, |
| 11465 | { TestRound(kGet, kServerChallenge, OK), |
| 11466 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11467 | { NULL, AUTH_NONE, OK, kServer, AUTH_SYNC, kAuthErr, 2, kNoSSL, |
| 11468 | { TestRound(kGet, kServerChallenge, OK), |
| 11469 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11470 | { NULL, AUTH_NONE, OK, kServer, AUTH_ASYNC, OK, 2, kNoSSL, |
| 11471 | { TestRound(kGet, kServerChallenge, OK), |
| 11472 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11473 | { NULL, AUTH_NONE, OK, kServer, AUTH_ASYNC, kAuthErr, 2, kNoSSL, |
| 11474 | { TestRound(kGet, kServerChallenge, OK), |
| 11475 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11476 | // Non-authenticating HTTP server through a non-authenticating proxy. |
| 11477 | { kProxy, AUTH_NONE, OK, kServer, AUTH_NONE, OK, 1, kNoSSL, |
| 11478 | { TestRound(kGetProxy, kSuccess, OK)}}, |
| 11479 | // Authenticating HTTP server through a non-authenticating proxy. |
| 11480 | { kProxy, AUTH_NONE, OK, kServer, AUTH_SYNC, OK, 2, kNoSSL, |
| 11481 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 11482 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
| 11483 | { kProxy, AUTH_NONE, OK, kServer, AUTH_SYNC, kAuthErr, 2, kNoSSL, |
| 11484 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 11485 | TestRound(kGetAuthThroughProxy, kFailure, kAuthErr)}}, |
| 11486 | { kProxy, AUTH_NONE, OK, kServer, AUTH_ASYNC, OK, 2, kNoSSL, |
| 11487 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 11488 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
| 11489 | { kProxy, AUTH_NONE, OK, kServer, AUTH_ASYNC, kAuthErr, 2, kNoSSL, |
| 11490 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 11491 | TestRound(kGetAuthThroughProxy, kFailure, kAuthErr)}}, |
| 11492 | // Non-authenticating HTTP server through an authenticating proxy. |
| 11493 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 11494 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11495 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
| 11496 | { kProxy, AUTH_SYNC, kAuthErr, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 11497 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11498 | TestRound(kGetProxyAuth, kFailure, kAuthErr)}}, |
| 11499 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 11500 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11501 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
| 11502 | { kProxy, AUTH_ASYNC, kAuthErr, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 11503 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11504 | TestRound(kGetProxyAuth, kFailure, kAuthErr)}}, |
| 11505 | // Authenticating HTTP server through an authenticating proxy. |
| 11506 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_SYNC, OK, 3, kNoSSL, |
| 11507 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11508 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11509 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 11510 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_SYNC, kAuthErr, 3, kNoSSL, |
| 11511 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11512 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11513 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 11514 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_SYNC, OK, 3, kNoSSL, |
| 11515 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11516 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11517 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 11518 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_SYNC, kAuthErr, 3, kNoSSL, |
| 11519 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11520 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11521 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 11522 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_ASYNC, OK, 3, kNoSSL, |
| 11523 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11524 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11525 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 11526 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_ASYNC, kAuthErr, 3, kNoSSL, |
| 11527 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11528 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11529 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 11530 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_ASYNC, OK, 3, kNoSSL, |
| 11531 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11532 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11533 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 11534 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_ASYNC, kAuthErr, 3, kNoSSL, |
| 11535 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11536 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11537 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 11538 | // Non-authenticating HTTPS server with a direct connection. |
| 11539 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_NONE, OK, 1, 0, |
| 11540 | { TestRound(kGet, kSuccess, OK)}}, |
| 11541 | // Authenticating HTTPS server with a direct connection. |
| 11542 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, OK, 2, 0, |
| 11543 | { TestRound(kGet, kServerChallenge, OK), |
| 11544 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11545 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, kAuthErr, 2, 0, |
| 11546 | { TestRound(kGet, kServerChallenge, OK), |
| 11547 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11548 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, OK, 2, 0, |
| 11549 | { TestRound(kGet, kServerChallenge, OK), |
| 11550 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11551 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 2, 0, |
| 11552 | { TestRound(kGet, kServerChallenge, OK), |
| 11553 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11554 | // Non-authenticating HTTPS server with a non-authenticating proxy. |
| 11555 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_NONE, OK, 1, 0, |
| 11556 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 11557 | // Authenticating HTTPS server through a non-authenticating proxy. |
| 11558 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, OK, 2, 0, |
| 11559 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 11560 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11561 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, kAuthErr, 2, 0, |
| 11562 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 11563 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11564 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, OK, 2, 0, |
| 11565 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 11566 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11567 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 2, 0, |
| 11568 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 11569 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11570 | // Non-Authenticating HTTPS server through an authenticating proxy. |
| 11571 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_NONE, OK, 2, 1, |
| 11572 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11573 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 11574 | { kProxy, AUTH_SYNC, kAuthErr, kSecureServer, AUTH_NONE, OK, 2, kNoSSL, |
| 11575 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11576 | TestRound(kConnectProxyAuth, kFailure, kAuthErr)}}, |
| 11577 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_NONE, OK, 2, 1, |
| 11578 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11579 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 11580 | { kProxy, AUTH_ASYNC, kAuthErr, kSecureServer, AUTH_NONE, OK, 2, kNoSSL, |
| 11581 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11582 | TestRound(kConnectProxyAuth, kFailure, kAuthErr)}}, |
| 11583 | // Authenticating HTTPS server through an authenticating proxy. |
| 11584 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_SYNC, OK, 3, 1, |
| 11585 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11586 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 11587 | &kGet, &kServerChallenge), |
| 11588 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11589 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_SYNC, kAuthErr, 3, 1, |
| 11590 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11591 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 11592 | &kGet, &kServerChallenge), |
| 11593 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11594 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_SYNC, OK, 3, 1, |
| 11595 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11596 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 11597 | &kGet, &kServerChallenge), |
| 11598 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11599 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_SYNC, kAuthErr, 3, 1, |
| 11600 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11601 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 11602 | &kGet, &kServerChallenge), |
| 11603 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11604 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_ASYNC, OK, 3, 1, |
| 11605 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11606 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 11607 | &kGet, &kServerChallenge), |
| 11608 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11609 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 3, 1, |
| 11610 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11611 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 11612 | &kGet, &kServerChallenge), |
| 11613 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11614 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_ASYNC, OK, 3, 1, |
| 11615 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11616 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 11617 | &kGet, &kServerChallenge), |
| 11618 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11619 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 3, 1, |
| 11620 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11621 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 11622 | &kGet, &kServerChallenge), |
| 11623 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11624 | }; |
| 11625 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 11626 | for (size_t i = 0; i < arraysize(test_configs); ++i) { |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 11627 | HttpAuthHandlerMock::Factory* auth_factory( |
| 11628 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11629 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 11630 | SSLInfo empty_ssl_info; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11631 | const TestConfig& test_config = test_configs[i]; |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 11632 | |
| 11633 | // Set up authentication handlers as necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11634 | if (test_config.proxy_auth_timing != AUTH_NONE) { |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 11635 | for (int n = 0; n < 2; n++) { |
| 11636 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 11637 | std::string auth_challenge = "Mock realm=proxy"; |
| 11638 | GURL origin(test_config.proxy_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 11639 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 11640 | auth_challenge.end()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 11641 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_PROXY, |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 11642 | empty_ssl_info, origin, BoundNetLog()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 11643 | auth_handler->SetGenerateExpectation( |
| 11644 | test_config.proxy_auth_timing == AUTH_ASYNC, |
| 11645 | test_config.proxy_auth_rv); |
| 11646 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
| 11647 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11648 | } |
| 11649 | if (test_config.server_auth_timing != AUTH_NONE) { |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 11650 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11651 | std::string auth_challenge = "Mock realm=server"; |
| 11652 | GURL origin(test_config.server_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 11653 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 11654 | auth_challenge.end()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11655 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 11656 | empty_ssl_info, origin, BoundNetLog()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11657 | auth_handler->SetGenerateExpectation( |
| 11658 | test_config.server_auth_timing == AUTH_ASYNC, |
| 11659 | test_config.server_auth_rv); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 11660 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11661 | } |
| 11662 | if (test_config.proxy_url) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 11663 | session_deps_.proxy_service = |
| 11664 | ProxyService::CreateFixed(test_config.proxy_url); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11665 | } else { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 11666 | session_deps_.proxy_service = ProxyService::CreateDirect(); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11667 | } |
| 11668 | |
| 11669 | HttpRequestInfo request; |
| 11670 | request.method = "GET"; |
| 11671 | request.url = GURL(test_config.server_url); |
| 11672 | request.load_flags = 0; |
| 11673 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11674 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11675 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11676 | SSLSocketDataProvider ssl_socket_data_provider(SYNCHRONOUS, OK); |
| 11677 | |
| 11678 | std::vector<std::vector<MockRead>> mock_reads(1); |
| 11679 | std::vector<std::vector<MockWrite>> mock_writes(1); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11680 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
| 11681 | const TestRound& read_write_round = test_config.rounds[round]; |
| 11682 | |
| 11683 | // Set up expected reads and writes. |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11684 | mock_reads.back().push_back(read_write_round.read); |
| 11685 | mock_writes.back().push_back(read_write_round.write); |
| 11686 | |
| 11687 | // kProxyChallenge uses Proxy-Connection: close which means that the |
| 11688 | // socket is closed and a new one will be created for the next request. |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 11689 | if (read_write_round.read.data == kProxyChallenge.data) { |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11690 | mock_reads.push_back(std::vector<MockRead>()); |
| 11691 | mock_writes.push_back(std::vector<MockWrite>()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11692 | } |
| 11693 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11694 | if (read_write_round.extra_read) { |
| 11695 | mock_reads.back().push_back(*read_write_round.extra_read); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11696 | } |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11697 | if (read_write_round.extra_write) { |
| 11698 | mock_writes.back().push_back(*read_write_round.extra_write); |
| 11699 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11700 | |
| 11701 | // Add an SSL sequence if necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11702 | if (round >= test_config.first_ssl_round) |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11703 | session_deps_.socket_factory->AddSSLSocketDataProvider( |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11704 | &ssl_socket_data_provider); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11705 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11706 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11707 | std::vector<std::unique_ptr<StaticSocketDataProvider>> data_providers; |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11708 | for (size_t i = 0; i < mock_reads.size(); ++i) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11709 | data_providers.push_back(base::WrapUnique(new StaticSocketDataProvider( |
davidben | 5f8b6bc | 2015-11-25 03:19:54 | [diff] [blame] | 11710 | mock_reads[i].data(), mock_reads[i].size(), mock_writes[i].data(), |
olli.raula | 525048c | 2015-12-10 07:38:32 | [diff] [blame] | 11711 | mock_writes[i].size()))); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11712 | session_deps_.socket_factory->AddSocketDataProvider( |
olli.raula | 525048c | 2015-12-10 07:38:32 | [diff] [blame] | 11713 | data_providers.back().get()); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11714 | } |
| 11715 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 11716 | // Transaction must be created after DataProviders, so it's destroyed before |
| 11717 | // they are as well. |
| 11718 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 11719 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11720 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
| 11721 | const TestRound& read_write_round = test_config.rounds[round]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11722 | // Start or restart the transaction. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11723 | TestCompletionCallback callback; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11724 | int rv; |
| 11725 | if (round == 0) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11726 | rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11727 | } else { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11728 | rv = trans.RestartWithAuth( |
| 11729 | AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11730 | } |
| 11731 | if (rv == ERR_IO_PENDING) |
| 11732 | rv = callback.WaitForResult(); |
| 11733 | |
| 11734 | // Compare results with expected data. |
| 11735 | EXPECT_EQ(read_write_round.expected_rv, rv); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11736 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | c0c82849 | 2015-05-15 01:25:55 | [diff] [blame] | 11737 | if (read_write_round.expected_rv != OK) { |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11738 | EXPECT_EQ(round + 1, test_config.num_auth_rounds); |
| 11739 | continue; |
| 11740 | } |
| 11741 | if (round + 1 < test_config.num_auth_rounds) { |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11742 | EXPECT_TRUE(response->auth_challenge); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11743 | } else { |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11744 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11745 | } |
| 11746 | } |
[email protected] | e5ae96a | 2010-04-14 20:12:45 | [diff] [blame] | 11747 | } |
| 11748 | } |
| 11749 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11750 | TEST_F(HttpNetworkTransactionTest, MultiRoundAuth) { |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11751 | // Do multi-round authentication and make sure it works correctly. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11752 | HttpAuthHandlerMock::Factory* auth_factory( |
| 11753 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11754 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 11755 | session_deps_.proxy_service = ProxyService::CreateDirect(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11756 | session_deps_.host_resolver->rules()->AddRule("www.example.com", "10.0.0.1"); |
| 11757 | session_deps_.host_resolver->set_synchronous_mode(true); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11758 | |
| 11759 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 11760 | auth_handler->set_connection_based(true); |
| 11761 | std::string auth_challenge = "Mock realm=server"; |
| 11762 | GURL origin("http://www.example.com"); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 11763 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 11764 | auth_challenge.end()); |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 11765 | SSLInfo empty_ssl_info; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11766 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 11767 | empty_ssl_info, origin, BoundNetLog()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 11768 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11769 | |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11770 | int rv = OK; |
| 11771 | const HttpResponseInfo* response = NULL; |
| 11772 | HttpRequestInfo request; |
| 11773 | request.method = "GET"; |
| 11774 | request.url = origin; |
| 11775 | request.load_flags = 0; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11776 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11777 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11778 | |
| 11779 | // Use a TCP Socket Pool with only one connection per group. This is used |
| 11780 | // to validate that the TCP socket is not released to the pool between |
| 11781 | // each round of multi-round authentication. |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11782 | HttpNetworkSessionPeer session_peer(session.get()); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 11783 | TransportClientSocketPool* transport_pool = new TransportClientSocketPool( |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11784 | 50, // Max sockets for pool |
| 11785 | 1, // Max sockets per group |
tbansal | 7b403bcc | 2016-04-13 22:33:21 | [diff] [blame] | 11786 | session_deps_.host_resolver.get(), session_deps_.socket_factory.get(), |
| 11787 | NULL, session_deps_.net_log); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11788 | std::unique_ptr<MockClientSocketPoolManager> mock_pool_manager( |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 11789 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 11790 | mock_pool_manager->SetTransportSocketPool(transport_pool); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 11791 | session_peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11792 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11793 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11794 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11795 | TestCompletionCallback callback; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11796 | |
| 11797 | const MockWrite kGet( |
| 11798 | "GET / HTTP/1.1\r\n" |
| 11799 | "Host: www.example.com\r\n" |
| 11800 | "Connection: keep-alive\r\n\r\n"); |
| 11801 | const MockWrite kGetAuth( |
| 11802 | "GET / HTTP/1.1\r\n" |
| 11803 | "Host: www.example.com\r\n" |
| 11804 | "Connection: keep-alive\r\n" |
| 11805 | "Authorization: auth_token\r\n\r\n"); |
| 11806 | |
| 11807 | const MockRead kServerChallenge( |
| 11808 | "HTTP/1.1 401 Unauthorized\r\n" |
| 11809 | "WWW-Authenticate: Mock realm=server\r\n" |
| 11810 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11811 | "Content-Length: 14\r\n\r\n" |
| 11812 | "Unauthorized\r\n"); |
| 11813 | const MockRead kSuccess( |
| 11814 | "HTTP/1.1 200 OK\r\n" |
| 11815 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11816 | "Content-Length: 3\r\n\r\n" |
| 11817 | "Yes"); |
| 11818 | |
| 11819 | MockWrite writes[] = { |
| 11820 | // First round |
| 11821 | kGet, |
| 11822 | // Second round |
| 11823 | kGetAuth, |
| 11824 | // Third round |
| 11825 | kGetAuth, |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 11826 | // Fourth round |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11827 | kGetAuth, |
| 11828 | // Competing request |
| 11829 | kGet, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11830 | }; |
| 11831 | MockRead reads[] = { |
| 11832 | // First round |
| 11833 | kServerChallenge, |
| 11834 | // Second round |
| 11835 | kServerChallenge, |
| 11836 | // Third round |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 11837 | kServerChallenge, |
| 11838 | // Fourth round |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11839 | kSuccess, |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11840 | // Competing response |
| 11841 | kSuccess, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11842 | }; |
| 11843 | StaticSocketDataProvider data_provider(reads, arraysize(reads), |
| 11844 | writes, arraysize(writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11845 | session_deps_.socket_factory->AddSocketDataProvider(&data_provider); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11846 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 11847 | const char kSocketGroup[] = "www.example.com:80"; |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11848 | |
| 11849 | // First round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11850 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11851 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11852 | if (rv == ERR_IO_PENDING) |
| 11853 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11854 | EXPECT_THAT(rv, IsOk()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11855 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11856 | ASSERT_TRUE(response); |
| 11857 | EXPECT_TRUE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 11858 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11859 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11860 | // In between rounds, another request comes in for the same domain. |
| 11861 | // It should not be able to grab the TCP socket that trans has already |
| 11862 | // claimed. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11863 | std::unique_ptr<HttpTransaction> trans_compete( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11864 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11865 | TestCompletionCallback callback_compete; |
| 11866 | rv = trans_compete->Start( |
| 11867 | &request, callback_compete.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11868 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11869 | // callback_compete.WaitForResult at this point would stall forever, |
| 11870 | // since the HttpNetworkTransaction does not release the request back to |
| 11871 | // the pool until after authentication completes. |
| 11872 | |
| 11873 | // Second round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11874 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11875 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11876 | if (rv == ERR_IO_PENDING) |
| 11877 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11878 | EXPECT_THAT(rv, IsOk()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11879 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11880 | ASSERT_TRUE(response); |
| 11881 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 11882 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11883 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11884 | // Third round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11885 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11886 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11887 | if (rv == ERR_IO_PENDING) |
| 11888 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11889 | EXPECT_THAT(rv, IsOk()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11890 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11891 | ASSERT_TRUE(response); |
| 11892 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 11893 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 11894 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11895 | // Fourth round of authentication, which completes successfully. |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 11896 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11897 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 11898 | if (rv == ERR_IO_PENDING) |
| 11899 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11900 | EXPECT_THAT(rv, IsOk()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 11901 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11902 | ASSERT_TRUE(response); |
| 11903 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 11904 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11905 | |
| 11906 | // Read the body since the fourth round was successful. This will also |
| 11907 | // release the socket back to the pool. |
| 11908 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(50)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11909 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11910 | if (rv == ERR_IO_PENDING) |
| 11911 | rv = callback.WaitForResult(); |
| 11912 | EXPECT_EQ(3, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11913 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11914 | EXPECT_EQ(0, rv); |
| 11915 | // There are still 0 idle sockets, since the trans_compete transaction |
| 11916 | // will be handed it immediately after trans releases it to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 11917 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11918 | |
| 11919 | // The competing request can now finish. Wait for the headers and then |
| 11920 | // read the body. |
| 11921 | rv = callback_compete.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11922 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11923 | rv = trans_compete->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11924 | if (rv == ERR_IO_PENDING) |
| 11925 | rv = callback.WaitForResult(); |
| 11926 | EXPECT_EQ(3, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11927 | rv = trans_compete->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11928 | EXPECT_EQ(0, rv); |
| 11929 | |
| 11930 | // Finally, the socket is released to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 11931 | EXPECT_EQ(1, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11932 | } |
| 11933 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11934 | // This tests the case that a request is issued via http instead of spdy after |
| 11935 | // npn is negotiated. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11936 | TEST_F(HttpNetworkTransactionTest, NpnWithHttpOverSSL) { |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11937 | HttpRequestInfo request; |
| 11938 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11939 | request.url = GURL("https://www.example.org/"); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11940 | request.load_flags = 0; |
| 11941 | |
| 11942 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11943 | MockWrite( |
| 11944 | "GET / HTTP/1.1\r\n" |
| 11945 | "Host: www.example.org\r\n" |
| 11946 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11947 | }; |
| 11948 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11949 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11950 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11951 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11952 | MockRead("\r\n"), |
| 11953 | MockRead("hello world"), |
| 11954 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11955 | }; |
| 11956 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11957 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11958 | ssl.next_proto = kProtoHTTP11; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11959 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11960 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11961 | |
| 11962 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 11963 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11964 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11965 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11966 | TestCompletionCallback callback; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11967 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11968 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 11969 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11970 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11971 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11972 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11973 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11974 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11975 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11976 | |
| 11977 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11978 | ASSERT_TRUE(response); |
| 11979 | ASSERT_TRUE(response->headers); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11980 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11981 | |
| 11982 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11983 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11984 | EXPECT_EQ("hello world", response_data); |
| 11985 | |
| 11986 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 11987 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11988 | } |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11989 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11990 | // Simulate the SSL handshake completing with an NPN negotiation followed by an |
| 11991 | // immediate server closing of the socket. |
| 11992 | // Regression test for https://crbug.com/46369. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11993 | TEST_F(HttpNetworkTransactionTest, SpdyPostNPNServerHangup) { |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11994 | HttpRequestInfo request; |
| 11995 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11996 | request.url = GURL("https://www.example.org/"); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11997 | request.load_flags = 0; |
| 11998 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11999 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12000 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12001 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12002 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12003 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 12004 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12005 | MockWrite spdy_writes[] = {CreateMockWrite(req, 1)}; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12006 | |
| 12007 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12008 | MockRead(SYNCHRONOUS, 0, 0) // Not async - return 0 immediately. |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12009 | }; |
| 12010 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12011 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 12012 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12013 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12014 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12015 | TestCompletionCallback callback; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12016 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12017 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12018 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12019 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12020 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12021 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12022 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12023 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_CLOSED)); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12024 | } |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 12025 | |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 12026 | // A subclass of HttpAuthHandlerMock that records the request URL when |
| 12027 | // it gets it. This is needed since the auth handler may get destroyed |
| 12028 | // before we get a chance to query it. |
| 12029 | class UrlRecordingHttpAuthHandlerMock : public HttpAuthHandlerMock { |
| 12030 | public: |
| 12031 | explicit UrlRecordingHttpAuthHandlerMock(GURL* url) : url_(url) {} |
| 12032 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12033 | ~UrlRecordingHttpAuthHandlerMock() override {} |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 12034 | |
| 12035 | protected: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12036 | int GenerateAuthTokenImpl(const AuthCredentials* credentials, |
| 12037 | const HttpRequestInfo* request, |
| 12038 | const CompletionCallback& callback, |
| 12039 | std::string* auth_token) override { |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 12040 | *url_ = request->url; |
| 12041 | return HttpAuthHandlerMock::GenerateAuthTokenImpl( |
| 12042 | credentials, request, callback, auth_token); |
| 12043 | } |
| 12044 | |
| 12045 | private: |
| 12046 | GURL* url_; |
| 12047 | }; |
| 12048 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12049 | // Test that if we cancel the transaction as the connection is completing, that |
| 12050 | // everything tears down correctly. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12051 | TEST_F(HttpNetworkTransactionTest, SimpleCancel) { |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12052 | // Setup everything about the connection to complete synchronously, so that |
| 12053 | // after calling HttpNetworkTransaction::Start, the only thing we're waiting |
| 12054 | // for is the callback from the HttpStreamRequest. |
| 12055 | // Then cancel the transaction. |
| 12056 | // Verify that we don't crash. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12057 | MockConnect mock_connect(SYNCHRONOUS, OK); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12058 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12059 | MockRead(SYNCHRONOUS, "HTTP/1.0 200 OK\r\n\r\n"), |
| 12060 | MockRead(SYNCHRONOUS, "hello world"), |
| 12061 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12062 | }; |
| 12063 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12064 | HttpRequestInfo request; |
| 12065 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12066 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12067 | request.load_flags = 0; |
| 12068 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12069 | session_deps_.host_resolver->set_synchronous_mode(true); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12070 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12071 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12072 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12073 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12074 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 12075 | data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12076 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12077 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12078 | TestCompletionCallback callback; |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12079 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12080 | BoundTestNetLog log; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12081 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12082 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12083 | trans.reset(); // Cancel the transaction here. |
| 12084 | |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 12085 | base::RunLoop().RunUntilIdle(); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 12086 | } |
| 12087 | |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12088 | // Test that if a transaction is cancelled after receiving the headers, the |
| 12089 | // stream is drained properly and added back to the socket pool. The main |
| 12090 | // purpose of this test is to make sure that an HttpStreamParser can be read |
| 12091 | // from after the HttpNetworkTransaction and the objects it owns have been |
| 12092 | // deleted. |
| 12093 | // See http://crbug.com/368418 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12094 | TEST_F(HttpNetworkTransactionTest, CancelAfterHeaders) { |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12095 | MockRead data_reads[] = { |
| 12096 | MockRead(ASYNC, "HTTP/1.1 200 OK\r\n"), |
| 12097 | MockRead(ASYNC, "Content-Length: 2\r\n"), |
| 12098 | MockRead(ASYNC, "Connection: Keep-Alive\r\n\r\n"), |
| 12099 | MockRead(ASYNC, "1"), |
| 12100 | // 2 async reads are necessary to trigger a ReadResponseBody call after the |
| 12101 | // HttpNetworkTransaction has been deleted. |
| 12102 | MockRead(ASYNC, "2"), |
| 12103 | MockRead(SYNCHRONOUS, ERR_IO_PENDING), // Should never read this. |
| 12104 | }; |
| 12105 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 12106 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12107 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12108 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12109 | |
| 12110 | { |
| 12111 | HttpRequestInfo request; |
| 12112 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12113 | request.url = GURL("http://www.example.org/"); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12114 | request.load_flags = 0; |
| 12115 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12116 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12117 | TestCompletionCallback callback; |
| 12118 | |
| 12119 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12120 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12121 | callback.WaitForResult(); |
| 12122 | |
| 12123 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12124 | ASSERT_TRUE(response); |
| 12125 | EXPECT_TRUE(response->headers); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12126 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12127 | |
| 12128 | // The transaction and HttpRequestInfo are deleted. |
| 12129 | } |
| 12130 | |
| 12131 | // Let the HttpResponseBodyDrainer drain the socket. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 12132 | base::RunLoop().RunUntilIdle(); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12133 | |
| 12134 | // Socket should now be idle, waiting to be reused. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12135 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12136 | } |
| 12137 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12138 | // Test a basic GET request through a proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12139 | TEST_F(HttpNetworkTransactionTest, ProxyGet) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12140 | session_deps_.proxy_service = |
| 12141 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12142 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12143 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12144 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12145 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12146 | HttpRequestInfo request; |
| 12147 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12148 | request.url = GURL("http://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12149 | |
| 12150 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12151 | MockWrite( |
| 12152 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 12153 | "Host: www.example.org\r\n" |
| 12154 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12155 | }; |
| 12156 | |
| 12157 | MockRead data_reads1[] = { |
| 12158 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12159 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 12160 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12161 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12162 | }; |
| 12163 | |
| 12164 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 12165 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12166 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12167 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12168 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12169 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12170 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12171 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 12172 | BeforeHeadersSentHandler headers_handler; |
| 12173 | trans->SetBeforeHeadersSentCallback( |
| 12174 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 12175 | base::Unretained(&headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 12176 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12177 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12178 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12179 | |
| 12180 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12181 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12182 | |
| 12183 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12184 | ASSERT_TRUE(response); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12185 | |
| 12186 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 12187 | EXPECT_EQ(200, response->headers->response_code()); |
| 12188 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 12189 | EXPECT_TRUE(response->was_fetched_via_proxy); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 12190 | EXPECT_TRUE( |
| 12191 | response->proxy_server.Equals(HostPortPair::FromString("myproxy:70"))); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 12192 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 12193 | EXPECT_TRUE(headers_handler.observed_before_headers_sent_with_proxy()); |
| 12194 | EXPECT_EQ("myproxy:70", headers_handler.observed_proxy_server_uri()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12195 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 12196 | |
| 12197 | LoadTimingInfo load_timing_info; |
| 12198 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 12199 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 12200 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12201 | } |
| 12202 | |
| 12203 | // Test a basic HTTPS GET request through a proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12204 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGet) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12205 | session_deps_.proxy_service = |
| 12206 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12207 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12208 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12209 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12210 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12211 | HttpRequestInfo request; |
| 12212 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12213 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12214 | |
| 12215 | // Since we have proxy, should try to establish tunnel. |
| 12216 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12217 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 12218 | "Host: www.example.org:443\r\n" |
| 12219 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12220 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12221 | MockWrite("GET / HTTP/1.1\r\n" |
| 12222 | "Host: www.example.org\r\n" |
| 12223 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12224 | }; |
| 12225 | |
| 12226 | MockRead data_reads1[] = { |
| 12227 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 12228 | |
| 12229 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12230 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 12231 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12232 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12233 | }; |
| 12234 | |
| 12235 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 12236 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12237 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12238 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12239 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12240 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12241 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12242 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12243 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12244 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 12245 | BeforeHeadersSentHandler headers_handler; |
| 12246 | trans->SetBeforeHeadersSentCallback( |
| 12247 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 12248 | base::Unretained(&headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 12249 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12250 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12251 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12252 | |
| 12253 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12254 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 12255 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 12256 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12257 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 12258 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12259 | NetLog::PHASE_NONE); |
| 12260 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 12261 | entries, pos, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12262 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 12263 | NetLog::PHASE_NONE); |
| 12264 | |
| 12265 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12266 | ASSERT_TRUE(response); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12267 | |
| 12268 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 12269 | EXPECT_EQ(200, response->headers->response_code()); |
| 12270 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 12271 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 12272 | EXPECT_TRUE(response->was_fetched_via_proxy); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 12273 | EXPECT_TRUE( |
| 12274 | response->proxy_server.Equals(HostPortPair::FromString("myproxy:70"))); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 12275 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 12276 | EXPECT_TRUE(headers_handler.observed_before_headers_sent_with_proxy()); |
| 12277 | EXPECT_EQ("myproxy:70", headers_handler.observed_proxy_server_uri()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 12278 | |
| 12279 | LoadTimingInfo load_timing_info; |
| 12280 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 12281 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 12282 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12283 | } |
| 12284 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12285 | // Test a basic HTTPS GET request through a proxy, connecting to an IPv6 |
| 12286 | // literal host. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12287 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGetIPv6) { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12288 | session_deps_.proxy_service = |
| 12289 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 12290 | BoundTestNetLog log; |
| 12291 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12292 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12293 | |
| 12294 | HttpRequestInfo request; |
| 12295 | request.method = "GET"; |
| 12296 | request.url = GURL("https://[::1]:443/"); |
| 12297 | |
| 12298 | // Since we have proxy, should try to establish tunnel. |
| 12299 | MockWrite data_writes1[] = { |
| 12300 | MockWrite("CONNECT [::1]:443 HTTP/1.1\r\n" |
| 12301 | "Host: [::1]:443\r\n" |
| 12302 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 12303 | |
| 12304 | MockWrite("GET / HTTP/1.1\r\n" |
| 12305 | "Host: [::1]\r\n" |
| 12306 | "Connection: keep-alive\r\n\r\n"), |
| 12307 | }; |
| 12308 | |
| 12309 | MockRead data_reads1[] = { |
| 12310 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 12311 | |
| 12312 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12313 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 12314 | MockRead("Content-Length: 100\r\n\r\n"), |
| 12315 | MockRead(SYNCHRONOUS, OK), |
| 12316 | }; |
| 12317 | |
| 12318 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 12319 | data_writes1, arraysize(data_writes1)); |
| 12320 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 12321 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 12322 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12323 | |
| 12324 | TestCompletionCallback callback1; |
| 12325 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12326 | std::unique_ptr<HttpTransaction> trans( |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12327 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 12328 | |
| 12329 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12330 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12331 | |
| 12332 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12333 | EXPECT_THAT(rv, IsOk()); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12334 | TestNetLogEntry::List entries; |
| 12335 | log.GetEntries(&entries); |
| 12336 | size_t pos = ExpectLogContainsSomewhere( |
| 12337 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 12338 | NetLog::PHASE_NONE); |
| 12339 | ExpectLogContainsSomewhere( |
| 12340 | entries, pos, NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 12341 | NetLog::PHASE_NONE); |
| 12342 | |
| 12343 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12344 | ASSERT_TRUE(response); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12345 | |
| 12346 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 12347 | EXPECT_EQ(200, response->headers->response_code()); |
| 12348 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 12349 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 12350 | EXPECT_TRUE(response->was_fetched_via_proxy); |
| 12351 | EXPECT_TRUE( |
| 12352 | response->proxy_server.Equals(HostPortPair::FromString("myproxy:70"))); |
| 12353 | |
| 12354 | LoadTimingInfo load_timing_info; |
| 12355 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 12356 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 12357 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 12358 | } |
| 12359 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12360 | // Test a basic HTTPS GET request through a proxy, but the server hangs up |
| 12361 | // while establishing the tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12362 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGetHangup) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12363 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12364 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12365 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12366 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12367 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12368 | HttpRequestInfo request; |
| 12369 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12370 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12371 | |
| 12372 | // Since we have proxy, should try to establish tunnel. |
| 12373 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12374 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 12375 | "Host: www.example.org:443\r\n" |
| 12376 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12377 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12378 | MockWrite("GET / HTTP/1.1\r\n" |
| 12379 | "Host: www.example.org\r\n" |
| 12380 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12381 | }; |
| 12382 | |
| 12383 | MockRead data_reads1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12384 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12385 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12386 | MockRead(ASYNC, 0, 0), // EOF |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12387 | }; |
| 12388 | |
| 12389 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 12390 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12391 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12392 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12393 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12394 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12395 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12396 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12397 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12398 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 12399 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12400 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12401 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12402 | |
| 12403 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12404 | EXPECT_THAT(rv, IsError(ERR_EMPTY_RESPONSE)); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 12405 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 12406 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12407 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 12408 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12409 | NetLog::PHASE_NONE); |
| 12410 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 12411 | entries, pos, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12412 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 12413 | NetLog::PHASE_NONE); |
| 12414 | } |
| 12415 | |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12416 | // Test for crbug.com/55424. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12417 | TEST_F(HttpNetworkTransactionTest, PreconnectWithExistingSpdySession) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12418 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 12419 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12420 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12421 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 12422 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12423 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12424 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12425 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12426 | }; |
| 12427 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12428 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 12429 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12430 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12431 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12432 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12433 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12434 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12435 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12436 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12437 | |
| 12438 | // Set up an initial SpdySession in the pool to reuse. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12439 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 12440 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 12441 | PRIVACY_MODE_DISABLED); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 12442 | base::WeakPtr<SpdySession> spdy_session = |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12443 | CreateInsecureSpdySession(session.get(), key, BoundNetLog()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12444 | |
| 12445 | HttpRequestInfo request; |
| 12446 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12447 | request.url = GURL("https://www.example.org/"); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12448 | request.load_flags = 0; |
| 12449 | |
| 12450 | // This is the important line that marks this as a preconnect. |
| 12451 | request.motivation = HttpRequestInfo::PRECONNECT_MOTIVATED; |
| 12452 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12453 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12454 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12455 | |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 12456 | TestCompletionCallback callback; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12457 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12458 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12459 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12460 | } |
| 12461 | |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 12462 | // Given a net error, cause that error to be returned from the first Write() |
| 12463 | // call and verify that the HttpTransaction fails with that error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12464 | void HttpNetworkTransactionTest::CheckErrorIsPassedBack( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12465 | int error, IoMode mode) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12466 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12467 | request_info.url = GURL("https://www.example.com/"); |
| 12468 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12469 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12470 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12471 | SSLSocketDataProvider ssl_data(mode, OK); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12472 | MockWrite data_writes[] = { |
| 12473 | MockWrite(mode, error), |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 12474 | }; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12475 | StaticSocketDataProvider data(NULL, 0, data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12476 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12477 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 12478 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12479 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12480 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12481 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 12482 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12483 | TestCompletionCallback callback; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12484 | int rv = trans->Start(&request_info, callback.callback(), BoundNetLog()); |
| 12485 | if (rv == ERR_IO_PENDING) |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 12486 | rv = callback.WaitForResult(); |
| 12487 | ASSERT_EQ(error, rv); |
| 12488 | } |
| 12489 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12490 | TEST_F(HttpNetworkTransactionTest, SSLWriteCertError) { |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 12491 | // Just check a grab bag of cert errors. |
| 12492 | static const int kErrors[] = { |
| 12493 | ERR_CERT_COMMON_NAME_INVALID, |
| 12494 | ERR_CERT_AUTHORITY_INVALID, |
| 12495 | ERR_CERT_DATE_INVALID, |
| 12496 | }; |
| 12497 | for (size_t i = 0; i < arraysize(kErrors); i++) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12498 | CheckErrorIsPassedBack(kErrors[i], ASYNC); |
| 12499 | CheckErrorIsPassedBack(kErrors[i], SYNCHRONOUS); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 12500 | } |
| 12501 | } |
| 12502 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12503 | // Ensure that a client certificate is removed from the SSL client auth |
| 12504 | // cache when: |
| 12505 | // 1) No proxy is involved. |
| 12506 | // 2) TLS False Start is disabled. |
| 12507 | // 3) The initial TLS handshake requests a client certificate. |
| 12508 | // 4) The client supplies an invalid/unacceptable certificate. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12509 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_NoFalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12510 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12511 | request_info.url = GURL("https://www.example.com/"); |
| 12512 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12513 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12514 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12515 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12516 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12517 | |
| 12518 | // [ssl_]data1 contains the data for the first SSL handshake. When a |
| 12519 | // CertificateRequest is received for the first time, the handshake will |
| 12520 | // be aborted to allow the caller to provide a certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12521 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12522 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12523 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12524 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12525 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12526 | |
| 12527 | // [ssl_]data2 contains the data for the second SSL handshake. When TLS |
| 12528 | // False Start is not being used, the result of the SSL handshake will be |
| 12529 | // returned as part of the SSLClientSocket::Connect() call. This test |
| 12530 | // matches the result of a server sending a handshake_failure alert, |
| 12531 | // rather than a Finished message, because it requires a client |
| 12532 | // certificate and none was supplied. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12533 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12534 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12535 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12536 | StaticSocketDataProvider data2(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12537 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12538 | |
| 12539 | // [ssl_]data3 contains the data for the third SSL handshake. When a |
| 12540 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 12541 | // HttpNetworkTransaction will attempt to fallback to TLSv1.1 if the previous |
| 12542 | // connection was attempted with TLSv1.2. This is transparent to the caller |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12543 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 12544 | // requiring a client certificate, this fallback handshake should also |
| 12545 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12546 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12547 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12548 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12549 | StaticSocketDataProvider data3(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12550 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12551 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12552 | // [ssl_]data4 contains the data for the fourth SSL handshake. When a |
| 12553 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 12554 | // HttpNetworkTransaction will attempt to fallback to TLSv1 if the previous |
| 12555 | // connection was attempted with TLSv1.1. This is transparent to the caller |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12556 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 12557 | // requiring a client certificate, this fallback handshake should also |
| 12558 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12559 | SSLSocketDataProvider ssl_data4(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12560 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12561 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12562 | StaticSocketDataProvider data4(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12563 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12564 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12565 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12566 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12567 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12568 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12569 | // Begin the SSL handshake with the peer. This consumes ssl_data1. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12570 | TestCompletionCallback callback; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12571 | int rv = trans->Start(&request_info, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12572 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12573 | |
| 12574 | // Complete the SSL handshake, which should abort due to requiring a |
| 12575 | // client certificate. |
| 12576 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12577 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12578 | |
| 12579 | // Indicate that no certificate should be supplied. From the perspective |
| 12580 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 12581 | // certificate, so this is the same as supply a |
| 12582 | // legitimate-but-unacceptable certificate. |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12583 | rv = trans->RestartWithCertificate(NULL, NULL, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12584 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12585 | |
| 12586 | // Ensure the certificate was added to the client auth cache before |
| 12587 | // allowing the connection to continue restarting. |
| 12588 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12589 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12590 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12591 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12592 | ASSERT_FALSE(client_cert); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12593 | |
| 12594 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12595 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 12596 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12597 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12598 | ASSERT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12599 | |
| 12600 | // Ensure that the client certificate is removed from the cache on a |
| 12601 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12602 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12603 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12604 | } |
| 12605 | |
| 12606 | // Ensure that a client certificate is removed from the SSL client auth |
| 12607 | // cache when: |
| 12608 | // 1) No proxy is involved. |
| 12609 | // 2) TLS False Start is enabled. |
| 12610 | // 3) The initial TLS handshake requests a client certificate. |
| 12611 | // 4) The client supplies an invalid/unacceptable certificate. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12612 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_FalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12613 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12614 | request_info.url = GURL("https://www.example.com/"); |
| 12615 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12616 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12617 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12618 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12619 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12620 | |
| 12621 | // When TLS False Start is used, SSLClientSocket::Connect() calls will |
| 12622 | // return successfully after reading up to the peer's Certificate message. |
| 12623 | // This is to allow the caller to call SSLClientSocket::Write(), which can |
| 12624 | // enqueue application data to be sent in the same packet as the |
| 12625 | // ChangeCipherSpec and Finished messages. |
| 12626 | // The actual handshake will be finished when SSLClientSocket::Read() is |
| 12627 | // called, which expects to process the peer's ChangeCipherSpec and |
| 12628 | // Finished messages. If there was an error negotiating with the peer, |
| 12629 | // such as due to the peer requiring a client certificate when none was |
| 12630 | // supplied, the alert sent by the peer won't be processed until Read() is |
| 12631 | // called. |
| 12632 | |
| 12633 | // Like the non-False Start case, when a client certificate is requested by |
| 12634 | // the peer, the handshake is aborted during the Connect() call. |
| 12635 | // [ssl_]data1 represents the initial SSL handshake with the peer. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12636 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12637 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12638 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12639 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12640 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12641 | |
| 12642 | // When a client certificate is supplied, Connect() will not be aborted |
| 12643 | // when the peer requests the certificate. Instead, the handshake will |
| 12644 | // artificially succeed, allowing the caller to write the HTTP request to |
| 12645 | // the socket. The handshake messages are not processed until Read() is |
| 12646 | // called, which then detects that the handshake was aborted, due to the |
| 12647 | // peer sending a handshake_failure because it requires a client |
| 12648 | // certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12649 | SSLSocketDataProvider ssl_data2(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12650 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12651 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12652 | MockRead data2_reads[] = { |
| 12653 | MockRead(ASYNC /* async */, ERR_SSL_PROTOCOL_ERROR), |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12654 | }; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12655 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12656 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12657 | |
| 12658 | // As described in ClientAuthCertCache_Direct_NoFalseStart, [ssl_]data3 is |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12659 | // the data for the SSL handshake once the TLSv1.1 connection falls back to |
| 12660 | // TLSv1. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12661 | SSLSocketDataProvider ssl_data3(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12662 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12663 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12664 | StaticSocketDataProvider data3(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12665 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12666 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12667 | // [ssl_]data4 is the data for the SSL handshake once the TLSv1 connection |
| 12668 | // falls back to SSLv3. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12669 | SSLSocketDataProvider ssl_data4(ASYNC, OK); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12670 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12671 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12672 | StaticSocketDataProvider data4(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12673 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12674 | |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 12675 | // Need one more if TLSv1.2 is enabled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12676 | SSLSocketDataProvider ssl_data5(ASYNC, OK); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 12677 | ssl_data5.cert_request_info = cert_request.get(); |
| 12678 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data5); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12679 | StaticSocketDataProvider data5(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 12680 | session_deps_.socket_factory->AddSocketDataProvider(&data5); |
| 12681 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12682 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12683 | std::unique_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12684 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12685 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12686 | // Begin the initial SSL handshake. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12687 | TestCompletionCallback callback; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12688 | int rv = trans->Start(&request_info, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12689 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12690 | |
| 12691 | // Complete the SSL handshake, which should abort due to requiring a |
| 12692 | // client certificate. |
| 12693 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12694 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12695 | |
| 12696 | // Indicate that no certificate should be supplied. From the perspective |
| 12697 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 12698 | // certificate, so this is the same as supply a |
| 12699 | // legitimate-but-unacceptable certificate. |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12700 | rv = trans->RestartWithCertificate(NULL, NULL, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12701 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12702 | |
| 12703 | // Ensure the certificate was added to the client auth cache before |
| 12704 | // allowing the connection to continue restarting. |
| 12705 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12706 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12707 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12708 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12709 | ASSERT_FALSE(client_cert); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12710 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12711 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12712 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 12713 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12714 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12715 | ASSERT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12716 | |
| 12717 | // Ensure that the client certificate is removed from the cache on a |
| 12718 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12719 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12720 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12721 | } |
| 12722 | |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12723 | // Ensure that a client certificate is removed from the SSL client auth |
| 12724 | // cache when: |
| 12725 | // 1) An HTTPS proxy is involved. |
| 12726 | // 3) The HTTPS proxy requests a client certificate. |
| 12727 | // 4) The client supplies an invalid/unacceptable certificate for the |
| 12728 | // proxy. |
| 12729 | // The test is repeated twice, first for connecting to an HTTPS endpoint, |
| 12730 | // then for connecting to an HTTP endpoint. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12731 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Proxy_Fail) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12732 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12733 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12734 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12735 | |
| 12736 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12737 | cert_request->host_and_port = HostPortPair("proxy", 70); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12738 | |
| 12739 | // See ClientAuthCertCache_Direct_NoFalseStart for the explanation of |
| 12740 | // [ssl_]data[1-3]. Rather than represending the endpoint |
| 12741 | // (www.example.com:443), they represent failures with the HTTPS proxy |
| 12742 | // (proxy:70). |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12743 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12744 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12745 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12746 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12747 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12748 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12749 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12750 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12751 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12752 | StaticSocketDataProvider data2(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12753 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12754 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12755 | // TODO(wtc): find out why this unit test doesn't need [ssl_]data3. |
| 12756 | #if 0 |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12757 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12758 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12759 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12760 | StaticSocketDataProvider data3(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12761 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12762 | #endif |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12763 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12764 | HttpRequestInfo requests[2]; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12765 | requests[0].url = GURL("https://www.example.com/"); |
| 12766 | requests[0].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12767 | requests[0].load_flags = LOAD_NORMAL; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12768 | |
| 12769 | requests[1].url = GURL("http://www.example.com/"); |
| 12770 | requests[1].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12771 | requests[1].load_flags = LOAD_NORMAL; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12772 | |
| 12773 | for (size_t i = 0; i < arraysize(requests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12774 | session_deps_.socket_factory->ResetNextMockIndexes(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12775 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12776 | std::unique_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12777 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12778 | |
| 12779 | // Begin the SSL handshake with the proxy. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12780 | TestCompletionCallback callback; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12781 | int rv = trans->Start(&requests[i], callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12782 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12783 | |
| 12784 | // Complete the SSL handshake, which should abort due to requiring a |
| 12785 | // client certificate. |
| 12786 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12787 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12788 | |
| 12789 | // Indicate that no certificate should be supplied. From the perspective |
| 12790 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 12791 | // certificate, so this is the same as supply a |
| 12792 | // legitimate-but-unacceptable certificate. |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12793 | rv = trans->RestartWithCertificate(NULL, NULL, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12794 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12795 | |
| 12796 | // Ensure the certificate was added to the client auth cache before |
| 12797 | // allowing the connection to continue restarting. |
| 12798 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12799 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12800 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12801 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12802 | ASSERT_FALSE(client_cert); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12803 | // Ensure the certificate was NOT cached for the endpoint. This only |
| 12804 | // applies to HTTPS requests, but is fine to check for HTTP requests. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12805 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12806 | HostPortPair("www.example.com", 443), &client_cert, |
| 12807 | &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12808 | |
| 12809 | // Restart the handshake. This will consume ssl_data2, which fails, and |
| 12810 | // then consume ssl_data3, which should also fail. The result code is |
| 12811 | // checked against what ssl_data3 should return. |
| 12812 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12813 | ASSERT_THAT(rv, IsError(ERR_PROXY_CONNECTION_FAILED)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12814 | |
| 12815 | // Now that the new handshake has failed, ensure that the client |
| 12816 | // certificate was removed from the client auth cache. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12817 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12818 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12819 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12820 | HostPortPair("www.example.com", 443), &client_cert, |
| 12821 | &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12822 | } |
| 12823 | } |
| 12824 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12825 | TEST_F(HttpNetworkTransactionTest, UseIPConnectionPooling) { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12826 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12827 | session_deps_.host_resolver.reset(new MockCachingHostResolver()); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12828 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | b9ec688 | 2011-07-01 07:40:26 | [diff] [blame] | 12829 | SpdySessionPoolPeer pool_peer(session->spdy_session_pool()); |
| 12830 | pool_peer.DisableDomainAuthenticationVerification(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12831 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12832 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12833 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12834 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12835 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12836 | SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 12837 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 12838 | spdy_util_.UpdateWithStreamDestruction(1); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12839 | SpdySerializedFrame host2_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 12840 | spdy_util_.ConstructSpdyGet("https://www.gmail.com", 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12841 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12842 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12843 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 12844 | SpdySerializedFrame host1_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12845 | SpdySerializedFrame host1_resp_body( |
| 12846 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 12847 | SpdySerializedFrame host2_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12848 | SpdySerializedFrame host2_resp_body( |
| 12849 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12850 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12851 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 12852 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12853 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12854 | }; |
| 12855 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 12856 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12857 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12858 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 12859 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12860 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12861 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 12862 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12863 | HttpRequestInfo request1; |
| 12864 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12865 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12866 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12867 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12868 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12869 | int rv = trans1.Start(&request1, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12870 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12871 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12872 | |
| 12873 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12874 | ASSERT_TRUE(response); |
| 12875 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12876 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12877 | |
| 12878 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12879 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12880 | EXPECT_EQ("hello!", response_data); |
| 12881 | |
| 12882 | // Preload www.gmail.com into HostCache. |
| 12883 | HostPortPair host_port("www.gmail.com", 443); |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 12884 | HostResolver::RequestInfo resolve_info(host_port); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12885 | AddressList ignored; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 12886 | std::unique_ptr<HostResolver::Request> request; |
| 12887 | rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 12888 | &ignored, callback.callback(), |
| 12889 | &request, BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12890 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 12891 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12892 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12893 | |
| 12894 | HttpRequestInfo request2; |
| 12895 | request2.method = "GET"; |
| 12896 | request2.url = GURL("https://www.gmail.com/"); |
| 12897 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12898 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12899 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12900 | rv = trans2.Start(&request2, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12901 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12902 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12903 | |
| 12904 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12905 | ASSERT_TRUE(response); |
| 12906 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12907 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12908 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 12909 | EXPECT_TRUE(response->was_npn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12910 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12911 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12912 | } |
| 12913 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12914 | TEST_F(HttpNetworkTransactionTest, UseIPConnectionPoolingAfterResolution) { |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12915 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12916 | session_deps_.host_resolver.reset(new MockCachingHostResolver()); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12917 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12918 | SpdySessionPoolPeer pool_peer(session->spdy_session_pool()); |
| 12919 | pool_peer.DisableDomainAuthenticationVerification(); |
| 12920 | |
| 12921 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12922 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12923 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12924 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12925 | SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 12926 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 12927 | spdy_util_.UpdateWithStreamDestruction(1); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12928 | SpdySerializedFrame host2_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 12929 | spdy_util_.ConstructSpdyGet("https://www.gmail.com", 3, LOWEST)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12930 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12931 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12932 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 12933 | SpdySerializedFrame host1_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12934 | SpdySerializedFrame host1_resp_body( |
| 12935 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 12936 | SpdySerializedFrame host2_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12937 | SpdySerializedFrame host2_resp_body( |
| 12938 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12939 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12940 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 12941 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12942 | MockRead(ASYNC, 0, 6), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12943 | }; |
| 12944 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 12945 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12946 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12947 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 12948 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12949 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12950 | |
| 12951 | TestCompletionCallback callback; |
| 12952 | HttpRequestInfo request1; |
| 12953 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12954 | request1.url = GURL("https://www.example.org/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12955 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12956 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12957 | |
| 12958 | int rv = trans1.Start(&request1, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12959 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12960 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12961 | |
| 12962 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12963 | ASSERT_TRUE(response); |
| 12964 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12965 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12966 | |
| 12967 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12968 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12969 | EXPECT_EQ("hello!", response_data); |
| 12970 | |
| 12971 | HttpRequestInfo request2; |
| 12972 | request2.method = "GET"; |
| 12973 | request2.url = GURL("https://www.gmail.com/"); |
| 12974 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12975 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12976 | |
| 12977 | rv = trans2.Start(&request2, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12978 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12979 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12980 | |
| 12981 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12982 | ASSERT_TRUE(response); |
| 12983 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12984 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12985 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 12986 | EXPECT_TRUE(response->was_npn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12987 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12988 | EXPECT_EQ("hello!", response_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12989 | } |
| 12990 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12991 | class OneTimeCachingHostResolver : public HostResolver { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12992 | public: |
| 12993 | explicit OneTimeCachingHostResolver(const HostPortPair& host_port) |
| 12994 | : host_port_(host_port) {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12995 | ~OneTimeCachingHostResolver() override {} |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12996 | |
| 12997 | RuleBasedHostResolverProc* rules() { return host_resolver_.rules(); } |
| 12998 | |
| 12999 | // HostResolver methods: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13000 | int Resolve(const RequestInfo& info, |
| 13001 | RequestPriority priority, |
| 13002 | AddressList* addresses, |
| 13003 | const CompletionCallback& callback, |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 13004 | std::unique_ptr<Request>* out_req, |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13005 | const BoundNetLog& net_log) override { |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 13006 | return host_resolver_.Resolve( |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 13007 | info, priority, addresses, callback, out_req, net_log); |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 13008 | } |
| 13009 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13010 | int ResolveFromCache(const RequestInfo& info, |
| 13011 | AddressList* addresses, |
| 13012 | const BoundNetLog& net_log) override { |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 13013 | int rv = host_resolver_.ResolveFromCache(info, addresses, net_log); |
| 13014 | if (rv == OK && info.host_port_pair().Equals(host_port_)) |
[email protected] | 98e1cd01 | 2011-11-08 15:33:09 | [diff] [blame] | 13015 | host_resolver_.GetHostCache()->clear(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13016 | return rv; |
| 13017 | } |
| 13018 | |
[email protected] | 46da33be | 2011-07-19 21:58:04 | [diff] [blame] | 13019 | MockCachingHostResolver* GetMockHostResolver() { |
| 13020 | return &host_resolver_; |
| 13021 | } |
| 13022 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13023 | private: |
| 13024 | MockCachingHostResolver host_resolver_; |
| 13025 | const HostPortPair host_port_; |
| 13026 | }; |
| 13027 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13028 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 5c64213 | 2015-06-02 16:05:13 | [diff] [blame] | 13029 | UseIPConnectionPoolingWithHostCacheExpiration) { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13030 | // Set up a special HttpNetworkSession with a OneTimeCachingHostResolver. |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13031 | OneTimeCachingHostResolver host_resolver(HostPortPair("www.gmail.com", 443)); |
[email protected] | c6bf815 | 2012-12-02 07:43:34 | [diff] [blame] | 13032 | HttpNetworkSession::Params params = |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13033 | SpdySessionDependencies::CreateSessionParams(&session_deps_); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13034 | params.host_resolver = &host_resolver; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13035 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | b9ec688 | 2011-07-01 07:40:26 | [diff] [blame] | 13036 | SpdySessionPoolPeer pool_peer(session->spdy_session_pool()); |
| 13037 | pool_peer.DisableDomainAuthenticationVerification(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13038 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13039 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13040 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13041 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13042 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13043 | SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13044 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13045 | spdy_util_.UpdateWithStreamDestruction(1); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13046 | SpdySerializedFrame host2_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13047 | spdy_util_.ConstructSpdyGet("https://www.gmail.com", 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13048 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13049 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13050 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13051 | SpdySerializedFrame host1_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13052 | SpdySerializedFrame host1_resp_body( |
| 13053 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13054 | SpdySerializedFrame host2_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13055 | SpdySerializedFrame host2_resp_body( |
| 13056 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13057 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13058 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 13059 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13060 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13061 | }; |
| 13062 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 13063 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13064 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13065 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 13066 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13067 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13068 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 13069 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13070 | HttpRequestInfo request1; |
| 13071 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13072 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13073 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13074 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13075 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13076 | int rv = trans1.Start(&request1, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13077 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13078 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13079 | |
| 13080 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13081 | ASSERT_TRUE(response); |
| 13082 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13083 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13084 | |
| 13085 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13086 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13087 | EXPECT_EQ("hello!", response_data); |
| 13088 | |
| 13089 | // Preload cache entries into HostCache. |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 13090 | HostResolver::RequestInfo resolve_info(HostPortPair("www.gmail.com", 443)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13091 | AddressList ignored; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 13092 | std::unique_ptr<HostResolver::Request> request; |
| 13093 | rv = host_resolver.Resolve(resolve_info, DEFAULT_PRIORITY, &ignored, |
| 13094 | callback.callback(), &request, BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13095 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 13096 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13097 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13098 | |
| 13099 | HttpRequestInfo request2; |
| 13100 | request2.method = "GET"; |
| 13101 | request2.url = GURL("https://www.gmail.com/"); |
| 13102 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13103 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13104 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13105 | rv = trans2.Start(&request2, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13106 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13107 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13108 | |
| 13109 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13110 | ASSERT_TRUE(response); |
| 13111 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13112 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13113 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 13114 | EXPECT_TRUE(response->was_npn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13115 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13116 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13117 | } |
| 13118 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13119 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttp) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13120 | const std::string https_url = "https://www.example.org:8080/"; |
| 13121 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13122 | |
| 13123 | // SPDY GET for HTTPS URL |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13124 | SpdySerializedFrame req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13125 | spdy_util_.ConstructSpdyGet(https_url.c_str(), 1, LOWEST)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13126 | |
| 13127 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13128 | CreateMockWrite(req1, 0), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13129 | }; |
| 13130 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13131 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13132 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 13133 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 13134 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3)}; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13135 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13136 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 13137 | arraysize(writes1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13138 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 13139 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13140 | |
| 13141 | // HTTP GET for the HTTP URL |
| 13142 | MockWrite writes2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13143 | MockWrite(ASYNC, 0, |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 13144 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13145 | "Host: www.example.org:8080\r\n" |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 13146 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13147 | }; |
| 13148 | |
| 13149 | MockRead reads2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13150 | MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 13151 | MockRead(ASYNC, 2, "hello"), |
| 13152 | MockRead(ASYNC, OK, 3), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13153 | }; |
| 13154 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13155 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 13156 | arraysize(writes2)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13157 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13158 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13159 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13160 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13161 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 13162 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13163 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13164 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13165 | |
| 13166 | // Start the first transaction to set up the SpdySession |
| 13167 | HttpRequestInfo request1; |
| 13168 | request1.method = "GET"; |
| 13169 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13170 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13171 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13172 | TestCompletionCallback callback1; |
| 13173 | EXPECT_EQ(ERR_IO_PENDING, |
| 13174 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 13175 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13176 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13177 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13178 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 13179 | |
| 13180 | // Now, start the HTTP request |
| 13181 | HttpRequestInfo request2; |
| 13182 | request2.method = "GET"; |
| 13183 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13184 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13185 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13186 | TestCompletionCallback callback2; |
| 13187 | EXPECT_EQ(ERR_IO_PENDING, |
| 13188 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 13189 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13190 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13191 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13192 | EXPECT_FALSE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 13193 | } |
| 13194 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13195 | // Alternative service requires HTTP/2 (or SPDY), but HTTP/1.1 is negotiated |
| 13196 | // with the alternative server. That connection should not be used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13197 | TEST_F(HttpNetworkTransactionTest, AlternativeServiceNotOnHttp11) { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13198 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 13199 | HostPortPair alternative("www.example.org", 444); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13200 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13201 | // Negotiate HTTP/1.1 with alternative. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13202 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13203 | ssl.next_proto = kProtoHTTP11; |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13204 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13205 | |
| 13206 | // No data should be read from the alternative, because HTTP/1.1 is |
| 13207 | // negotiated. |
| 13208 | StaticSocketDataProvider data; |
| 13209 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13210 | |
| 13211 | // 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] | 13212 | // negotiated. In order to test this, a failed connection to the server is |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13213 | // mocked. This way the request relies on the alternate Job. |
| 13214 | StaticSocketDataProvider data_refused; |
| 13215 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 13216 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 13217 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 13218 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13219 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 13220 | HttpServerProperties* http_server_properties = |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13221 | session->http_server_properties(); |
| 13222 | AlternativeService alternative_service( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 13223 | AlternateProtocolFromNextProto(kProtoHTTP2), alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 13224 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 13225 | http_server_properties->SetAlternativeService(server, alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 13226 | expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13227 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13228 | std::unique_ptr<HttpTransaction> trans( |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13229 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 13230 | HttpRequestInfo request; |
| 13231 | request.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13232 | request.url = GURL("https://www.example.org:443"); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13233 | request.load_flags = 0; |
| 13234 | TestCompletionCallback callback; |
| 13235 | |
| 13236 | // HTTP/2 (or SPDY) is required for alternative service, if HTTP/1.1 is |
| 13237 | // negotiated, the alternate Job should fail with ERR_NPN_NEGOTIATION_FAILED. |
| 13238 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13239 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_NPN_NEGOTIATION_FAILED)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13240 | } |
| 13241 | |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13242 | // 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] | 13243 | // server, and an alternate one to the alternative server. If the former |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13244 | // succeeds, the request should succeed, even if the latter fails because |
| 13245 | // HTTP/1.1 is negotiated which is insufficient for alternative service. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13246 | TEST_F(HttpNetworkTransactionTest, FailedAlternativeServiceIsNotUserVisible) { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13247 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 13248 | HostPortPair alternative("www.example.org", 444); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13249 | |
| 13250 | // Negotiate HTTP/1.1 with alternative. |
| 13251 | SSLSocketDataProvider alternative_ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13252 | alternative_ssl.next_proto = kProtoHTTP11; |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13253 | session_deps_.socket_factory->AddSSLSocketDataProvider(&alternative_ssl); |
| 13254 | |
| 13255 | // No data should be read from the alternative, because HTTP/1.1 is |
| 13256 | // negotiated. |
| 13257 | StaticSocketDataProvider data; |
| 13258 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13259 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 13260 | // Negotiate HTTP/1.1 with server. |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13261 | SSLSocketDataProvider origin_ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13262 | origin_ssl.next_proto = kProtoHTTP11; |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13263 | session_deps_.socket_factory->AddSSLSocketDataProvider(&origin_ssl); |
| 13264 | |
| 13265 | MockWrite http_writes[] = { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13266 | MockWrite("GET / HTTP/1.1\r\n" |
| 13267 | "Host: www.example.org\r\n" |
| 13268 | "Connection: keep-alive\r\n\r\n"), |
| 13269 | MockWrite("GET /second HTTP/1.1\r\n" |
| 13270 | "Host: www.example.org\r\n" |
| 13271 | "Connection: keep-alive\r\n\r\n"), |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13272 | }; |
| 13273 | |
| 13274 | MockRead http_reads[] = { |
| 13275 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13276 | MockRead("Content-Type: text/html\r\n"), |
| 13277 | MockRead("Content-Length: 6\r\n\r\n"), |
| 13278 | MockRead("foobar"), |
| 13279 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13280 | MockRead("Content-Type: text/html\r\n"), |
| 13281 | MockRead("Content-Length: 7\r\n\r\n"), |
| 13282 | MockRead("another"), |
| 13283 | }; |
| 13284 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 13285 | http_writes, arraysize(http_writes)); |
| 13286 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 13287 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 13288 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13289 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 13290 | HttpServerProperties* http_server_properties = |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13291 | session->http_server_properties(); |
| 13292 | AlternativeService alternative_service( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 13293 | AlternateProtocolFromNextProto(kProtoHTTP2), alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 13294 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 13295 | http_server_properties->SetAlternativeService(server, alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 13296 | expiration); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13297 | |
| 13298 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 13299 | HttpRequestInfo request1; |
| 13300 | request1.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13301 | request1.url = GURL("https://www.example.org:443"); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13302 | request1.load_flags = 0; |
| 13303 | TestCompletionCallback callback1; |
| 13304 | |
| 13305 | int rv = trans1.Start(&request1, callback1.callback(), BoundNetLog()); |
| 13306 | rv = callback1.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13307 | EXPECT_THAT(rv, IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13308 | |
| 13309 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13310 | ASSERT_TRUE(response1); |
| 13311 | ASSERT_TRUE(response1->headers); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13312 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
| 13313 | |
| 13314 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13315 | ASSERT_THAT(ReadTransaction(&trans1, &response_data1), IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13316 | EXPECT_EQ("foobar", response_data1); |
| 13317 | |
| 13318 | // Alternative should be marked as broken, because HTTP/1.1 is not sufficient |
| 13319 | // for alternative service. |
| 13320 | EXPECT_TRUE( |
| 13321 | http_server_properties->IsAlternativeServiceBroken(alternative_service)); |
| 13322 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 13323 | // Since |alternative_service| is broken, a second transaction to server |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13324 | // should not start an alternate Job. It should pool to existing connection |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 13325 | // to server. |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13326 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 13327 | HttpRequestInfo request2; |
| 13328 | request2.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13329 | request2.url = GURL("https://www.example.org:443/second"); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13330 | request2.load_flags = 0; |
| 13331 | TestCompletionCallback callback2; |
| 13332 | |
| 13333 | rv = trans2.Start(&request2, callback2.callback(), BoundNetLog()); |
| 13334 | rv = callback2.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13335 | EXPECT_THAT(rv, IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13336 | |
| 13337 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13338 | ASSERT_TRUE(response2); |
| 13339 | ASSERT_TRUE(response2->headers); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13340 | EXPECT_EQ("HTTP/1.1 200 OK", response2->headers->GetStatusLine()); |
| 13341 | |
| 13342 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13343 | ASSERT_THAT(ReadTransaction(&trans2, &response_data2), IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13344 | EXPECT_EQ("another", response_data2); |
| 13345 | } |
| 13346 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13347 | // Alternative service requires HTTP/2 (or SPDY), but there is already a |
| 13348 | // HTTP/1.1 socket open to the alternative server. That socket should not be |
| 13349 | // used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13350 | TEST_F(HttpNetworkTransactionTest, AlternativeServiceShouldNotPoolToHttp11) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 13351 | url::SchemeHostPort server("https", "origin.example.org", 443); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13352 | HostPortPair alternative("alternative.example.org", 443); |
| 13353 | std::string origin_url = "https://origin.example.org:443"; |
| 13354 | std::string alternative_url = "https://alternative.example.org:443"; |
| 13355 | |
| 13356 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 13357 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13358 | ssl.next_proto = kProtoHTTP11; |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13359 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13360 | |
| 13361 | // HTTP/1.1 data for |request1| and |request2|. |
| 13362 | MockWrite http_writes[] = { |
| 13363 | MockWrite( |
| 13364 | "GET / HTTP/1.1\r\n" |
| 13365 | "Host: alternative.example.org\r\n" |
| 13366 | "Connection: keep-alive\r\n\r\n"), |
| 13367 | MockWrite( |
| 13368 | "GET / HTTP/1.1\r\n" |
| 13369 | "Host: alternative.example.org\r\n" |
| 13370 | "Connection: keep-alive\r\n\r\n"), |
| 13371 | }; |
| 13372 | |
| 13373 | MockRead http_reads[] = { |
| 13374 | MockRead( |
| 13375 | "HTTP/1.1 200 OK\r\n" |
| 13376 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13377 | "Content-Length: 40\r\n\r\n" |
| 13378 | "first HTTP/1.1 response from alternative"), |
| 13379 | MockRead( |
| 13380 | "HTTP/1.1 200 OK\r\n" |
| 13381 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13382 | "Content-Length: 41\r\n\r\n" |
| 13383 | "second HTTP/1.1 response from alternative"), |
| 13384 | }; |
| 13385 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 13386 | http_writes, arraysize(http_writes)); |
| 13387 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 13388 | |
| 13389 | // This test documents that an alternate Job should not pool to an already |
| 13390 | // existing HTTP/1.1 connection. In order to test this, a failed connection |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 13391 | // to the server is mocked. This way |request2| relies on the alternate Job. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13392 | StaticSocketDataProvider data_refused; |
| 13393 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 13394 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 13395 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 13396 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13397 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 13398 | HttpServerProperties* http_server_properties = |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13399 | session->http_server_properties(); |
| 13400 | AlternativeService alternative_service( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 13401 | AlternateProtocolFromNextProto(kProtoHTTP2), alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 13402 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 13403 | http_server_properties->SetAlternativeService(server, alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 13404 | expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13405 | |
| 13406 | // First transaction to alternative to open an HTTP/1.1 socket. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13407 | std::unique_ptr<HttpTransaction> trans1( |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13408 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 13409 | HttpRequestInfo request1; |
| 13410 | request1.method = "GET"; |
| 13411 | request1.url = GURL(alternative_url); |
| 13412 | request1.load_flags = 0; |
| 13413 | TestCompletionCallback callback1; |
| 13414 | |
| 13415 | int rv = trans1->Start(&request1, callback1.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13416 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13417 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 13418 | ASSERT_TRUE(response1); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13419 | ASSERT_TRUE(response1->headers); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13420 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
| 13421 | EXPECT_TRUE(response1->was_npn_negotiated); |
| 13422 | EXPECT_FALSE(response1->was_fetched_via_spdy); |
| 13423 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13424 | ASSERT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13425 | EXPECT_EQ("first HTTP/1.1 response from alternative", response_data1); |
| 13426 | |
| 13427 | // Request for origin.example.org, which has an alternative service. This |
| 13428 | // will start two Jobs: the alternative looks for connections to pool to, |
| 13429 | // 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] | 13430 | // open other connections to alternative server. The Job to server fails, so |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13431 | // this request fails. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13432 | std::unique_ptr<HttpTransaction> trans2( |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13433 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 13434 | HttpRequestInfo request2; |
| 13435 | request2.method = "GET"; |
| 13436 | request2.url = GURL(origin_url); |
| 13437 | request2.load_flags = 0; |
| 13438 | TestCompletionCallback callback2; |
| 13439 | |
| 13440 | rv = trans2->Start(&request2, callback2.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13441 | EXPECT_THAT(callback2.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13442 | |
| 13443 | // Another transaction to alternative. This is to test that the HTTP/1.1 |
| 13444 | // socket is still open and in the pool. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13445 | std::unique_ptr<HttpTransaction> trans3( |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13446 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 13447 | HttpRequestInfo request3; |
| 13448 | request3.method = "GET"; |
| 13449 | request3.url = GURL(alternative_url); |
| 13450 | request3.load_flags = 0; |
| 13451 | TestCompletionCallback callback3; |
| 13452 | |
| 13453 | rv = trans3->Start(&request3, callback3.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13454 | EXPECT_THAT(callback3.GetResult(rv), IsOk()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13455 | const HttpResponseInfo* response3 = trans3->GetResponseInfo(); |
| 13456 | ASSERT_TRUE(response3); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13457 | ASSERT_TRUE(response3->headers); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13458 | EXPECT_EQ("HTTP/1.1 200 OK", response3->headers->GetStatusLine()); |
| 13459 | EXPECT_TRUE(response3->was_npn_negotiated); |
| 13460 | EXPECT_FALSE(response3->was_fetched_via_spdy); |
| 13461 | std::string response_data3; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13462 | ASSERT_THAT(ReadTransaction(trans3.get(), &response_data3), IsOk()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13463 | EXPECT_EQ("second HTTP/1.1 response from alternative", response_data3); |
| 13464 | } |
| 13465 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13466 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttpOverTunnel) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13467 | const std::string https_url = "https://www.example.org:8080/"; |
| 13468 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13469 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13470 | // Separate SPDY util instance for naked and wrapped requests. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13471 | SpdyTestUtil spdy_util_wrapped; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13472 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13473 | // SPDY GET for HTTPS URL (through CONNECT tunnel) |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13474 | const HostPortPair host_port_pair("www.example.org", 8080); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13475 | SpdySerializedFrame connect( |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 13476 | spdy_util_.ConstructSpdyConnect(NULL, 0, 1, LOWEST, host_port_pair)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13477 | SpdySerializedFrame req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13478 | spdy_util_wrapped.ConstructSpdyGet(https_url.c_str(), 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13479 | SpdySerializedFrame wrapped_req1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13480 | spdy_util_.ConstructWrappedSpdyFrame(req1, 1)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 13481 | |
| 13482 | // SPDY GET for HTTP URL (through the proxy, but not the tunnel). |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 13483 | SpdyHeaderBlock req2_block; |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 13484 | req2_block[spdy_util_.GetMethodKey()] = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13485 | req2_block[spdy_util_.GetHostKey()] = "www.example.org:8080"; |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 13486 | req2_block[spdy_util_.GetSchemeKey()] = "http"; |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 13487 | req2_block[spdy_util_.GetPathKey()] = "/"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13488 | SpdySerializedFrame req2( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13489 | spdy_util_.ConstructSpdyHeaders(3, std::move(req2_block), MEDIUM, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13490 | |
| 13491 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13492 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_req1, 2), |
| 13493 | CreateMockWrite(req2, 6), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13494 | }; |
| 13495 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13496 | SpdySerializedFrame conn_resp( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13497 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13498 | SpdySerializedFrame resp1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13499 | spdy_util_wrapped.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13500 | SpdySerializedFrame body1(spdy_util_wrapped.ConstructSpdyDataFrame(1, true)); |
| 13501 | SpdySerializedFrame wrapped_resp1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13502 | spdy_util_wrapped.ConstructWrappedSpdyFrame(resp1, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13503 | SpdySerializedFrame wrapped_body1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13504 | spdy_util_wrapped.ConstructWrappedSpdyFrame(body1, 1)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13505 | SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13506 | SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13507 | MockRead reads1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13508 | CreateMockRead(conn_resp, 1), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13509 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13510 | CreateMockRead(wrapped_resp1, 4), |
| 13511 | CreateMockRead(wrapped_body1, 5), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13512 | MockRead(ASYNC, ERR_IO_PENDING, 7), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13513 | CreateMockRead(resp2, 8), |
| 13514 | CreateMockRead(body2, 9), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13515 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 10), |
| 13516 | }; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13517 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13518 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 13519 | arraysize(writes1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13520 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 13521 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13522 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 13523 | session_deps_.proxy_service = |
| 13524 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 13525 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13526 | session_deps_.net_log = &log; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13527 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13528 | ssl1.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13529 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13530 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13531 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13532 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 13533 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13534 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13535 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13536 | |
| 13537 | // Start the first transaction to set up the SpdySession |
| 13538 | HttpRequestInfo request1; |
| 13539 | request1.method = "GET"; |
| 13540 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13541 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13542 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13543 | TestCompletionCallback callback1; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13544 | int rv = trans1.Start(&request1, callback1.callback(), BoundNetLog()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13545 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13546 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 13547 | data1.RunUntilPaused(); |
| 13548 | base::RunLoop().RunUntilIdle(); |
| 13549 | data1.Resume(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13550 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13551 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 13552 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 13553 | LoadTimingInfo load_timing_info1; |
| 13554 | EXPECT_TRUE(trans1.GetLoadTimingInfo(&load_timing_info1)); |
| 13555 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 13556 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 13557 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13558 | // Now, start the HTTP request. |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13559 | HttpRequestInfo request2; |
| 13560 | request2.method = "GET"; |
| 13561 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13562 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13563 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13564 | TestCompletionCallback callback2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13565 | rv = trans2.Start(&request2, callback2.callback(), BoundNetLog()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13566 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13567 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 13568 | data1.RunUntilPaused(); |
| 13569 | base::RunLoop().RunUntilIdle(); |
| 13570 | data1.Resume(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13571 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13572 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13573 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 13574 | |
| 13575 | LoadTimingInfo load_timing_info2; |
| 13576 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
| 13577 | // The established SPDY sessions is considered reused by the HTTP request. |
| 13578 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 13579 | // HTTP requests over a SPDY session should have a different connection |
| 13580 | // socket_log_id than requests over a tunnel. |
| 13581 | 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] | 13582 | } |
| 13583 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13584 | // Test that in the case where we have a SPDY session to a SPDY proxy |
| 13585 | // that we do not pool other origins that resolve to the same IP when |
| 13586 | // the certificate does not match the new origin. |
| 13587 | // http://crbug.com/134690 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13588 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionIfCertDoesNotMatch) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13589 | const std::string url1 = "http://www.example.org/"; |
| 13590 | const std::string url2 = "https://news.example.org/"; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13591 | const std::string ip_addr = "1.2.3.4"; |
| 13592 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13593 | // Second SpdyTestUtil instance for the second socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13594 | SpdyTestUtil spdy_util_secure; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13595 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13596 | // SPDY GET for HTTP URL (through SPDY proxy) |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 13597 | SpdyHeaderBlock headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13598 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13599 | SpdySerializedFrame req1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13600 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13601 | |
| 13602 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13603 | CreateMockWrite(req1, 0), |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13604 | }; |
| 13605 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13606 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13607 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13608 | MockRead reads1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13609 | MockRead(ASYNC, ERR_IO_PENDING, 1), CreateMockRead(resp1, 2), |
| 13610 | CreateMockRead(body1, 3), MockRead(ASYNC, OK, 4), // EOF |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13611 | }; |
| 13612 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13613 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 13614 | arraysize(writes1)); |
martijn | fe9636e | 2016-02-06 14:33:32 | [diff] [blame] | 13615 | IPAddress ip; |
martijn | 654c8c4 | 2016-02-10 22:10:59 | [diff] [blame] | 13616 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13617 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 13618 | MockConnect connect_data1(ASYNC, OK, peer_addr); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13619 | data1.set_connect_data(connect_data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13620 | |
| 13621 | // SPDY GET for HTTPS URL (direct) |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13622 | SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13623 | spdy_util_secure.ConstructSpdyGet(url2.c_str(), 1, MEDIUM)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13624 | |
| 13625 | MockWrite writes2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13626 | CreateMockWrite(req2, 0), |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13627 | }; |
| 13628 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13629 | SpdySerializedFrame resp2(spdy_util_secure.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13630 | SpdySerializedFrame body2(spdy_util_secure.ConstructSpdyDataFrame(1, true)); |
| 13631 | MockRead reads2[] = {CreateMockRead(resp2, 1), CreateMockRead(body2, 2), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13632 | MockRead(ASYNC, OK, 3)}; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13633 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13634 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 13635 | arraysize(writes2)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13636 | MockConnect connect_data2(ASYNC, OK); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13637 | data2.set_connect_data(connect_data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13638 | |
| 13639 | // Set up a proxy config that sends HTTP requests to a proxy, and |
| 13640 | // all others direct. |
| 13641 | ProxyConfig proxy_config; |
| 13642 | proxy_config.proxy_rules().ParseFromString("http=https://proxy:443"); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13643 | session_deps_.proxy_service.reset(new ProxyService( |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13644 | base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), nullptr, |
csharrison | b7e3a08 | 2015-09-22 19:13:04 | [diff] [blame] | 13645 | NULL)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13646 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13647 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13648 | ssl1.next_proto = kProtoHTTP2; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13649 | // Load a valid cert. Note, that this does not need to |
| 13650 | // be valid for proxy because the MockSSLClientSocket does |
| 13651 | // not actually verify it. But SpdySession will use this |
| 13652 | // to see if it is valid for the new origin |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13653 | ssl1.cert = ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem"); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13654 | ASSERT_TRUE(ssl1.cert); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13655 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 13656 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13657 | |
| 13658 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13659 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13660 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 13661 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13662 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13663 | session_deps_.host_resolver.reset(new MockCachingHostResolver()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13664 | session_deps_.host_resolver->rules()->AddRule("news.example.org", ip_addr); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13665 | session_deps_.host_resolver->rules()->AddRule("proxy", ip_addr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13666 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13667 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13668 | |
| 13669 | // Start the first transaction to set up the SpdySession |
| 13670 | HttpRequestInfo request1; |
| 13671 | request1.method = "GET"; |
| 13672 | request1.url = GURL(url1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13673 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13674 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13675 | TestCompletionCallback callback1; |
| 13676 | ASSERT_EQ(ERR_IO_PENDING, |
| 13677 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13678 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 13679 | data1.RunUntilPaused(); |
| 13680 | base::RunLoop().RunUntilIdle(); |
| 13681 | data1.Resume(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13682 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13683 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13684 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 13685 | |
| 13686 | // Now, start the HTTP request |
| 13687 | HttpRequestInfo request2; |
| 13688 | request2.method = "GET"; |
| 13689 | request2.url = GURL(url2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13690 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13691 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13692 | TestCompletionCallback callback2; |
| 13693 | EXPECT_EQ(ERR_IO_PENDING, |
| 13694 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 13695 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13696 | |
| 13697 | ASSERT_TRUE(callback2.have_result()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13698 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13699 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 13700 | } |
| 13701 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13702 | // Test to verify that a failed socket read (due to an ERR_CONNECTION_CLOSED |
| 13703 | // error) in SPDY session, removes the socket from pool and closes the SPDY |
| 13704 | // session. Verify that new url's from the same HttpNetworkSession (and a new |
| 13705 | // SpdySession) do work. http://crbug.com/224701 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13706 | TEST_F(HttpNetworkTransactionTest, ErrorSocketNotConnected) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13707 | const std::string https_url = "https://www.example.org/"; |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13708 | |
| 13709 | MockRead reads1[] = { |
| 13710 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED, 0) |
| 13711 | }; |
| 13712 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 13713 | SequencedSocketData data1(reads1, arraysize(reads1), NULL, 0); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13714 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13715 | SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13716 | spdy_util_.ConstructSpdyGet(https_url.c_str(), 1, MEDIUM)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13717 | MockWrite writes2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13718 | CreateMockWrite(req2, 0), |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13719 | }; |
| 13720 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13721 | SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13722 | SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13723 | MockRead reads2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13724 | CreateMockRead(resp2, 1), CreateMockRead(body2, 2), |
| 13725 | MockRead(ASYNC, OK, 3) // EOF |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13726 | }; |
| 13727 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 13728 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 13729 | arraysize(writes2)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13730 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13731 | SSLSocketDataProvider ssl1(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13732 | ssl1.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 13733 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 13734 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13735 | |
| 13736 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13737 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 13738 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 13739 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13740 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13741 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 13742 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13743 | |
| 13744 | // Start the first transaction to set up the SpdySession and verify that |
| 13745 | // connection was closed. |
| 13746 | HttpRequestInfo request1; |
| 13747 | request1.method = "GET"; |
| 13748 | request1.url = GURL(https_url); |
| 13749 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13750 | HttpNetworkTransaction trans1(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13751 | TestCompletionCallback callback1; |
| 13752 | EXPECT_EQ(ERR_IO_PENDING, |
| 13753 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13754 | EXPECT_THAT(callback1.WaitForResult(), IsError(ERR_CONNECTION_CLOSED)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13755 | |
| 13756 | // Now, start the second request and make sure it succeeds. |
| 13757 | HttpRequestInfo request2; |
| 13758 | request2.method = "GET"; |
| 13759 | request2.url = GURL(https_url); |
| 13760 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13761 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13762 | TestCompletionCallback callback2; |
| 13763 | EXPECT_EQ(ERR_IO_PENDING, |
| 13764 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13765 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13766 | ASSERT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13767 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 13768 | } |
| 13769 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13770 | TEST_F(HttpNetworkTransactionTest, CloseIdleSpdySessionToOpenNewOne) { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13771 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 13772 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 13773 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 13774 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 13775 | |
| 13776 | // Use two different hosts with different IPs so they don't get pooled. |
| 13777 | session_deps_.host_resolver->rules()->AddRule("www.a.com", "10.0.0.1"); |
| 13778 | session_deps_.host_resolver->rules()->AddRule("www.b.com", "10.0.0.2"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13779 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13780 | |
| 13781 | SSLSocketDataProvider ssl1(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13782 | ssl1.next_proto = kProtoHTTP2; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13783 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13784 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13785 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 13786 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 13787 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13788 | SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13789 | spdy_util_.ConstructSpdyGet("https://www.a.com", 1, DEFAULT_PRIORITY)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13790 | MockWrite spdy1_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13791 | CreateMockWrite(host1_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13792 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13793 | SpdySerializedFrame host1_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13794 | SpdySerializedFrame host1_resp_body( |
| 13795 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13796 | MockRead spdy1_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13797 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 13798 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13799 | }; |
| 13800 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13801 | // Use a separate test instance for the separate SpdySession that will be |
| 13802 | // created. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13803 | SpdyTestUtil spdy_util_2; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13804 | std::unique_ptr<SequencedSocketData> spdy1_data( |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13805 | new SequencedSocketData(spdy1_reads, arraysize(spdy1_reads), spdy1_writes, |
| 13806 | arraysize(spdy1_writes))); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13807 | session_deps_.socket_factory->AddSocketDataProvider(spdy1_data.get()); |
| 13808 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13809 | SpdySerializedFrame host2_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13810 | spdy_util_2.ConstructSpdyGet("https://www.b.com", 1, DEFAULT_PRIORITY)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13811 | MockWrite spdy2_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13812 | CreateMockWrite(host2_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13813 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13814 | SpdySerializedFrame host2_resp(spdy_util_2.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13815 | SpdySerializedFrame host2_resp_body( |
| 13816 | spdy_util_2.ConstructSpdyDataFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13817 | MockRead spdy2_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13818 | CreateMockRead(host2_resp, 1), CreateMockRead(host2_resp_body, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 13819 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13820 | }; |
| 13821 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13822 | std::unique_ptr<SequencedSocketData> spdy2_data( |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13823 | new SequencedSocketData(spdy2_reads, arraysize(spdy2_reads), spdy2_writes, |
| 13824 | arraysize(spdy2_writes))); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13825 | session_deps_.socket_factory->AddSocketDataProvider(spdy2_data.get()); |
| 13826 | |
| 13827 | MockWrite http_write[] = { |
| 13828 | MockWrite("GET / HTTP/1.1\r\n" |
| 13829 | "Host: www.a.com\r\n" |
| 13830 | "Connection: keep-alive\r\n\r\n"), |
| 13831 | }; |
| 13832 | |
| 13833 | MockRead http_read[] = { |
| 13834 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13835 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 13836 | MockRead("Content-Length: 6\r\n\r\n"), |
| 13837 | MockRead("hello!"), |
| 13838 | }; |
| 13839 | StaticSocketDataProvider http_data(http_read, arraysize(http_read), |
| 13840 | http_write, arraysize(http_write)); |
| 13841 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 13842 | |
| 13843 | HostPortPair host_port_pair_a("www.a.com", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 13844 | SpdySessionKey spdy_session_key_a( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 13845 | host_port_pair_a, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13846 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13847 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13848 | |
| 13849 | TestCompletionCallback callback; |
| 13850 | HttpRequestInfo request1; |
| 13851 | request1.method = "GET"; |
| 13852 | request1.url = GURL("https://www.a.com/"); |
| 13853 | request1.load_flags = 0; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13854 | std::unique_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13855 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13856 | |
| 13857 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13858 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13859 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13860 | |
| 13861 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13862 | ASSERT_TRUE(response); |
| 13863 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13864 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13865 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 13866 | EXPECT_TRUE(response->was_npn_negotiated); |
| 13867 | |
| 13868 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13869 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13870 | EXPECT_EQ("hello!", response_data); |
| 13871 | trans.reset(); |
| 13872 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13873 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13874 | |
| 13875 | HostPortPair host_port_pair_b("www.b.com", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 13876 | SpdySessionKey spdy_session_key_b( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 13877 | host_port_pair_b, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13878 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13879 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13880 | HttpRequestInfo request2; |
| 13881 | request2.method = "GET"; |
| 13882 | request2.url = GURL("https://www.b.com/"); |
| 13883 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13884 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13885 | |
| 13886 | rv = trans->Start(&request2, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13887 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13888 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13889 | |
| 13890 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13891 | ASSERT_TRUE(response); |
| 13892 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13893 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13894 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 13895 | EXPECT_TRUE(response->was_npn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13896 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13897 | EXPECT_EQ("hello!", response_data); |
| 13898 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13899 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13900 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13901 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13902 | |
| 13903 | HostPortPair host_port_pair_a1("www.a.com", 80); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 13904 | SpdySessionKey spdy_session_key_a1( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 13905 | host_port_pair_a1, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13906 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13907 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a1)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13908 | HttpRequestInfo request3; |
| 13909 | request3.method = "GET"; |
| 13910 | request3.url = GURL("http://www.a.com/"); |
| 13911 | request3.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13912 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13913 | |
| 13914 | rv = trans->Start(&request3, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13915 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13916 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13917 | |
| 13918 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13919 | ASSERT_TRUE(response); |
| 13920 | ASSERT_TRUE(response->headers); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13921 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13922 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 13923 | EXPECT_FALSE(response->was_npn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13924 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13925 | EXPECT_EQ("hello!", response_data); |
| 13926 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13927 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13928 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13929 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13930 | } |
| 13931 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13932 | TEST_F(HttpNetworkTransactionTest, HttpSyncConnectError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13933 | HttpRequestInfo request; |
| 13934 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13935 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13936 | request.load_flags = 0; |
| 13937 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13938 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13939 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13940 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13941 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 13942 | MockConnect mock_connect(SYNCHRONOUS, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13943 | StaticSocketDataProvider data; |
| 13944 | data.set_connect_data(mock_connect); |
| 13945 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13946 | |
| 13947 | TestCompletionCallback callback; |
| 13948 | |
| 13949 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13950 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13951 | |
| 13952 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13953 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13954 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13955 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 13956 | HttpRequestHeaders request_headers; |
| 13957 | trans->GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 13958 | |
| 13959 | ConnectionAttempts attempts; |
| 13960 | trans->GetConnectionAttempts(&attempts); |
| 13961 | ASSERT_EQ(1u, attempts.size()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13962 | EXPECT_THAT(attempts[0].result, IsError(ERR_NAME_NOT_RESOLVED)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 13963 | |
| 13964 | IPEndPoint endpoint; |
| 13965 | EXPECT_FALSE(trans->GetRemoteEndpoint(&endpoint)); |
| 13966 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13967 | } |
| 13968 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13969 | TEST_F(HttpNetworkTransactionTest, HttpAsyncConnectError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13970 | HttpRequestInfo request; |
| 13971 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13972 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13973 | request.load_flags = 0; |
| 13974 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13975 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13976 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13977 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13978 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 13979 | MockConnect mock_connect(ASYNC, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13980 | StaticSocketDataProvider data; |
| 13981 | data.set_connect_data(mock_connect); |
| 13982 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13983 | |
| 13984 | TestCompletionCallback callback; |
| 13985 | |
| 13986 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13987 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13988 | |
| 13989 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13990 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13991 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13992 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 13993 | HttpRequestHeaders request_headers; |
| 13994 | trans->GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 13995 | |
| 13996 | ConnectionAttempts attempts; |
| 13997 | trans->GetConnectionAttempts(&attempts); |
| 13998 | ASSERT_EQ(1u, attempts.size()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13999 | EXPECT_THAT(attempts[0].result, IsError(ERR_NAME_NOT_RESOLVED)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14000 | |
| 14001 | IPEndPoint endpoint; |
| 14002 | EXPECT_FALSE(trans->GetRemoteEndpoint(&endpoint)); |
| 14003 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14004 | } |
| 14005 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14006 | TEST_F(HttpNetworkTransactionTest, HttpSyncWriteError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14007 | HttpRequestInfo request; |
| 14008 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14009 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14010 | request.load_flags = 0; |
| 14011 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14012 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14013 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14014 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14015 | |
| 14016 | MockWrite data_writes[] = { |
| 14017 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14018 | }; |
| 14019 | MockRead data_reads[] = { |
| 14020 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 14021 | }; |
| 14022 | |
| 14023 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 14024 | data_writes, arraysize(data_writes)); |
| 14025 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14026 | |
| 14027 | TestCompletionCallback callback; |
| 14028 | |
| 14029 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14030 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14031 | |
| 14032 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14033 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14034 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14035 | HttpRequestHeaders request_headers; |
| 14036 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 14037 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 14038 | } |
| 14039 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14040 | TEST_F(HttpNetworkTransactionTest, HttpAsyncWriteError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14041 | HttpRequestInfo request; |
| 14042 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14043 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14044 | request.load_flags = 0; |
| 14045 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14046 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14047 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14048 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14049 | |
| 14050 | MockWrite data_writes[] = { |
| 14051 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
| 14052 | }; |
| 14053 | MockRead data_reads[] = { |
| 14054 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 14055 | }; |
| 14056 | |
| 14057 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 14058 | data_writes, arraysize(data_writes)); |
| 14059 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14060 | |
| 14061 | TestCompletionCallback callback; |
| 14062 | |
| 14063 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14064 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14065 | |
| 14066 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14067 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14068 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14069 | HttpRequestHeaders request_headers; |
| 14070 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 14071 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 14072 | } |
| 14073 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14074 | TEST_F(HttpNetworkTransactionTest, HttpSyncReadError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14075 | HttpRequestInfo request; |
| 14076 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14077 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14078 | request.load_flags = 0; |
| 14079 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14080 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14081 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14082 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14083 | |
| 14084 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14085 | MockWrite( |
| 14086 | "GET / HTTP/1.1\r\n" |
| 14087 | "Host: www.example.org\r\n" |
| 14088 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14089 | }; |
| 14090 | MockRead data_reads[] = { |
| 14091 | MockRead(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14092 | }; |
| 14093 | |
| 14094 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 14095 | data_writes, arraysize(data_writes)); |
| 14096 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14097 | |
| 14098 | TestCompletionCallback callback; |
| 14099 | |
| 14100 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14101 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14102 | |
| 14103 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14104 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14105 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14106 | HttpRequestHeaders request_headers; |
| 14107 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 14108 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 14109 | } |
| 14110 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14111 | TEST_F(HttpNetworkTransactionTest, HttpAsyncReadError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14112 | HttpRequestInfo request; |
| 14113 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14114 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14115 | request.load_flags = 0; |
| 14116 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14117 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14118 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14119 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14120 | |
| 14121 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14122 | MockWrite( |
| 14123 | "GET / HTTP/1.1\r\n" |
| 14124 | "Host: www.example.org\r\n" |
| 14125 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14126 | }; |
| 14127 | MockRead data_reads[] = { |
| 14128 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
| 14129 | }; |
| 14130 | |
| 14131 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 14132 | data_writes, arraysize(data_writes)); |
| 14133 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14134 | |
| 14135 | TestCompletionCallback callback; |
| 14136 | |
| 14137 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14138 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14139 | |
| 14140 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14141 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14142 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14143 | HttpRequestHeaders request_headers; |
| 14144 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 14145 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 14146 | } |
| 14147 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14148 | TEST_F(HttpNetworkTransactionTest, GetFullRequestHeadersIncludesExtraHeader) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14149 | HttpRequestInfo request; |
| 14150 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14151 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14152 | request.load_flags = 0; |
| 14153 | request.extra_headers.SetHeader("X-Foo", "bar"); |
| 14154 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14155 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14156 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14157 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14158 | |
| 14159 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14160 | MockWrite( |
| 14161 | "GET / HTTP/1.1\r\n" |
| 14162 | "Host: www.example.org\r\n" |
| 14163 | "Connection: keep-alive\r\n" |
| 14164 | "X-Foo: bar\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14165 | }; |
| 14166 | MockRead data_reads[] = { |
| 14167 | MockRead("HTTP/1.1 200 OK\r\n" |
| 14168 | "Content-Length: 5\r\n\r\n" |
| 14169 | "hello"), |
| 14170 | MockRead(ASYNC, ERR_UNEXPECTED), |
| 14171 | }; |
| 14172 | |
| 14173 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 14174 | data_writes, arraysize(data_writes)); |
| 14175 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14176 | |
| 14177 | TestCompletionCallback callback; |
| 14178 | |
| 14179 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14180 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14181 | |
| 14182 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14183 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14184 | |
| 14185 | HttpRequestHeaders request_headers; |
| 14186 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 14187 | std::string foo; |
| 14188 | EXPECT_TRUE(request_headers.GetHeader("X-Foo", &foo)); |
| 14189 | EXPECT_EQ("bar", foo); |
| 14190 | } |
| 14191 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14192 | namespace { |
| 14193 | |
yhirano | a7e05bb | 2014-11-06 05:40:39 | [diff] [blame] | 14194 | // Fake HttpStream that simply records calls to SetPriority(). |
| 14195 | class FakeStream : public HttpStream, |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14196 | public base::SupportsWeakPtr<FakeStream> { |
| 14197 | public: |
| 14198 | explicit FakeStream(RequestPriority priority) : priority_(priority) {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14199 | ~FakeStream() override {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14200 | |
| 14201 | RequestPriority priority() const { return priority_; } |
| 14202 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14203 | int InitializeStream(const HttpRequestInfo* request_info, |
| 14204 | RequestPriority priority, |
| 14205 | const BoundNetLog& net_log, |
| 14206 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14207 | return ERR_IO_PENDING; |
| 14208 | } |
| 14209 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14210 | int SendRequest(const HttpRequestHeaders& request_headers, |
| 14211 | HttpResponseInfo* response, |
| 14212 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14213 | ADD_FAILURE(); |
| 14214 | return ERR_UNEXPECTED; |
| 14215 | } |
| 14216 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14217 | int ReadResponseHeaders(const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14218 | ADD_FAILURE(); |
| 14219 | return ERR_UNEXPECTED; |
| 14220 | } |
| 14221 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14222 | int ReadResponseBody(IOBuffer* buf, |
| 14223 | int buf_len, |
| 14224 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14225 | ADD_FAILURE(); |
| 14226 | return ERR_UNEXPECTED; |
| 14227 | } |
| 14228 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14229 | void Close(bool not_reusable) override {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14230 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14231 | bool IsResponseBodyComplete() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14232 | ADD_FAILURE(); |
| 14233 | return false; |
| 14234 | } |
| 14235 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14236 | bool IsConnectionReused() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14237 | ADD_FAILURE(); |
| 14238 | return false; |
| 14239 | } |
| 14240 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14241 | void SetConnectionReused() override { ADD_FAILURE(); } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14242 | |
mmenke | bd84c39 | 2015-09-02 14:12:34 | [diff] [blame] | 14243 | bool CanReuseConnection() const override { return false; } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14244 | |
sclittle | 4de1bab9 | 2015-09-22 21:28:24 | [diff] [blame] | 14245 | int64_t GetTotalReceivedBytes() const override { |
[email protected] | bc92bc97 | 2013-12-13 08:32:59 | [diff] [blame] | 14246 | ADD_FAILURE(); |
| 14247 | return 0; |
| 14248 | } |
| 14249 | |
sclittle | be1ccf6 | 2015-09-02 19:40:36 | [diff] [blame] | 14250 | int64_t GetTotalSentBytes() const override { |
| 14251 | ADD_FAILURE(); |
| 14252 | return 0; |
| 14253 | } |
| 14254 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14255 | bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14256 | ADD_FAILURE(); |
| 14257 | return false; |
| 14258 | } |
| 14259 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14260 | void GetSSLInfo(SSLInfo* ssl_info) override { ADD_FAILURE(); } |
| 14261 | |
| 14262 | void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14263 | ADD_FAILURE(); |
| 14264 | } |
| 14265 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14266 | bool GetRemoteEndpoint(IPEndPoint* endpoint) override { return false; } |
| 14267 | |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 14268 | Error GetSignedEKMForTokenBinding(crypto::ECPrivateKey* key, |
| 14269 | std::vector<uint8_t>* out) override { |
| 14270 | ADD_FAILURE(); |
| 14271 | return ERR_NOT_IMPLEMENTED; |
| 14272 | } |
| 14273 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14274 | void Drain(HttpNetworkSession* session) override { ADD_FAILURE(); } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14275 | |
zhongyi | ca364fbb | 2015-12-12 03:39:12 | [diff] [blame] | 14276 | void PopulateNetErrorDetails(NetErrorDetails* details) override { return; } |
| 14277 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14278 | void SetPriority(RequestPriority priority) override { priority_ = priority; } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14279 | |
yhirano | a7e05bb | 2014-11-06 05:40:39 | [diff] [blame] | 14280 | UploadProgress GetUploadProgress() const override { return UploadProgress(); } |
| 14281 | |
| 14282 | HttpStream* RenewStreamForAuth() override { return NULL; } |
| 14283 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14284 | private: |
| 14285 | RequestPriority priority_; |
| 14286 | |
| 14287 | DISALLOW_COPY_AND_ASSIGN(FakeStream); |
| 14288 | }; |
| 14289 | |
| 14290 | // Fake HttpStreamRequest that simply records calls to SetPriority() |
| 14291 | // and vends FakeStreams with its current priority. |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14292 | class FakeStreamRequest : public HttpStreamRequest, |
| 14293 | public base::SupportsWeakPtr<FakeStreamRequest> { |
| 14294 | public: |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14295 | FakeStreamRequest(RequestPriority priority, |
| 14296 | HttpStreamRequest::Delegate* delegate) |
| 14297 | : priority_(priority), |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14298 | delegate_(delegate), |
| 14299 | websocket_stream_create_helper_(NULL) {} |
| 14300 | |
| 14301 | FakeStreamRequest(RequestPriority priority, |
| 14302 | HttpStreamRequest::Delegate* delegate, |
| 14303 | WebSocketHandshakeStreamBase::CreateHelper* create_helper) |
| 14304 | : priority_(priority), |
| 14305 | delegate_(delegate), |
| 14306 | websocket_stream_create_helper_(create_helper) {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14307 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14308 | ~FakeStreamRequest() override {} |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14309 | |
| 14310 | RequestPriority priority() const { return priority_; } |
| 14311 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14312 | const WebSocketHandshakeStreamBase::CreateHelper* |
| 14313 | websocket_stream_create_helper() const { |
| 14314 | return websocket_stream_create_helper_; |
| 14315 | } |
| 14316 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14317 | // Create a new FakeStream and pass it to the request's |
| 14318 | // delegate. Returns a weak pointer to the FakeStream. |
| 14319 | base::WeakPtr<FakeStream> FinishStreamRequest() { |
| 14320 | FakeStream* fake_stream = new FakeStream(priority_); |
| 14321 | // Do this before calling OnStreamReady() as OnStreamReady() may |
| 14322 | // immediately delete |fake_stream|. |
| 14323 | base::WeakPtr<FakeStream> weak_stream = fake_stream->AsWeakPtr(); |
| 14324 | delegate_->OnStreamReady(SSLConfig(), ProxyInfo(), fake_stream); |
| 14325 | return weak_stream; |
| 14326 | } |
| 14327 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14328 | int RestartTunnelWithProxyAuth(const AuthCredentials& credentials) override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14329 | ADD_FAILURE(); |
| 14330 | return ERR_UNEXPECTED; |
| 14331 | } |
| 14332 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14333 | LoadState GetLoadState() const override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14334 | ADD_FAILURE(); |
| 14335 | return LoadState(); |
| 14336 | } |
| 14337 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14338 | void SetPriority(RequestPriority priority) override { priority_ = priority; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14339 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14340 | bool was_npn_negotiated() const override { return false; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14341 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14342 | NextProto protocol_negotiated() const override { return kProtoUnknown; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14343 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14344 | bool using_spdy() const override { return false; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14345 | |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 14346 | const ConnectionAttempts& connection_attempts() const override { |
| 14347 | static ConnectionAttempts no_attempts; |
| 14348 | return no_attempts; |
| 14349 | } |
| 14350 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14351 | private: |
| 14352 | RequestPriority priority_; |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14353 | HttpStreamRequest::Delegate* const delegate_; |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14354 | WebSocketHandshakeStreamBase::CreateHelper* websocket_stream_create_helper_; |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14355 | |
| 14356 | DISALLOW_COPY_AND_ASSIGN(FakeStreamRequest); |
| 14357 | }; |
| 14358 | |
| 14359 | // Fake HttpStreamFactory that vends FakeStreamRequests. |
| 14360 | class FakeStreamFactory : public HttpStreamFactory { |
| 14361 | public: |
| 14362 | FakeStreamFactory() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14363 | ~FakeStreamFactory() override {} |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14364 | |
| 14365 | // Returns a WeakPtr<> to the last HttpStreamRequest returned by |
| 14366 | // RequestStream() (which may be NULL if it was destroyed already). |
| 14367 | base::WeakPtr<FakeStreamRequest> last_stream_request() { |
| 14368 | return last_stream_request_; |
| 14369 | } |
| 14370 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14371 | HttpStreamRequest* RequestStream(const HttpRequestInfo& info, |
| 14372 | RequestPriority priority, |
| 14373 | const SSLConfig& server_ssl_config, |
| 14374 | const SSLConfig& proxy_ssl_config, |
| 14375 | HttpStreamRequest::Delegate* delegate, |
| 14376 | const BoundNetLog& net_log) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14377 | FakeStreamRequest* fake_request = new FakeStreamRequest(priority, delegate); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14378 | last_stream_request_ = fake_request->AsWeakPtr(); |
| 14379 | return fake_request; |
| 14380 | } |
| 14381 | |
xunjieli | 5749218c | 2016-03-22 16:43:06 | [diff] [blame] | 14382 | HttpStreamRequest* RequestBidirectionalStreamImpl( |
xunjieli | 11834f0 | 2015-12-22 04:27:08 | [diff] [blame] | 14383 | const HttpRequestInfo& info, |
| 14384 | RequestPriority priority, |
| 14385 | const SSLConfig& server_ssl_config, |
| 14386 | const SSLConfig& proxy_ssl_config, |
| 14387 | HttpStreamRequest::Delegate* delegate, |
| 14388 | const BoundNetLog& net_log) override { |
| 14389 | NOTREACHED(); |
| 14390 | return nullptr; |
| 14391 | } |
| 14392 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14393 | HttpStreamRequest* RequestWebSocketHandshakeStream( |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14394 | const HttpRequestInfo& info, |
| 14395 | RequestPriority priority, |
| 14396 | const SSLConfig& server_ssl_config, |
| 14397 | const SSLConfig& proxy_ssl_config, |
| 14398 | HttpStreamRequest::Delegate* delegate, |
[email protected] | 467086b | 2013-11-12 08:19:46 | [diff] [blame] | 14399 | WebSocketHandshakeStreamBase::CreateHelper* create_helper, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 14400 | const BoundNetLog& net_log) override { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14401 | FakeStreamRequest* fake_request = |
| 14402 | new FakeStreamRequest(priority, delegate, create_helper); |
| 14403 | last_stream_request_ = fake_request->AsWeakPtr(); |
| 14404 | return fake_request; |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14405 | } |
| 14406 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14407 | void PreconnectStreams(int num_streams, |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 14408 | const HttpRequestInfo& info) override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14409 | ADD_FAILURE(); |
| 14410 | } |
| 14411 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14412 | const HostMappingRules* GetHostMappingRules() const override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14413 | ADD_FAILURE(); |
| 14414 | return NULL; |
| 14415 | } |
| 14416 | |
| 14417 | private: |
| 14418 | base::WeakPtr<FakeStreamRequest> last_stream_request_; |
| 14419 | |
| 14420 | DISALLOW_COPY_AND_ASSIGN(FakeStreamFactory); |
| 14421 | }; |
| 14422 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14423 | // TODO(ricea): Maybe unify this with the one in |
| 14424 | // url_request_http_job_unittest.cc ? |
| 14425 | class FakeWebSocketBasicHandshakeStream : public WebSocketHandshakeStreamBase { |
| 14426 | public: |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14427 | FakeWebSocketBasicHandshakeStream( |
| 14428 | std::unique_ptr<ClientSocketHandle> connection, |
| 14429 | bool using_proxy) |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14430 | : state_(connection.release(), using_proxy) {} |
| 14431 | |
| 14432 | // Fake implementation of HttpStreamBase methods. |
| 14433 | // This ends up being quite "real" because this object has to really send data |
| 14434 | // on the mock socket. It might be easier to use the real implementation, but |
| 14435 | // the fact that the WebSocket code is not compiled on iOS makes that |
| 14436 | // difficult. |
| 14437 | int InitializeStream(const HttpRequestInfo* request_info, |
| 14438 | RequestPriority priority, |
| 14439 | const BoundNetLog& net_log, |
| 14440 | const CompletionCallback& callback) override { |
| 14441 | state_.Initialize(request_info, priority, net_log, callback); |
| 14442 | return OK; |
| 14443 | } |
| 14444 | |
| 14445 | int SendRequest(const HttpRequestHeaders& request_headers, |
| 14446 | HttpResponseInfo* response, |
| 14447 | const CompletionCallback& callback) override { |
| 14448 | return parser()->SendRequest(state_.GenerateRequestLine(), request_headers, |
| 14449 | response, callback); |
| 14450 | } |
| 14451 | |
| 14452 | int ReadResponseHeaders(const CompletionCallback& callback) override { |
| 14453 | return parser()->ReadResponseHeaders(callback); |
| 14454 | } |
| 14455 | |
| 14456 | int ReadResponseBody(IOBuffer* buf, |
| 14457 | int buf_len, |
| 14458 | const CompletionCallback& callback) override { |
| 14459 | NOTREACHED(); |
| 14460 | return ERR_IO_PENDING; |
| 14461 | } |
| 14462 | |
| 14463 | void Close(bool not_reusable) override { |
| 14464 | if (parser()) |
| 14465 | parser()->Close(true); |
| 14466 | } |
| 14467 | |
| 14468 | bool IsResponseBodyComplete() const override { |
| 14469 | NOTREACHED(); |
| 14470 | return false; |
| 14471 | } |
| 14472 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14473 | bool IsConnectionReused() const override { |
| 14474 | NOTREACHED(); |
| 14475 | return false; |
| 14476 | } |
| 14477 | void SetConnectionReused() override { NOTREACHED(); } |
| 14478 | |
mmenke | bd84c39 | 2015-09-02 14:12:34 | [diff] [blame] | 14479 | bool CanReuseConnection() const override { return false; } |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14480 | |
sclittle | 4de1bab9 | 2015-09-22 21:28:24 | [diff] [blame] | 14481 | int64_t GetTotalReceivedBytes() const override { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14482 | NOTREACHED(); |
| 14483 | return 0; |
| 14484 | } |
| 14485 | |
sclittle | be1ccf6 | 2015-09-02 19:40:36 | [diff] [blame] | 14486 | int64_t GetTotalSentBytes() const override { |
| 14487 | NOTREACHED(); |
| 14488 | return 0; |
| 14489 | } |
| 14490 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14491 | bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override { |
| 14492 | NOTREACHED(); |
| 14493 | return false; |
| 14494 | } |
| 14495 | |
Adam Rice | cb76ac6 | 2015-02-20 05:33:25 | [diff] [blame] | 14496 | void GetSSLInfo(SSLInfo* ssl_info) override {} |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14497 | |
| 14498 | void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override { |
| 14499 | NOTREACHED(); |
| 14500 | } |
| 14501 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14502 | bool GetRemoteEndpoint(IPEndPoint* endpoint) override { return false; } |
| 14503 | |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 14504 | Error GetSignedEKMForTokenBinding(crypto::ECPrivateKey* key, |
| 14505 | std::vector<uint8_t>* out) override { |
| 14506 | ADD_FAILURE(); |
| 14507 | return ERR_NOT_IMPLEMENTED; |
| 14508 | } |
| 14509 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14510 | void Drain(HttpNetworkSession* session) override { NOTREACHED(); } |
| 14511 | |
zhongyi | ca364fbb | 2015-12-12 03:39:12 | [diff] [blame] | 14512 | void PopulateNetErrorDetails(NetErrorDetails* details) override { return; } |
| 14513 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14514 | void SetPriority(RequestPriority priority) override { NOTREACHED(); } |
| 14515 | |
| 14516 | UploadProgress GetUploadProgress() const override { |
| 14517 | NOTREACHED(); |
| 14518 | return UploadProgress(); |
| 14519 | } |
| 14520 | |
| 14521 | HttpStream* RenewStreamForAuth() override { |
| 14522 | NOTREACHED(); |
| 14523 | return nullptr; |
| 14524 | } |
| 14525 | |
| 14526 | // Fake implementation of WebSocketHandshakeStreamBase method(s) |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14527 | std::unique_ptr<WebSocketStream> Upgrade() override { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14528 | NOTREACHED(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14529 | return std::unique_ptr<WebSocketStream>(); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14530 | } |
| 14531 | |
| 14532 | private: |
| 14533 | HttpStreamParser* parser() const { return state_.parser(); } |
| 14534 | HttpBasicState state_; |
| 14535 | |
| 14536 | DISALLOW_COPY_AND_ASSIGN(FakeWebSocketBasicHandshakeStream); |
| 14537 | }; |
| 14538 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14539 | // TODO(yhirano): Split this class out into a net/websockets file, if it is |
| 14540 | // worth doing. |
| 14541 | class FakeWebSocketStreamCreateHelper : |
| 14542 | public WebSocketHandshakeStreamBase::CreateHelper { |
| 14543 | public: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14544 | WebSocketHandshakeStreamBase* CreateBasicStream( |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14545 | std::unique_ptr<ClientSocketHandle> connection, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 14546 | bool using_proxy) override { |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 14547 | return new FakeWebSocketBasicHandshakeStream(std::move(connection), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14548 | using_proxy); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14549 | } |
| 14550 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14551 | WebSocketHandshakeStreamBase* CreateSpdyStream( |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14552 | const base::WeakPtr<SpdySession>& session, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 14553 | bool use_relative_url) override { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14554 | NOTREACHED(); |
| 14555 | return NULL; |
| 14556 | }; |
| 14557 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14558 | ~FakeWebSocketStreamCreateHelper() override {} |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14559 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14560 | virtual std::unique_ptr<WebSocketStream> Upgrade() { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14561 | NOTREACHED(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14562 | return std::unique_ptr<WebSocketStream>(); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14563 | } |
| 14564 | }; |
| 14565 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14566 | } // namespace |
| 14567 | |
| 14568 | // Make sure that HttpNetworkTransaction passes on its priority to its |
| 14569 | // stream request on start. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14570 | TEST_F(HttpNetworkTransactionTest, SetStreamRequestPriorityOnStart) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14571 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14572 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14573 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14574 | peer.SetHttpStreamFactory(std::unique_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14575 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14576 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14577 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14578 | ASSERT_FALSE(fake_factory->last_stream_request()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14579 | |
| 14580 | HttpRequestInfo request; |
| 14581 | TestCompletionCallback callback; |
| 14582 | EXPECT_EQ(ERR_IO_PENDING, |
| 14583 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 14584 | |
| 14585 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 14586 | fake_factory->last_stream_request(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14587 | ASSERT_TRUE(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14588 | EXPECT_EQ(LOW, fake_request->priority()); |
| 14589 | } |
| 14590 | |
| 14591 | // Make sure that HttpNetworkTransaction passes on its priority |
| 14592 | // updates to its stream request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14593 | TEST_F(HttpNetworkTransactionTest, SetStreamRequestPriority) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14594 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14595 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14596 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14597 | peer.SetHttpStreamFactory(std::unique_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14598 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14599 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14600 | |
| 14601 | HttpRequestInfo request; |
| 14602 | TestCompletionCallback callback; |
| 14603 | EXPECT_EQ(ERR_IO_PENDING, |
| 14604 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 14605 | |
| 14606 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 14607 | fake_factory->last_stream_request(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14608 | ASSERT_TRUE(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14609 | EXPECT_EQ(LOW, fake_request->priority()); |
| 14610 | |
| 14611 | trans.SetPriority(LOWEST); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14612 | ASSERT_TRUE(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14613 | EXPECT_EQ(LOWEST, fake_request->priority()); |
| 14614 | } |
| 14615 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14616 | // Make sure that HttpNetworkTransaction passes on its priority |
| 14617 | // updates to its stream. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14618 | TEST_F(HttpNetworkTransactionTest, SetStreamPriority) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14619 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14620 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14621 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14622 | peer.SetHttpStreamFactory(std::unique_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14623 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14624 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14625 | |
| 14626 | HttpRequestInfo request; |
| 14627 | TestCompletionCallback callback; |
| 14628 | EXPECT_EQ(ERR_IO_PENDING, |
| 14629 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 14630 | |
| 14631 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 14632 | fake_factory->last_stream_request(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14633 | ASSERT_TRUE(fake_request); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14634 | base::WeakPtr<FakeStream> fake_stream = fake_request->FinishStreamRequest(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14635 | ASSERT_TRUE(fake_stream); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14636 | EXPECT_EQ(LOW, fake_stream->priority()); |
| 14637 | |
| 14638 | trans.SetPriority(LOWEST); |
| 14639 | EXPECT_EQ(LOWEST, fake_stream->priority()); |
| 14640 | } |
| 14641 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14642 | TEST_F(HttpNetworkTransactionTest, CreateWebSocketHandshakeStream) { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14643 | // The same logic needs to be tested for both ws: and wss: schemes, but this |
| 14644 | // test is already parameterised on NextProto, so it uses a loop to verify |
| 14645 | // that the different schemes work. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14646 | std::string test_cases[] = {"ws://www.example.org/", |
| 14647 | "wss://www.example.org/"}; |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14648 | for (size_t i = 0; i < arraysize(test_cases); ++i) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14649 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14650 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14651 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
| 14652 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
[email protected] | 0191b51c | 2013-11-18 10:55:23 | [diff] [blame] | 14653 | peer.SetHttpStreamFactoryForWebSocket( |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14654 | std::unique_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14655 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14656 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14657 | trans.SetWebSocketHandshakeStreamCreateHelper( |
| 14658 | &websocket_stream_create_helper); |
| 14659 | |
| 14660 | HttpRequestInfo request; |
| 14661 | TestCompletionCallback callback; |
| 14662 | request.method = "GET"; |
| 14663 | request.url = GURL(test_cases[i]); |
| 14664 | |
| 14665 | EXPECT_EQ(ERR_IO_PENDING, |
| 14666 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 14667 | |
| 14668 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 14669 | fake_factory->last_stream_request(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14670 | ASSERT_TRUE(fake_request); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14671 | EXPECT_EQ(&websocket_stream_create_helper, |
| 14672 | fake_request->websocket_stream_create_helper()); |
| 14673 | } |
| 14674 | } |
| 14675 | |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14676 | // Tests that when a used socket is returned to the SSL socket pool, it's closed |
| 14677 | // if the transport socket pool is stalled on the global socket limit. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14678 | TEST_F(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest) { |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14679 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 14680 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 14681 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 14682 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 14683 | |
| 14684 | // Set up SSL request. |
| 14685 | |
| 14686 | HttpRequestInfo ssl_request; |
| 14687 | ssl_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14688 | ssl_request.url = GURL("https://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14689 | |
| 14690 | MockWrite ssl_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14691 | MockWrite( |
| 14692 | "GET / HTTP/1.1\r\n" |
| 14693 | "Host: www.example.org\r\n" |
| 14694 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14695 | }; |
| 14696 | MockRead ssl_reads[] = { |
| 14697 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14698 | MockRead("Content-Length: 11\r\n\r\n"), |
| 14699 | MockRead("hello world"), |
| 14700 | MockRead(SYNCHRONOUS, OK), |
| 14701 | }; |
| 14702 | StaticSocketDataProvider ssl_data(ssl_reads, arraysize(ssl_reads), |
| 14703 | ssl_writes, arraysize(ssl_writes)); |
| 14704 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 14705 | |
| 14706 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 14707 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 14708 | |
| 14709 | // Set up HTTP request. |
| 14710 | |
| 14711 | HttpRequestInfo http_request; |
| 14712 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14713 | http_request.url = GURL("http://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14714 | |
| 14715 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14716 | MockWrite( |
| 14717 | "GET / HTTP/1.1\r\n" |
| 14718 | "Host: www.example.org\r\n" |
| 14719 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14720 | }; |
| 14721 | MockRead http_reads[] = { |
| 14722 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14723 | MockRead("Content-Length: 7\r\n\r\n"), |
| 14724 | MockRead("falafel"), |
| 14725 | MockRead(SYNCHRONOUS, OK), |
| 14726 | }; |
| 14727 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 14728 | http_writes, arraysize(http_writes)); |
| 14729 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 14730 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14731 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14732 | |
| 14733 | // Start the SSL request. |
| 14734 | TestCompletionCallback ssl_callback; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14735 | std::unique_ptr<HttpTransaction> ssl_trans( |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14736 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 14737 | ASSERT_EQ(ERR_IO_PENDING, |
| 14738 | ssl_trans->Start(&ssl_request, ssl_callback.callback(), |
| 14739 | BoundNetLog())); |
| 14740 | |
| 14741 | // Start the HTTP request. Pool should stall. |
| 14742 | TestCompletionCallback http_callback; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14743 | std::unique_ptr<HttpTransaction> http_trans( |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14744 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 14745 | ASSERT_EQ(ERR_IO_PENDING, |
| 14746 | http_trans->Start(&http_request, http_callback.callback(), |
| 14747 | BoundNetLog())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14748 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14749 | |
| 14750 | // Wait for response from SSL request. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14751 | ASSERT_THAT(ssl_callback.WaitForResult(), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14752 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14753 | ASSERT_THAT(ReadTransaction(ssl_trans.get(), &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14754 | EXPECT_EQ("hello world", response_data); |
| 14755 | |
| 14756 | // The SSL socket should automatically be closed, so the HTTP request can |
| 14757 | // start. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14758 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 14759 | ASSERT_FALSE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14760 | |
| 14761 | // The HTTP request can now complete. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14762 | ASSERT_THAT(http_callback.WaitForResult(), IsOk()); |
| 14763 | ASSERT_THAT(ReadTransaction(http_trans.get(), &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14764 | EXPECT_EQ("falafel", response_data); |
| 14765 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14766 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14767 | } |
| 14768 | |
| 14769 | // Tests that when a SSL connection is established but there's no corresponding |
| 14770 | // request that needs it, the new socket is closed if the transport socket pool |
| 14771 | // is stalled on the global socket limit. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14772 | TEST_F(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest2) { |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14773 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 14774 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 14775 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 14776 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 14777 | |
| 14778 | // Set up an ssl request. |
| 14779 | |
| 14780 | HttpRequestInfo ssl_request; |
| 14781 | ssl_request.method = "GET"; |
| 14782 | ssl_request.url = GURL("https://www.foopy.com/"); |
| 14783 | |
| 14784 | // No data will be sent on the SSL socket. |
| 14785 | StaticSocketDataProvider ssl_data; |
| 14786 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 14787 | |
| 14788 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 14789 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 14790 | |
| 14791 | // Set up HTTP request. |
| 14792 | |
| 14793 | HttpRequestInfo http_request; |
| 14794 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14795 | http_request.url = GURL("http://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14796 | |
| 14797 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14798 | MockWrite( |
| 14799 | "GET / HTTP/1.1\r\n" |
| 14800 | "Host: www.example.org\r\n" |
| 14801 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14802 | }; |
| 14803 | MockRead http_reads[] = { |
| 14804 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14805 | MockRead("Content-Length: 7\r\n\r\n"), |
| 14806 | MockRead("falafel"), |
| 14807 | MockRead(SYNCHRONOUS, OK), |
| 14808 | }; |
| 14809 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 14810 | http_writes, arraysize(http_writes)); |
| 14811 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 14812 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14813 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14814 | |
| 14815 | // Preconnect an SSL socket. A preconnect is needed because connect jobs are |
| 14816 | // cancelled when a normal transaction is cancelled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14817 | HttpStreamFactory* http_stream_factory = session->http_stream_factory(); |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 14818 | http_stream_factory->PreconnectStreams(1, ssl_request); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14819 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14820 | |
| 14821 | // Start the HTTP request. Pool should stall. |
| 14822 | TestCompletionCallback http_callback; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14823 | std::unique_ptr<HttpTransaction> http_trans( |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14824 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 14825 | ASSERT_EQ(ERR_IO_PENDING, |
| 14826 | http_trans->Start(&http_request, http_callback.callback(), |
| 14827 | BoundNetLog())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14828 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14829 | |
| 14830 | // The SSL connection will automatically be closed once the connection is |
| 14831 | // established, to let the HTTP request start. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14832 | ASSERT_THAT(http_callback.WaitForResult(), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14833 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14834 | ASSERT_THAT(ReadTransaction(http_trans.get(), &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14835 | EXPECT_EQ("falafel", response_data); |
| 14836 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14837 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14838 | } |
| 14839 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14840 | TEST_F(HttpNetworkTransactionTest, PostReadsErrorResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14841 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 14842 | element_readers.push_back( |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14843 | base::WrapUnique(new UploadBytesElementReader("foo", 3))); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 14844 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14845 | |
| 14846 | HttpRequestInfo request; |
| 14847 | request.method = "POST"; |
| 14848 | request.url = GURL("http://www.foo.com/"); |
| 14849 | request.upload_data_stream = &upload_data_stream; |
| 14850 | request.load_flags = 0; |
| 14851 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14852 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14853 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14854 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14855 | // Send headers successfully, but get an error while sending the body. |
| 14856 | MockWrite data_writes[] = { |
| 14857 | MockWrite("POST / HTTP/1.1\r\n" |
| 14858 | "Host: www.foo.com\r\n" |
| 14859 | "Connection: keep-alive\r\n" |
| 14860 | "Content-Length: 3\r\n\r\n"), |
| 14861 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14862 | }; |
| 14863 | |
| 14864 | MockRead data_reads[] = { |
| 14865 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 14866 | MockRead("hello world"), |
| 14867 | MockRead(SYNCHRONOUS, OK), |
| 14868 | }; |
| 14869 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14870 | arraysize(data_writes)); |
| 14871 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14872 | |
| 14873 | TestCompletionCallback callback; |
| 14874 | |
| 14875 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14876 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14877 | |
| 14878 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14879 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14880 | |
| 14881 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14882 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14883 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14884 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14885 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 14886 | |
| 14887 | std::string response_data; |
| 14888 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14889 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14890 | EXPECT_EQ("hello world", response_data); |
| 14891 | } |
| 14892 | |
| 14893 | // This test makes sure the retry logic doesn't trigger when reading an error |
| 14894 | // response from a server that rejected a POST with a CONNECTION_RESET. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14895 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14896 | PostReadsErrorResponseAfterResetOnReusedSocket) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14897 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14898 | MockWrite data_writes[] = { |
| 14899 | MockWrite("GET / HTTP/1.1\r\n" |
| 14900 | "Host: www.foo.com\r\n" |
| 14901 | "Connection: keep-alive\r\n\r\n"), |
| 14902 | MockWrite("POST / HTTP/1.1\r\n" |
| 14903 | "Host: www.foo.com\r\n" |
| 14904 | "Connection: keep-alive\r\n" |
| 14905 | "Content-Length: 3\r\n\r\n"), |
| 14906 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14907 | }; |
| 14908 | |
| 14909 | MockRead data_reads[] = { |
| 14910 | MockRead("HTTP/1.1 200 Peachy\r\n" |
| 14911 | "Content-Length: 14\r\n\r\n"), |
| 14912 | MockRead("first response"), |
| 14913 | MockRead("HTTP/1.1 400 Not OK\r\n" |
| 14914 | "Content-Length: 15\r\n\r\n"), |
| 14915 | MockRead("second response"), |
| 14916 | MockRead(SYNCHRONOUS, OK), |
| 14917 | }; |
| 14918 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14919 | arraysize(data_writes)); |
| 14920 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14921 | |
| 14922 | TestCompletionCallback callback; |
| 14923 | HttpRequestInfo request1; |
| 14924 | request1.method = "GET"; |
| 14925 | request1.url = GURL("http://www.foo.com/"); |
| 14926 | request1.load_flags = 0; |
| 14927 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14928 | std::unique_ptr<HttpTransaction> trans1( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14929 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14930 | int rv = trans1->Start(&request1, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14931 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14932 | |
| 14933 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14934 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14935 | |
| 14936 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14937 | ASSERT_TRUE(response1); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14938 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14939 | EXPECT_TRUE(response1->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14940 | EXPECT_EQ("HTTP/1.1 200 Peachy", response1->headers->GetStatusLine()); |
| 14941 | |
| 14942 | std::string response_data1; |
| 14943 | rv = ReadTransaction(trans1.get(), &response_data1); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14944 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14945 | EXPECT_EQ("first response", response_data1); |
| 14946 | // Delete the transaction to release the socket back into the socket pool. |
| 14947 | trans1.reset(); |
| 14948 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14949 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 14950 | element_readers.push_back( |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14951 | base::WrapUnique(new UploadBytesElementReader("foo", 3))); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 14952 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14953 | |
| 14954 | HttpRequestInfo request2; |
| 14955 | request2.method = "POST"; |
| 14956 | request2.url = GURL("http://www.foo.com/"); |
| 14957 | request2.upload_data_stream = &upload_data_stream; |
| 14958 | request2.load_flags = 0; |
| 14959 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14960 | std::unique_ptr<HttpTransaction> trans2( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14961 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14962 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14963 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14964 | |
| 14965 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14966 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14967 | |
| 14968 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14969 | ASSERT_TRUE(response2); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14970 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14971 | EXPECT_TRUE(response2->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14972 | EXPECT_EQ("HTTP/1.1 400 Not OK", response2->headers->GetStatusLine()); |
| 14973 | |
| 14974 | std::string response_data2; |
| 14975 | rv = ReadTransaction(trans2.get(), &response_data2); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14976 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14977 | EXPECT_EQ("second response", response_data2); |
| 14978 | } |
| 14979 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14980 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14981 | PostReadsErrorResponseAfterResetPartialBodySent) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14982 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 14983 | element_readers.push_back( |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14984 | base::WrapUnique(new UploadBytesElementReader("foo", 3))); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 14985 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14986 | |
| 14987 | HttpRequestInfo request; |
| 14988 | request.method = "POST"; |
| 14989 | request.url = GURL("http://www.foo.com/"); |
| 14990 | request.upload_data_stream = &upload_data_stream; |
| 14991 | request.load_flags = 0; |
| 14992 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14993 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14994 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14995 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14996 | // Send headers successfully, but get an error while sending the body. |
| 14997 | MockWrite data_writes[] = { |
| 14998 | MockWrite("POST / HTTP/1.1\r\n" |
| 14999 | "Host: www.foo.com\r\n" |
| 15000 | "Connection: keep-alive\r\n" |
| 15001 | "Content-Length: 3\r\n\r\n" |
| 15002 | "fo"), |
| 15003 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15004 | }; |
| 15005 | |
| 15006 | MockRead data_reads[] = { |
| 15007 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 15008 | MockRead("hello world"), |
| 15009 | MockRead(SYNCHRONOUS, OK), |
| 15010 | }; |
| 15011 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15012 | arraysize(data_writes)); |
| 15013 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15014 | |
| 15015 | TestCompletionCallback callback; |
| 15016 | |
| 15017 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15018 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15019 | |
| 15020 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15021 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15022 | |
| 15023 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15024 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15025 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15026 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15027 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 15028 | |
| 15029 | std::string response_data; |
| 15030 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15031 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15032 | EXPECT_EQ("hello world", response_data); |
| 15033 | } |
| 15034 | |
| 15035 | // This tests the more common case than the previous test, where headers and |
| 15036 | // body are not merged into a single request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15037 | TEST_F(HttpNetworkTransactionTest, ChunkedPostReadsErrorResponseAfterReset) { |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 15038 | ChunkedUploadDataStream upload_data_stream(0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15039 | |
| 15040 | HttpRequestInfo request; |
| 15041 | request.method = "POST"; |
| 15042 | request.url = GURL("http://www.foo.com/"); |
| 15043 | request.upload_data_stream = &upload_data_stream; |
| 15044 | request.load_flags = 0; |
| 15045 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15046 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 15047 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15048 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15049 | // Send headers successfully, but get an error while sending the body. |
| 15050 | MockWrite data_writes[] = { |
| 15051 | MockWrite("POST / HTTP/1.1\r\n" |
| 15052 | "Host: www.foo.com\r\n" |
| 15053 | "Connection: keep-alive\r\n" |
| 15054 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 15055 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15056 | }; |
| 15057 | |
| 15058 | MockRead data_reads[] = { |
| 15059 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 15060 | MockRead("hello world"), |
| 15061 | MockRead(SYNCHRONOUS, OK), |
| 15062 | }; |
| 15063 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15064 | arraysize(data_writes)); |
| 15065 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15066 | |
| 15067 | TestCompletionCallback callback; |
| 15068 | |
| 15069 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15070 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15071 | // Make sure the headers are sent before adding a chunk. This ensures that |
| 15072 | // they can't be merged with the body in a single send. Not currently |
| 15073 | // necessary since a chunked body is never merged with headers, but this makes |
| 15074 | // the test more future proof. |
| 15075 | base::RunLoop().RunUntilIdle(); |
| 15076 | |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 15077 | upload_data_stream.AppendData("last chunk", 10, true); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15078 | |
| 15079 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15080 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15081 | |
| 15082 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15083 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15084 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15085 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15086 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 15087 | |
| 15088 | std::string response_data; |
| 15089 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15090 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15091 | EXPECT_EQ("hello world", response_data); |
| 15092 | } |
| 15093 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15094 | TEST_F(HttpNetworkTransactionTest, PostReadsErrorResponseAfterResetAnd100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15095 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15096 | element_readers.push_back( |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15097 | base::WrapUnique(new UploadBytesElementReader("foo", 3))); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15098 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15099 | |
| 15100 | HttpRequestInfo request; |
| 15101 | request.method = "POST"; |
| 15102 | request.url = GURL("http://www.foo.com/"); |
| 15103 | request.upload_data_stream = &upload_data_stream; |
| 15104 | request.load_flags = 0; |
| 15105 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15106 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 15107 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15108 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15109 | |
| 15110 | MockWrite data_writes[] = { |
| 15111 | MockWrite("POST / HTTP/1.1\r\n" |
| 15112 | "Host: www.foo.com\r\n" |
| 15113 | "Connection: keep-alive\r\n" |
| 15114 | "Content-Length: 3\r\n\r\n"), |
| 15115 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15116 | }; |
| 15117 | |
| 15118 | MockRead data_reads[] = { |
| 15119 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 15120 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 15121 | MockRead("hello world"), |
| 15122 | MockRead(SYNCHRONOUS, OK), |
| 15123 | }; |
| 15124 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15125 | arraysize(data_writes)); |
| 15126 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15127 | |
| 15128 | TestCompletionCallback callback; |
| 15129 | |
| 15130 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15131 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15132 | |
| 15133 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15134 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15135 | |
| 15136 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15137 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15138 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15139 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15140 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 15141 | |
| 15142 | std::string response_data; |
| 15143 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15144 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15145 | EXPECT_EQ("hello world", response_data); |
| 15146 | } |
| 15147 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15148 | TEST_F(HttpNetworkTransactionTest, PostIgnoresNonErrorResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15149 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15150 | element_readers.push_back( |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15151 | base::WrapUnique(new UploadBytesElementReader("foo", 3))); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15152 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15153 | |
| 15154 | HttpRequestInfo request; |
| 15155 | request.method = "POST"; |
| 15156 | request.url = GURL("http://www.foo.com/"); |
| 15157 | request.upload_data_stream = &upload_data_stream; |
| 15158 | request.load_flags = 0; |
| 15159 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15160 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 15161 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15162 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15163 | // Send headers successfully, but get an error while sending the body. |
| 15164 | MockWrite data_writes[] = { |
| 15165 | MockWrite("POST / HTTP/1.1\r\n" |
| 15166 | "Host: www.foo.com\r\n" |
| 15167 | "Connection: keep-alive\r\n" |
| 15168 | "Content-Length: 3\r\n\r\n"), |
| 15169 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15170 | }; |
| 15171 | |
| 15172 | MockRead data_reads[] = { |
| 15173 | MockRead("HTTP/1.0 200 Just Dandy\r\n\r\n"), |
| 15174 | MockRead("hello world"), |
| 15175 | MockRead(SYNCHRONOUS, OK), |
| 15176 | }; |
| 15177 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15178 | arraysize(data_writes)); |
| 15179 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15180 | |
| 15181 | TestCompletionCallback callback; |
| 15182 | |
| 15183 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15184 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15185 | |
| 15186 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15187 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15188 | } |
| 15189 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15190 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15191 | PostIgnoresNonErrorResponseAfterResetAnd100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15192 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15193 | element_readers.push_back( |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15194 | base::WrapUnique(new UploadBytesElementReader("foo", 3))); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15195 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15196 | |
| 15197 | HttpRequestInfo request; |
| 15198 | request.method = "POST"; |
| 15199 | request.url = GURL("http://www.foo.com/"); |
| 15200 | request.upload_data_stream = &upload_data_stream; |
| 15201 | request.load_flags = 0; |
| 15202 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15203 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 15204 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15205 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15206 | // Send headers successfully, but get an error while sending the body. |
| 15207 | MockWrite data_writes[] = { |
| 15208 | MockWrite("POST / HTTP/1.1\r\n" |
| 15209 | "Host: www.foo.com\r\n" |
| 15210 | "Connection: keep-alive\r\n" |
| 15211 | "Content-Length: 3\r\n\r\n"), |
| 15212 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15213 | }; |
| 15214 | |
| 15215 | MockRead data_reads[] = { |
| 15216 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 15217 | MockRead("HTTP/1.0 302 Redirect\r\n"), |
| 15218 | MockRead("Location: http://somewhere-else.com/\r\n"), |
| 15219 | MockRead("Content-Length: 0\r\n\r\n"), |
| 15220 | MockRead(SYNCHRONOUS, OK), |
| 15221 | }; |
| 15222 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15223 | arraysize(data_writes)); |
| 15224 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15225 | |
| 15226 | TestCompletionCallback callback; |
| 15227 | |
| 15228 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15229 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15230 | |
| 15231 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15232 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15233 | } |
| 15234 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15235 | TEST_F(HttpNetworkTransactionTest, PostIgnoresHttp09ResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15236 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15237 | element_readers.push_back( |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15238 | base::WrapUnique(new UploadBytesElementReader("foo", 3))); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15239 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15240 | |
| 15241 | HttpRequestInfo request; |
| 15242 | request.method = "POST"; |
| 15243 | request.url = GURL("http://www.foo.com/"); |
| 15244 | request.upload_data_stream = &upload_data_stream; |
| 15245 | request.load_flags = 0; |
| 15246 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15247 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 15248 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15249 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15250 | // Send headers successfully, but get an error while sending the body. |
| 15251 | MockWrite data_writes[] = { |
| 15252 | MockWrite("POST / HTTP/1.1\r\n" |
| 15253 | "Host: www.foo.com\r\n" |
| 15254 | "Connection: keep-alive\r\n" |
| 15255 | "Content-Length: 3\r\n\r\n"), |
| 15256 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15257 | }; |
| 15258 | |
| 15259 | MockRead data_reads[] = { |
| 15260 | MockRead("HTTP 0.9 rocks!"), |
| 15261 | MockRead(SYNCHRONOUS, OK), |
| 15262 | }; |
| 15263 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15264 | arraysize(data_writes)); |
| 15265 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15266 | |
| 15267 | TestCompletionCallback callback; |
| 15268 | |
| 15269 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15270 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15271 | |
| 15272 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15273 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15274 | } |
| 15275 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15276 | TEST_F(HttpNetworkTransactionTest, PostIgnoresPartial400HeadersAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15277 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15278 | element_readers.push_back( |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15279 | base::WrapUnique(new UploadBytesElementReader("foo", 3))); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15280 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15281 | |
| 15282 | HttpRequestInfo request; |
| 15283 | request.method = "POST"; |
| 15284 | request.url = GURL("http://www.foo.com/"); |
| 15285 | request.upload_data_stream = &upload_data_stream; |
| 15286 | request.load_flags = 0; |
| 15287 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15288 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 15289 | std::unique_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15290 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15291 | // Send headers successfully, but get an error while sending the body. |
| 15292 | MockWrite data_writes[] = { |
| 15293 | MockWrite("POST / HTTP/1.1\r\n" |
| 15294 | "Host: www.foo.com\r\n" |
| 15295 | "Connection: keep-alive\r\n" |
| 15296 | "Content-Length: 3\r\n\r\n"), |
| 15297 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15298 | }; |
| 15299 | |
| 15300 | MockRead data_reads[] = { |
| 15301 | MockRead("HTTP/1.0 400 Not a Full Response\r\n"), |
| 15302 | MockRead(SYNCHRONOUS, OK), |
| 15303 | }; |
| 15304 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15305 | arraysize(data_writes)); |
| 15306 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15307 | |
| 15308 | TestCompletionCallback callback; |
| 15309 | |
| 15310 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15311 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15312 | |
| 15313 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15314 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15315 | } |
| 15316 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15317 | // Verify that proxy headers are not sent to the destination server when |
| 15318 | // establishing a tunnel for a secure WebSocket connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15319 | TEST_F(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWssTunnel) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15320 | HttpRequestInfo request; |
| 15321 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15322 | request.url = GURL("wss://www.example.org/"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15323 | AddWebSocketHeaders(&request.extra_headers); |
| 15324 | |
| 15325 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 15326 | session_deps_.proxy_service = |
| 15327 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15328 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15329 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15330 | |
| 15331 | // Since a proxy is configured, try to establish a tunnel. |
| 15332 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15333 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 15334 | "Host: www.example.org:443\r\n" |
| 15335 | "Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15336 | |
| 15337 | // After calling trans->RestartWithAuth(), this is the request we should |
| 15338 | // be issuing -- the final header line contains the credentials. |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15339 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 15340 | "Host: www.example.org:443\r\n" |
| 15341 | "Proxy-Connection: keep-alive\r\n" |
| 15342 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15343 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15344 | MockWrite("GET / HTTP/1.1\r\n" |
| 15345 | "Host: www.example.org\r\n" |
| 15346 | "Connection: Upgrade\r\n" |
| 15347 | "Upgrade: websocket\r\n" |
| 15348 | "Origin: http://www.example.org\r\n" |
| 15349 | "Sec-WebSocket-Version: 13\r\n" |
| 15350 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15351 | }; |
| 15352 | |
| 15353 | // The proxy responds to the connect with a 407, using a persistent |
| 15354 | // connection. |
| 15355 | MockRead data_reads[] = { |
| 15356 | // No credentials. |
| 15357 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 15358 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 15359 | MockRead("Content-Length: 0\r\n"), |
| 15360 | MockRead("Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15361 | |
| 15362 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 15363 | |
| 15364 | MockRead("HTTP/1.1 101 Switching Protocols\r\n"), |
| 15365 | MockRead("Upgrade: websocket\r\n"), |
| 15366 | MockRead("Connection: Upgrade\r\n"), |
| 15367 | MockRead("Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n"), |
| 15368 | }; |
| 15369 | |
| 15370 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15371 | arraysize(data_writes)); |
| 15372 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15373 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 15374 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 15375 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15376 | std::unique_ptr<HttpTransaction> trans( |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15377 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 15378 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
| 15379 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 15380 | &websocket_stream_create_helper); |
| 15381 | |
| 15382 | { |
| 15383 | TestCompletionCallback callback; |
| 15384 | |
| 15385 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15386 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15387 | |
| 15388 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15389 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15390 | } |
| 15391 | |
| 15392 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 15393 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15394 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15395 | EXPECT_EQ(407, response->headers->response_code()); |
| 15396 | |
| 15397 | { |
| 15398 | TestCompletionCallback callback; |
| 15399 | |
| 15400 | int rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 15401 | callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15402 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15403 | |
| 15404 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15405 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15406 | } |
| 15407 | |
| 15408 | response = trans->GetResponseInfo(); |
| 15409 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15410 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15411 | |
| 15412 | EXPECT_EQ(101, response->headers->response_code()); |
| 15413 | |
| 15414 | trans.reset(); |
| 15415 | session->CloseAllConnections(); |
| 15416 | } |
| 15417 | |
| 15418 | // Verify that proxy headers are not sent to the destination server when |
| 15419 | // establishing a tunnel for an insecure WebSocket connection. |
| 15420 | // This requires the authentication info to be injected into the auth cache |
| 15421 | // due to crbug.com/395064 |
| 15422 | // TODO(ricea): Change to use a 407 response once issue 395064 is fixed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15423 | TEST_F(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWsTunnel) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15424 | HttpRequestInfo request; |
| 15425 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15426 | request.url = GURL("ws://www.example.org/"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15427 | AddWebSocketHeaders(&request.extra_headers); |
| 15428 | |
| 15429 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 15430 | session_deps_.proxy_service = |
| 15431 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15432 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15433 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15434 | |
| 15435 | MockWrite data_writes[] = { |
| 15436 | // Try to establish a tunnel for the WebSocket connection, with |
| 15437 | // credentials. Because WebSockets have a separate set of socket pools, |
| 15438 | // they cannot and will not use the same TCP/IP connection as the |
| 15439 | // preflight HTTP request. |
| 15440 | MockWrite( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15441 | "CONNECT www.example.org:80 HTTP/1.1\r\n" |
| 15442 | "Host: www.example.org:80\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15443 | "Proxy-Connection: keep-alive\r\n" |
| 15444 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 15445 | |
| 15446 | MockWrite( |
| 15447 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15448 | "Host: www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15449 | "Connection: Upgrade\r\n" |
| 15450 | "Upgrade: websocket\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15451 | "Origin: http://www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15452 | "Sec-WebSocket-Version: 13\r\n" |
| 15453 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n\r\n"), |
| 15454 | }; |
| 15455 | |
| 15456 | MockRead data_reads[] = { |
| 15457 | // HTTP CONNECT with credentials. |
| 15458 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 15459 | |
| 15460 | // WebSocket connection established inside tunnel. |
| 15461 | MockRead("HTTP/1.1 101 Switching Protocols\r\n"), |
| 15462 | MockRead("Upgrade: websocket\r\n"), |
| 15463 | MockRead("Connection: Upgrade\r\n"), |
| 15464 | MockRead("Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n"), |
| 15465 | }; |
| 15466 | |
| 15467 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15468 | arraysize(data_writes)); |
| 15469 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15470 | |
| 15471 | session->http_auth_cache()->Add( |
| 15472 | GURL("http://myproxy:70/"), "MyRealm1", HttpAuth::AUTH_SCHEME_BASIC, |
| 15473 | "Basic realm=MyRealm1", AuthCredentials(kFoo, kBar), "/"); |
| 15474 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15475 | std::unique_ptr<HttpTransaction> trans( |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15476 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 15477 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
| 15478 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 15479 | &websocket_stream_create_helper); |
| 15480 | |
| 15481 | TestCompletionCallback callback; |
| 15482 | |
| 15483 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15484 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15485 | |
| 15486 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15487 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15488 | |
| 15489 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 15490 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15491 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15492 | |
| 15493 | EXPECT_EQ(101, response->headers->response_code()); |
| 15494 | |
| 15495 | trans.reset(); |
| 15496 | session->CloseAllConnections(); |
| 15497 | } |
| 15498 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15499 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesPost) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15500 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15501 | element_readers.push_back( |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15502 | base::WrapUnique(new UploadBytesElementReader("foo", 3))); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15503 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15504 | |
| 15505 | HttpRequestInfo request; |
| 15506 | request.method = "POST"; |
| 15507 | request.url = GURL("http://www.foo.com/"); |
| 15508 | request.upload_data_stream = &upload_data_stream; |
| 15509 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15510 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 15511 | std::unique_ptr<HttpTransaction> trans( |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15512 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 15513 | MockWrite data_writes[] = { |
| 15514 | MockWrite("POST / HTTP/1.1\r\n" |
| 15515 | "Host: www.foo.com\r\n" |
| 15516 | "Connection: keep-alive\r\n" |
| 15517 | "Content-Length: 3\r\n\r\n"), |
| 15518 | MockWrite("foo"), |
| 15519 | }; |
| 15520 | |
| 15521 | MockRead data_reads[] = { |
| 15522 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 15523 | MockRead(SYNCHRONOUS, OK), |
| 15524 | }; |
| 15525 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15526 | arraysize(data_writes)); |
| 15527 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15528 | |
| 15529 | TestCompletionCallback callback; |
| 15530 | |
| 15531 | EXPECT_EQ(ERR_IO_PENDING, |
| 15532 | trans->Start(&request, callback.callback(), BoundNetLog())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15533 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15534 | |
| 15535 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15536 | EXPECT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15537 | |
| 15538 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
| 15539 | trans->GetTotalSentBytes()); |
| 15540 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
| 15541 | trans->GetTotalReceivedBytes()); |
| 15542 | } |
| 15543 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15544 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesPost100Continue) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15545 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15546 | element_readers.push_back( |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15547 | base::WrapUnique(new UploadBytesElementReader("foo", 3))); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15548 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15549 | |
| 15550 | HttpRequestInfo request; |
| 15551 | request.method = "POST"; |
| 15552 | request.url = GURL("http://www.foo.com/"); |
| 15553 | request.upload_data_stream = &upload_data_stream; |
| 15554 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15555 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 15556 | std::unique_ptr<HttpTransaction> trans( |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15557 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 15558 | MockWrite data_writes[] = { |
| 15559 | MockWrite("POST / HTTP/1.1\r\n" |
| 15560 | "Host: www.foo.com\r\n" |
| 15561 | "Connection: keep-alive\r\n" |
| 15562 | "Content-Length: 3\r\n\r\n"), |
| 15563 | MockWrite("foo"), |
| 15564 | }; |
| 15565 | |
| 15566 | MockRead data_reads[] = { |
| 15567 | MockRead("HTTP/1.1 100 Continue\r\n\r\n"), |
| 15568 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 15569 | MockRead(SYNCHRONOUS, OK), |
| 15570 | }; |
| 15571 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15572 | arraysize(data_writes)); |
| 15573 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15574 | |
| 15575 | TestCompletionCallback callback; |
| 15576 | |
| 15577 | EXPECT_EQ(ERR_IO_PENDING, |
| 15578 | trans->Start(&request, callback.callback(), BoundNetLog())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15579 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15580 | |
| 15581 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15582 | EXPECT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15583 | |
| 15584 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
| 15585 | trans->GetTotalSentBytes()); |
| 15586 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
| 15587 | trans->GetTotalReceivedBytes()); |
| 15588 | } |
| 15589 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15590 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesChunkedPost) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15591 | ChunkedUploadDataStream upload_data_stream(0); |
| 15592 | |
| 15593 | HttpRequestInfo request; |
| 15594 | request.method = "POST"; |
| 15595 | request.url = GURL("http://www.foo.com/"); |
| 15596 | request.upload_data_stream = &upload_data_stream; |
| 15597 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15598 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 15599 | std::unique_ptr<HttpTransaction> trans( |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15600 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 15601 | // Send headers successfully, but get an error while sending the body. |
| 15602 | MockWrite data_writes[] = { |
| 15603 | MockWrite("POST / HTTP/1.1\r\n" |
| 15604 | "Host: www.foo.com\r\n" |
| 15605 | "Connection: keep-alive\r\n" |
| 15606 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 15607 | MockWrite("1\r\nf\r\n"), MockWrite("2\r\noo\r\n"), MockWrite("0\r\n\r\n"), |
| 15608 | }; |
| 15609 | |
| 15610 | MockRead data_reads[] = { |
| 15611 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 15612 | MockRead(SYNCHRONOUS, OK), |
| 15613 | }; |
| 15614 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15615 | arraysize(data_writes)); |
| 15616 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15617 | |
| 15618 | TestCompletionCallback callback; |
| 15619 | |
| 15620 | EXPECT_EQ(ERR_IO_PENDING, |
| 15621 | trans->Start(&request, callback.callback(), BoundNetLog())); |
| 15622 | |
| 15623 | base::RunLoop().RunUntilIdle(); |
| 15624 | upload_data_stream.AppendData("f", 1, false); |
| 15625 | |
| 15626 | base::RunLoop().RunUntilIdle(); |
| 15627 | upload_data_stream.AppendData("oo", 2, true); |
| 15628 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15629 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15630 | |
| 15631 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15632 | EXPECT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15633 | |
| 15634 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
| 15635 | trans->GetTotalSentBytes()); |
| 15636 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
| 15637 | trans->GetTotalReceivedBytes()); |
| 15638 | } |
| 15639 | |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 15640 | #if !defined(OS_IOS) |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15641 | TEST_F(HttpNetworkTransactionTest, TokenBindingSpdy) { |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 15642 | const std::string https_url = "https://www.example.com"; |
| 15643 | HttpRequestInfo request; |
| 15644 | request.url = GURL(https_url); |
| 15645 | request.method = "GET"; |
| 15646 | |
| 15647 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 15648 | ssl.token_binding_negotiated = true; |
| 15649 | ssl.token_binding_key_param = TB_PARAM_ECDSAP256; |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15650 | ssl.next_proto = kProtoHTTP2; |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 15651 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 15652 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15653 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15654 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 15655 | MockRead reads[] = {CreateMockRead(resp), CreateMockRead(body), |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 15656 | MockRead(ASYNC, ERR_IO_PENDING)}; |
| 15657 | StaticSocketDataProvider data(reads, arraysize(reads), nullptr, 0); |
| 15658 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15659 | session_deps_.channel_id_service.reset(new ChannelIDService( |
| 15660 | new DefaultChannelIDStore(nullptr), base::ThreadTaskRunnerHandle::Get())); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15661 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 15662 | |
| 15663 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 15664 | TestCompletionCallback callback; |
| 15665 | EXPECT_EQ(ERR_IO_PENDING, |
| 15666 | trans.Start(&request, callback.callback(), BoundNetLog())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 15667 | base::RunLoop().RunUntilIdle(); |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 15668 | |
| 15669 | EXPECT_TRUE(trans.GetResponseInfo()->was_fetched_via_spdy); |
| 15670 | HttpRequestHeaders headers; |
| 15671 | ASSERT_TRUE(trans.GetFullRequestHeaders(&headers)); |
| 15672 | EXPECT_TRUE(headers.HasHeader(HttpRequestHeaders::kTokenBinding)); |
| 15673 | } |
| 15674 | #endif // !defined(OS_IOS) |
| 15675 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 15676 | } // namespace net |