[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> |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 10 | #include <limits> |
[email protected] | 5285d97 | 2011-10-18 18:56:34 | [diff] [blame] | 11 | #include <string> |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 12 | #include <utility> |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 13 | #include <vector> |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 14 | |
[email protected] | 68bf915 | 2008-09-25 19:47:30 | [diff] [blame] | 15 | #include "base/compiler_specific.h" |
[email protected] | 5799981 | 2013-02-24 05:40:52 | [diff] [blame] | 16 | #include "base/files/file_path.h" |
thestig | d8df033 | 2014-09-04 06:33:29 | [diff] [blame] | 17 | #include "base/files/file_util.h" |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 18 | #include "base/json/json_writer.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 19 | #include "base/logging.h" |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 20 | #include "base/macros.h" |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 21 | #include "base/memory/scoped_ptr.h" |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 22 | #include "base/memory/weak_ptr.h" |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 23 | #include "base/run_loop.h" |
[email protected] | 125ef48 | 2013-06-11 18:32:47 | [diff] [blame] | 24 | #include "base/strings/string_util.h" |
[email protected] | 750b2f3c | 2013-06-07 18:41:05 | [diff] [blame] | 25 | #include "base/strings/utf_string_conversions.h" |
[email protected] | f36a813 | 2011-09-02 18:36:33 | [diff] [blame] | 26 | #include "base/test/test_file_util.h" |
skyostil | 4891b25b | 2015-06-11 11:43:45 | [diff] [blame] | 27 | #include "base/thread_task_runner_handle.h" |
[email protected] | 277d594 | 2010-08-11 21:02:35 | [diff] [blame] | 28 | #include "net/base/auth.h" |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 29 | #include "net/base/chunked_upload_data_stream.h" |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 30 | #include "net/base/completion_callback.h" |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 31 | #include "net/base/elements_upload_data_stream.h" |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 32 | #include "net/base/load_timing_info.h" |
| 33 | #include "net/base/load_timing_info_test_util.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 34 | #include "net/base/net_errors.h" |
[email protected] | ac790b4 | 2009-12-02 04:31:31 | [diff] [blame] | 35 | #include "net/base/request_priority.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 36 | #include "net/base/test_completion_callback.h" |
[email protected] | 42fdb45 | 2012-11-01 12:44:40 | [diff] [blame] | 37 | #include "net/base/test_data_directory.h" |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 38 | #include "net/base/upload_bytes_element_reader.h" |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 39 | #include "net/base/upload_file_element_reader.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 40 | #include "net/cert/mock_cert_verifier.h" |
[email protected] | bc71b877 | 2013-04-10 20:55:16 | [diff] [blame] | 41 | #include "net/dns/host_cache.h" |
[email protected] | f2cb3cf | 2013-03-21 01:40:53 | [diff] [blame] | 42 | #include "net/dns/mock_host_resolver.h" |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 43 | #include "net/http/http_auth_challenge_tokenizer.h" |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 44 | #include "net/http/http_auth_handler_digest.h" |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 45 | #include "net/http/http_auth_handler_mock.h" |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 46 | #include "net/http/http_auth_handler_ntlm.h" |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 47 | #include "net/http/http_auth_scheme.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 48 | #include "net/http/http_basic_state.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 49 | #include "net/http/http_basic_stream.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 50 | #include "net/http/http_network_session.h" |
[email protected] | 87bfa3f | 2010-09-30 14:54:56 | [diff] [blame] | 51 | #include "net/http/http_network_session_peer.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 52 | #include "net/http/http_request_headers.h" |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 53 | #include "net/http/http_server_properties_impl.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 54 | #include "net/http/http_stream.h" |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 55 | #include "net/http/http_stream_factory.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 56 | #include "net/http/http_stream_parser.h" |
[email protected] | c41737d | 2014-05-14 07:47:19 | [diff] [blame] | 57 | #include "net/http/http_transaction_test_util.h" |
eroman | 87c53d6 | 2015-04-02 06:51:07 | [diff] [blame] | 58 | #include "net/log/net_log.h" |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 59 | #include "net/log/test_net_log.h" |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 60 | #include "net/log/test_net_log_entry.h" |
| 61 | #include "net/log/test_net_log_util.h" |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 62 | #include "net/proxy/mock_proxy_resolver.h" |
[email protected] | 51fff29d | 2008-12-19 22:17:53 | [diff] [blame] | 63 | #include "net/proxy/proxy_config_service_fixed.h" |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 64 | #include "net/proxy/proxy_info.h" |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 65 | #include "net/proxy/proxy_resolver.h" |
| 66 | #include "net/proxy/proxy_service.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 67 | #include "net/socket/client_socket_factory.h" |
mmenke | d3641e1 | 2016-01-28 16:06:15 | [diff] [blame^] | 68 | #include "net/socket/client_socket_pool.h" |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 69 | #include "net/socket/client_socket_pool_manager.h" |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 70 | #include "net/socket/connection_attempts.h" |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 71 | #include "net/socket/mock_client_socket_pool_manager.h" |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 72 | #include "net/socket/next_proto.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 73 | #include "net/socket/socket_test_util.h" |
| 74 | #include "net/socket/ssl_client_socket.h" |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 75 | #include "net/spdy/spdy_framer.h" |
| 76 | #include "net/spdy/spdy_session.h" |
| 77 | #include "net/spdy/spdy_session_pool.h" |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 78 | #include "net/spdy/spdy_test_util_common.h" |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 79 | #include "net/ssl/default_channel_id_store.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 80 | #include "net/ssl/ssl_cert_request_info.h" |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 81 | #include "net/ssl/ssl_config_service.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 82 | #include "net/ssl/ssl_config_service_defaults.h" |
| 83 | #include "net/ssl/ssl_info.h" |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 84 | #include "net/ssl/ssl_private_key.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 85 | #include "net/test/cert_test_util.h" |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 86 | #include "net/websockets/websocket_handshake_stream_base.h" |
bnc | f458840 | 2015-11-24 13:33:18 | [diff] [blame] | 87 | #include "testing/gmock/include/gmock/gmock.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 88 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | 23887f04f | 2008-12-02 19:20:15 | [diff] [blame] | 89 | #include "testing/platform_test.h" |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 90 | #include "url/gurl.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 91 | |
[email protected] | ad65a3e | 2013-12-25 18:18:01 | [diff] [blame] | 92 | using base::ASCIIToUTF16; |
| 93 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 94 | //----------------------------------------------------------------------------- |
| 95 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 96 | namespace net { |
| 97 | |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 98 | namespace { |
| 99 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 100 | enum TestCase { |
| 101 | // Test using the SPDY/3.1 protocol. |
| 102 | kTestCaseSPDY31, |
| 103 | |
| 104 | // Test using the HTTP/2 protocol, without specifying a stream |
| 105 | // dependency based on the RequestPriority. |
| 106 | kTestCaseHTTP2NoPriorityDependencies, |
| 107 | |
| 108 | // Test using the HTTP/2 protocol, specifying a stream |
| 109 | // dependency based on the RequestPriority. |
| 110 | kTestCaseHTTP2PriorityDependencies |
| 111 | }; |
| 112 | |
[email protected] | 42cba2fb | 2013-03-29 19:58:57 | [diff] [blame] | 113 | const base::string16 kBar(ASCIIToUTF16("bar")); |
| 114 | const base::string16 kBar2(ASCIIToUTF16("bar2")); |
| 115 | const base::string16 kBar3(ASCIIToUTF16("bar3")); |
| 116 | const base::string16 kBaz(ASCIIToUTF16("baz")); |
| 117 | const base::string16 kFirst(ASCIIToUTF16("first")); |
| 118 | const base::string16 kFoo(ASCIIToUTF16("foo")); |
| 119 | const base::string16 kFoo2(ASCIIToUTF16("foo2")); |
| 120 | const base::string16 kFoo3(ASCIIToUTF16("foo3")); |
| 121 | const base::string16 kFou(ASCIIToUTF16("fou")); |
| 122 | const base::string16 kSecond(ASCIIToUTF16("second")); |
| 123 | const base::string16 kTestingNTLM(ASCIIToUTF16("testing-ntlm")); |
| 124 | const base::string16 kWrongPassword(ASCIIToUTF16("wrongpassword")); |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 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 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 253 | scoped_ptr<HttpNetworkSession> CreateSession( |
| 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 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 260 | class HttpNetworkTransactionTest |
| 261 | : public PlatformTest, |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 262 | public ::testing::WithParamInterface<TestCase> { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 263 | public: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 264 | virtual ~HttpNetworkTransactionTest() { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 265 | // Important to restore the per-pool limit first, since the pool limit must |
| 266 | // always be greater than group limit, and the tests reduce both limits. |
| 267 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 268 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_pool_sockets_); |
| 269 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 270 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_group_sockets_); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 271 | SpdySession::SetPriorityDependencyDefaultForTesting(false); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 272 | } |
| 273 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 274 | protected: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 275 | HttpNetworkTransactionTest() |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 276 | : spdy_util_(GetProtocol(), GetDependenciesFromPriority()), |
| 277 | session_deps_(GetProtocol()), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 278 | old_max_group_sockets_(ClientSocketPoolManager::max_sockets_per_group( |
| 279 | HttpNetworkSession::NORMAL_SOCKET_POOL)), |
| 280 | old_max_pool_sockets_(ClientSocketPoolManager::max_sockets_per_pool( |
| 281 | HttpNetworkSession::NORMAL_SOCKET_POOL)) { |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 282 | SpdySession::SetPriorityDependencyDefaultForTesting( |
| 283 | GetDependenciesFromPriority()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 284 | } |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 285 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 286 | struct SimpleGetHelperResult { |
| 287 | int rv; |
| 288 | std::string status_line; |
| 289 | std::string response_data; |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 290 | int64_t total_received_bytes; |
| 291 | int64_t total_sent_bytes; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 292 | LoadTimingInfo load_timing_info; |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 293 | ConnectionAttempts connection_attempts; |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 294 | IPEndPoint remote_endpoint_after_start; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 295 | }; |
| 296 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 297 | void SetUp() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 298 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 299 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 300 | } |
| 301 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 302 | void TearDown() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 303 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 304 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 305 | // Empty the current queue. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 306 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 307 | PlatformTest::TearDown(); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 308 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 309 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 310 | } |
| 311 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 312 | NextProto GetProtocol() const { |
| 313 | return GetParam() == kTestCaseSPDY31 ? kProtoSPDY31 : kProtoHTTP2; |
| 314 | } |
| 315 | |
| 316 | bool GetDependenciesFromPriority() const { |
| 317 | return GetParam() == kTestCaseHTTP2PriorityDependencies; |
| 318 | } |
| 319 | |
bnc | 33b8cef4 | 2014-11-19 17:30:38 | [diff] [blame] | 320 | const char* GetAlternateProtocolFromParam() { |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 321 | return AlternateProtocolToString( |
| 322 | AlternateProtocolFromNextProto(GetProtocol())); |
bnc | 33b8cef4 | 2014-11-19 17:30:38 | [diff] [blame] | 323 | } |
| 324 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 325 | std::string GetAlternativeServiceHttpHeader() { |
| 326 | return std::string("Alt-Svc: ") + GetAlternateProtocolFromParam() + |
| 327 | "=\"www.example.com:443\"\r\n"; |
| 328 | } |
| 329 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 330 | std::string GetAlternateProtocolHttpHeader() { |
bnc | 33b8cef4 | 2014-11-19 17:30:38 | [diff] [blame] | 331 | return std::string("Alternate-Protocol: 443:") + |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 332 | GetAlternateProtocolFromParam() + "\r\n"; |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 333 | } |
| 334 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 335 | // Either |write_failure| specifies a write failure or |read_failure| |
| 336 | // specifies a read failure when using a reused socket. In either case, the |
| 337 | // failure should cause the network transaction to resend the request, and the |
| 338 | // other argument should be NULL. |
| 339 | void KeepAliveConnectionResendRequestTest(const MockWrite* write_failure, |
| 340 | const MockRead* read_failure); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 341 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 342 | // Either |write_failure| specifies a write failure or |read_failure| |
| 343 | // specifies a read failure when using a reused socket. In either case, the |
| 344 | // failure should cause the network transaction to resend the request, and the |
| 345 | // other argument should be NULL. |
| 346 | void PreconnectErrorResendRequestTest(const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 347 | const MockRead* read_failure, |
| 348 | bool use_spdy); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 349 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 350 | SimpleGetHelperResult SimpleGetHelperForData(StaticSocketDataProvider* data[], |
| 351 | size_t data_count) { |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 352 | SimpleGetHelperResult out; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 353 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 354 | HttpRequestInfo request; |
| 355 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 356 | request.url = GURL("http://www.example.org/"); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 357 | request.load_flags = 0; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 358 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 359 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 360 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 361 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 362 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 363 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 364 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 365 | for (size_t i = 0; i < data_count; ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 366 | session_deps_.socket_factory->AddSocketDataProvider(data[i]); |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 367 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 368 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 369 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 370 | |
eroman | 24bc6a1 | 2015-05-06 19:55:48 | [diff] [blame] | 371 | EXPECT_TRUE(log.bound().IsCapturing()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 372 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 373 | EXPECT_EQ(ERR_IO_PENDING, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 374 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 375 | out.rv = callback.WaitForResult(); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 376 | out.total_received_bytes = trans->GetTotalReceivedBytes(); |
| 377 | out.total_sent_bytes = trans->GetTotalSentBytes(); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 378 | |
| 379 | // Even in the failure cases that use this function, connections are always |
| 380 | // successfully established before the error. |
| 381 | EXPECT_TRUE(trans->GetLoadTimingInfo(&out.load_timing_info)); |
| 382 | TestLoadTimingNotReused(out.load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 383 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 384 | if (out.rv != OK) |
| 385 | return out; |
| 386 | |
| 387 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 388 | // Can't use ASSERT_* inside helper functions like this, so |
| 389 | // return an error. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 390 | if (response == NULL || response->headers.get() == NULL) { |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 391 | out.rv = ERR_UNEXPECTED; |
| 392 | return out; |
| 393 | } |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 394 | out.status_line = response->headers->GetStatusLine(); |
| 395 | |
[email protected] | 80a09a8 | 2012-11-16 17:40:06 | [diff] [blame] | 396 | EXPECT_EQ("127.0.0.1", response->socket_address.host()); |
| 397 | EXPECT_EQ(80, response->socket_address.port()); |
[email protected] | 6d81b48 | 2011-02-22 19:47:19 | [diff] [blame] | 398 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 399 | bool got_endpoint = |
| 400 | trans->GetRemoteEndpoint(&out.remote_endpoint_after_start); |
| 401 | EXPECT_EQ(got_endpoint, |
| 402 | out.remote_endpoint_after_start.address().size() > 0); |
| 403 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 404 | rv = ReadTransaction(trans.get(), &out.response_data); |
| 405 | EXPECT_EQ(OK, rv); |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 406 | |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 407 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 408 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 409 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 410 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST_HEADERS, |
[email protected] | 169d001 | 2010-05-10 23:20:12 | [diff] [blame] | 411 | NetLog::PHASE_NONE); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 412 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 413 | entries, pos, |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 414 | NetLog::TYPE_HTTP_TRANSACTION_READ_RESPONSE_HEADERS, |
| 415 | NetLog::PHASE_NONE); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 416 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 417 | std::string line; |
| 418 | EXPECT_TRUE(entries[pos].GetStringValue("line", &line)); |
| 419 | EXPECT_EQ("GET / HTTP/1.1\r\n", line); |
| 420 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 421 | HttpRequestHeaders request_headers; |
| 422 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 423 | std::string value; |
| 424 | EXPECT_TRUE(request_headers.GetHeader("Host", &value)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 425 | EXPECT_EQ("www.example.org", value); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 426 | EXPECT_TRUE(request_headers.GetHeader("Connection", &value)); |
| 427 | EXPECT_EQ("keep-alive", value); |
| 428 | |
| 429 | std::string response_headers; |
| 430 | EXPECT_TRUE(GetHeaders(entries[pos].params.get(), &response_headers)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 431 | EXPECT_EQ("['Host: www.example.org','Connection: keep-alive']", |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 432 | response_headers); |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 433 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 434 | out.total_received_bytes = trans->GetTotalReceivedBytes(); |
| 435 | // The total number of sent bytes should not have changed. |
| 436 | EXPECT_EQ(out.total_sent_bytes, trans->GetTotalSentBytes()); |
| 437 | |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 438 | trans->GetConnectionAttempts(&out.connection_attempts); |
[email protected] | aecfbf2 | 2008-10-16 02:02:47 | [diff] [blame] | 439 | return out; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 440 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 441 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 442 | SimpleGetHelperResult SimpleGetHelper(MockRead data_reads[], |
| 443 | size_t reads_count) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 444 | MockWrite data_writes[] = { |
| 445 | MockWrite("GET / HTTP/1.1\r\n" |
| 446 | "Host: www.example.org\r\n" |
| 447 | "Connection: keep-alive\r\n\r\n"), |
| 448 | }; |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 449 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 450 | StaticSocketDataProvider reads(data_reads, reads_count, data_writes, |
| 451 | arraysize(data_writes)); |
| 452 | StaticSocketDataProvider* data[] = {&reads}; |
| 453 | SimpleGetHelperResult out = SimpleGetHelperForData(data, 1); |
| 454 | |
| 455 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
| 456 | out.total_sent_bytes); |
| 457 | return out; |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 458 | } |
| 459 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 460 | void ConnectStatusHelperWithExpectedStatus(const MockRead& status, |
| 461 | int expected_status); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 462 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 463 | void ConnectStatusHelper(const MockRead& status); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 464 | |
| 465 | void BypassHostCacheOnRefreshHelper(int load_flags); |
| 466 | |
| 467 | void CheckErrorIsPassedBack(int error, IoMode mode); |
| 468 | |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 469 | SpdyTestUtil spdy_util_; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 470 | SpdySessionDependencies session_deps_; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 471 | |
| 472 | // Original socket limits. Some tests set these. Safest to always restore |
| 473 | // them once each test has been run. |
| 474 | int old_max_group_sockets_; |
| 475 | int old_max_pool_sockets_; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 476 | }; |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 477 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 478 | INSTANTIATE_TEST_CASE_P(ProtoPlusDepend, |
bnc | 57685ae6 | 2015-03-10 21:27:20 | [diff] [blame] | 479 | HttpNetworkTransactionTest, |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 480 | testing::Values(kTestCaseSPDY31, |
| 481 | kTestCaseHTTP2NoPriorityDependencies, |
| 482 | kTestCaseHTTP2PriorityDependencies)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 483 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 484 | namespace { |
| 485 | |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 486 | class BeforeNetworkStartHandler { |
| 487 | public: |
| 488 | explicit BeforeNetworkStartHandler(bool defer) |
| 489 | : defer_on_before_network_start_(defer), |
| 490 | observed_before_network_start_(false) {} |
| 491 | |
| 492 | void OnBeforeNetworkStart(bool* defer) { |
| 493 | *defer = defer_on_before_network_start_; |
| 494 | observed_before_network_start_ = true; |
| 495 | } |
| 496 | |
| 497 | bool observed_before_network_start() const { |
| 498 | return observed_before_network_start_; |
| 499 | } |
| 500 | |
| 501 | private: |
| 502 | const bool defer_on_before_network_start_; |
| 503 | bool observed_before_network_start_; |
| 504 | |
| 505 | DISALLOW_COPY_AND_ASSIGN(BeforeNetworkStartHandler); |
| 506 | }; |
| 507 | |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 508 | class BeforeProxyHeadersSentHandler { |
| 509 | public: |
| 510 | BeforeProxyHeadersSentHandler() |
| 511 | : observed_before_proxy_headers_sent_(false) {} |
| 512 | |
[email protected] | 1252d42f | 2014-07-01 21:20:20 | [diff] [blame] | 513 | void OnBeforeProxyHeadersSent(const ProxyInfo& proxy_info, |
| 514 | HttpRequestHeaders* request_headers) { |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 515 | observed_before_proxy_headers_sent_ = true; |
| 516 | observed_proxy_server_uri_ = proxy_info.proxy_server().ToURI(); |
| 517 | } |
| 518 | |
| 519 | bool observed_before_proxy_headers_sent() const { |
| 520 | return observed_before_proxy_headers_sent_; |
| 521 | } |
| 522 | |
| 523 | std::string observed_proxy_server_uri() const { |
| 524 | return observed_proxy_server_uri_; |
| 525 | } |
| 526 | |
| 527 | private: |
| 528 | bool observed_before_proxy_headers_sent_; |
| 529 | std::string observed_proxy_server_uri_; |
| 530 | |
| 531 | DISALLOW_COPY_AND_ASSIGN(BeforeProxyHeadersSentHandler); |
| 532 | }; |
| 533 | |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 534 | // Fill |str| with a long header list that consumes >= |size| bytes. |
| 535 | void FillLargeHeadersString(std::string* str, int size) { |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 536 | const char row[] = |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 537 | "SomeHeaderName: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n"; |
| 538 | const int sizeof_row = strlen(row); |
| 539 | const int num_rows = static_cast<int>( |
| 540 | ceil(static_cast<float>(size) / sizeof_row)); |
| 541 | const int sizeof_data = num_rows * sizeof_row; |
| 542 | DCHECK(sizeof_data >= size); |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 543 | str->reserve(sizeof_data); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 544 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 545 | for (int i = 0; i < num_rows; ++i) |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 546 | str->append(row, sizeof_row); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 547 | } |
| 548 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 549 | #if defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 550 | // Alternative functions that eliminate randomness and dependency on the local |
| 551 | // host name so that the generated NTLM messages are reproducible. |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 552 | void MockGenerateRandom1(uint8_t* output, size_t n) { |
| 553 | static const uint8_t bytes[] = {0x55, 0x29, 0x66, 0x26, |
| 554 | 0x6b, 0x9c, 0x73, 0x54}; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 555 | static size_t current_byte = 0; |
| 556 | for (size_t i = 0; i < n; ++i) { |
| 557 | output[i] = bytes[current_byte++]; |
| 558 | current_byte %= arraysize(bytes); |
| 559 | } |
| 560 | } |
| 561 | |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 562 | void MockGenerateRandom2(uint8_t* output, size_t n) { |
| 563 | static const uint8_t bytes[] = {0x96, 0x79, 0x85, 0xe7, 0x49, 0x93, |
| 564 | 0x70, 0xa1, 0x4e, 0xe7, 0x87, 0x45, |
| 565 | 0x31, 0x5b, 0xd3, 0x1f}; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 566 | static size_t current_byte = 0; |
| 567 | for (size_t i = 0; i < n; ++i) { |
| 568 | output[i] = bytes[current_byte++]; |
| 569 | current_byte %= arraysize(bytes); |
| 570 | } |
| 571 | } |
| 572 | |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 573 | std::string MockGetHostName() { |
| 574 | return "WTC-WIN7"; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 575 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 576 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 577 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 578 | template<typename ParentPool> |
| 579 | class CaptureGroupNameSocketPool : public ParentPool { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 580 | public: |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 581 | CaptureGroupNameSocketPool(HostResolver* host_resolver, |
| 582 | CertVerifier* cert_verifier); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 583 | |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 584 | const std::string last_group_name_received() const { |
| 585 | return last_group_name_; |
| 586 | } |
| 587 | |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 588 | int RequestSocket(const std::string& group_name, |
| 589 | const void* socket_params, |
| 590 | RequestPriority priority, |
mmenke | d3641e1 | 2016-01-28 16:06:15 | [diff] [blame^] | 591 | ClientSocketPool::RespectLimits respect_limits, |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 592 | ClientSocketHandle* handle, |
| 593 | const CompletionCallback& callback, |
| 594 | const BoundNetLog& net_log) override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 595 | last_group_name_ = group_name; |
| 596 | return ERR_IO_PENDING; |
| 597 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 598 | void CancelRequest(const std::string& group_name, |
| 599 | ClientSocketHandle* handle) override {} |
| 600 | void ReleaseSocket(const std::string& group_name, |
| 601 | scoped_ptr<StreamSocket> socket, |
| 602 | int id) override {} |
| 603 | void CloseIdleSockets() override {} |
| 604 | int IdleSocketCount() const override { return 0; } |
| 605 | int IdleSocketCountInGroup(const std::string& group_name) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 606 | return 0; |
| 607 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 608 | LoadState GetLoadState(const std::string& group_name, |
| 609 | const ClientSocketHandle* handle) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 610 | return LOAD_STATE_IDLE; |
| 611 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 612 | base::TimeDelta ConnectionTimeout() const override { |
[email protected] | a796bcec | 2010-03-22 17:17:26 | [diff] [blame] | 613 | return base::TimeDelta(); |
| 614 | } |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 615 | |
| 616 | private: |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 617 | std::string last_group_name_; |
| 618 | }; |
| 619 | |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 620 | typedef CaptureGroupNameSocketPool<TransportClientSocketPool> |
| 621 | CaptureGroupNameTransportSocketPool; |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 622 | typedef CaptureGroupNameSocketPool<HttpProxyClientSocketPool> |
| 623 | CaptureGroupNameHttpProxySocketPool; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 624 | typedef CaptureGroupNameSocketPool<SOCKSClientSocketPool> |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 625 | CaptureGroupNameSOCKSSocketPool; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 626 | typedef CaptureGroupNameSocketPool<SSLClientSocketPool> |
| 627 | CaptureGroupNameSSLSocketPool; |
| 628 | |
rkaplow | d90695c | 2015-03-25 22:12:41 | [diff] [blame] | 629 | template <typename ParentPool> |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 630 | CaptureGroupNameSocketPool<ParentPool>::CaptureGroupNameSocketPool( |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 631 | HostResolver* host_resolver, |
| 632 | CertVerifier* /* cert_verifier */) |
rkaplow | d90695c | 2015-03-25 22:12:41 | [diff] [blame] | 633 | : ParentPool(0, 0, host_resolver, NULL, NULL) { |
| 634 | } |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 635 | |
hashimoto | 0d3e4fb | 2015-01-09 05:02:50 | [diff] [blame] | 636 | template <> |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 637 | CaptureGroupNameHttpProxySocketPool::CaptureGroupNameSocketPool( |
hashimoto | dae13b0 | 2015-01-15 04:28:21 | [diff] [blame] | 638 | HostResolver* /* host_resolver */, |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 639 | CertVerifier* /* cert_verifier */) |
rkaplow | d90695c | 2015-03-25 22:12:41 | [diff] [blame] | 640 | : HttpProxyClientSocketPool(0, 0, NULL, NULL, NULL) { |
hashimoto | 0d3e4fb | 2015-01-09 05:02:50 | [diff] [blame] | 641 | } |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 642 | |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 643 | template <> |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 644 | CaptureGroupNameSSLSocketPool::CaptureGroupNameSocketPool( |
hashimoto | dae13b0 | 2015-01-15 04:28:21 | [diff] [blame] | 645 | HostResolver* /* host_resolver */, |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 646 | CertVerifier* cert_verifier) |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 647 | : SSLClientSocketPool(0, |
| 648 | 0, |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 649 | cert_verifier, |
| 650 | NULL, |
| 651 | NULL, |
[email protected] | 284303b6 | 2013-11-28 15:11:54 | [diff] [blame] | 652 | NULL, |
eranm | 6571b2b | 2014-12-03 15:53:23 | [diff] [blame] | 653 | NULL, |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 654 | std::string(), |
| 655 | NULL, |
| 656 | NULL, |
| 657 | NULL, |
| 658 | NULL, |
| 659 | NULL, |
[email protected] | 8e45855 | 2014-08-05 00:02:15 | [diff] [blame] | 660 | NULL) { |
| 661 | } |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 662 | |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 663 | //----------------------------------------------------------------------------- |
| 664 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 665 | // Helper functions for validating that AuthChallengeInfo's are correctly |
| 666 | // configured for common cases. |
| 667 | bool CheckBasicServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 668 | if (!auth_challenge) |
| 669 | return false; |
| 670 | EXPECT_FALSE(auth_challenge->is_proxy); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 671 | EXPECT_EQ("www.example.org:80", auth_challenge->challenger.ToString()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 672 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 673 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 674 | return true; |
| 675 | } |
| 676 | |
| 677 | bool CheckBasicProxyAuth(const AuthChallengeInfo* auth_challenge) { |
| 678 | if (!auth_challenge) |
| 679 | return false; |
| 680 | EXPECT_TRUE(auth_challenge->is_proxy); |
| 681 | EXPECT_EQ("myproxy:70", auth_challenge->challenger.ToString()); |
| 682 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 683 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 684 | return true; |
| 685 | } |
| 686 | |
| 687 | bool CheckDigestServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 688 | if (!auth_challenge) |
| 689 | return false; |
| 690 | EXPECT_FALSE(auth_challenge->is_proxy); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 691 | EXPECT_EQ("www.example.org:80", auth_challenge->challenger.ToString()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 692 | EXPECT_EQ("digestive", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 693 | EXPECT_EQ(kDigestAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 694 | return true; |
| 695 | } |
| 696 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 697 | #if defined(NTLM_PORTABLE) |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 698 | bool CheckNTLMServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 699 | if (!auth_challenge) |
| 700 | return false; |
| 701 | EXPECT_FALSE(auth_challenge->is_proxy); |
| 702 | EXPECT_EQ("172.22.68.17:80", auth_challenge->challenger.ToString()); |
| 703 | EXPECT_EQ(std::string(), auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 704 | EXPECT_EQ(kNtlmAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 705 | return true; |
| 706 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 707 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 708 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 709 | } // namespace |
| 710 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 711 | TEST_P(HttpNetworkTransactionTest, Basic) { |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 712 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 713 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 714 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 715 | } |
| 716 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 717 | TEST_P(HttpNetworkTransactionTest, SimpleGET) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 718 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 719 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 720 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 721 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 722 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 723 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 724 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 725 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 726 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 727 | EXPECT_EQ("hello world", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 728 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 729 | EXPECT_EQ(reads_size, out.total_received_bytes); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 730 | EXPECT_EQ(0u, out.connection_attempts.size()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 731 | |
| 732 | EXPECT_FALSE(out.remote_endpoint_after_start.address().empty()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 733 | } |
| 734 | |
| 735 | // Response with no status line. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 736 | TEST_P(HttpNetworkTransactionTest, SimpleGETNoHeaders) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 737 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 738 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 739 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 740 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 741 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 742 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 743 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 744 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 745 | EXPECT_EQ("hello world", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 746 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 747 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 748 | } |
| 749 | |
| 750 | // Allow up to 4 bytes of junk to precede status line. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 751 | TEST_P(HttpNetworkTransactionTest, StatusLineJunk3Bytes) { |
[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("xxxHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 754 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 755 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 756 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 757 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 758 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 759 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 760 | EXPECT_EQ("DATA", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 761 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 762 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 763 | } |
| 764 | |
| 765 | // Allow up to 4 bytes of junk to precede status line. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 766 | TEST_P(HttpNetworkTransactionTest, StatusLineJunk4Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 767 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 768 | MockRead("\n\nQJHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 769 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 770 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 771 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 772 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 773 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 774 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 775 | EXPECT_EQ("DATA", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 776 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 777 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 778 | } |
| 779 | |
| 780 | // Beyond 4 bytes of slop and it should fail to find a status line. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 781 | TEST_P(HttpNetworkTransactionTest, StatusLineJunk5Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 782 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 783 | MockRead("xxxxxHTTP/1.1 404 Not Found\nServer: blah"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 784 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 785 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 786 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 787 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 788 | EXPECT_EQ(OK, out.rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 789 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 790 | EXPECT_EQ("xxxxxHTTP/1.1 404 Not Found\nServer: blah", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 791 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 792 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 793 | } |
| 794 | |
| 795 | // Same as StatusLineJunk4Bytes, except the read chunks are smaller. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 796 | TEST_P(HttpNetworkTransactionTest, StatusLineJunk4Bytes_Slow) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 797 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 798 | MockRead("\n"), |
| 799 | MockRead("\n"), |
| 800 | MockRead("Q"), |
| 801 | MockRead("J"), |
| 802 | MockRead("HTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 803 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 804 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 805 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 806 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 807 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 808 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 809 | EXPECT_EQ("DATA", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 810 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 811 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 812 | } |
| 813 | |
| 814 | // Close the connection before enough bytes to have a status line. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 815 | TEST_P(HttpNetworkTransactionTest, StatusLinePartial) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 816 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 817 | MockRead("HTT"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 818 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 819 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 820 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 821 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 822 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 823 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 824 | EXPECT_EQ("HTT", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 825 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 826 | EXPECT_EQ(reads_size, out.total_received_bytes); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 827 | } |
| 828 | |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 829 | // Simulate a 204 response, lacking a Content-Length header, sent over a |
| 830 | // persistent connection. The response should still terminate since a 204 |
| 831 | // cannot have a response body. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 832 | TEST_P(HttpNetworkTransactionTest, StopsReading204) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 833 | char junk[] = "junk"; |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 834 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 835 | MockRead("HTTP/1.1 204 No Content\r\n\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 836 | MockRead(junk), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 837 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 838 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 839 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 840 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 841 | EXPECT_EQ(OK, out.rv); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 842 | EXPECT_EQ("HTTP/1.1 204 No Content", out.status_line); |
| 843 | EXPECT_EQ("", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 844 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 845 | int64_t response_size = reads_size - strlen(junk); |
| 846 | EXPECT_EQ(response_size, out.total_received_bytes); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 847 | } |
| 848 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 849 | // A simple request using chunked encoding with some extra data after. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 850 | TEST_P(HttpNetworkTransactionTest, ChunkedEncoding) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 851 | std::string final_chunk = "0\r\n\r\n"; |
| 852 | std::string extra_data = "HTTP/1.1 200 OK\r\n"; |
| 853 | std::string last_read = final_chunk + extra_data; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 854 | MockRead data_reads[] = { |
| 855 | MockRead("HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n"), |
| 856 | MockRead("5\r\nHello\r\n"), |
| 857 | MockRead("1\r\n"), |
| 858 | MockRead(" \r\n"), |
| 859 | MockRead("5\r\nworld\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 860 | MockRead(last_read.data()), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 861 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 862 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 863 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 864 | arraysize(data_reads)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 865 | EXPECT_EQ(OK, out.rv); |
| 866 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 867 | EXPECT_EQ("Hello world", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 868 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 869 | int64_t response_size = reads_size - extra_data.size(); |
| 870 | EXPECT_EQ(response_size, out.total_received_bytes); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 871 | } |
| 872 | |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 873 | // Next tests deal with http://crbug.com/56344. |
| 874 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 875 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 876 | MultipleContentLengthHeadersNoTransferEncoding) { |
| 877 | MockRead data_reads[] = { |
| 878 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 879 | MockRead("Content-Length: 10\r\n"), |
| 880 | MockRead("Content-Length: 5\r\n\r\n"), |
| 881 | }; |
| 882 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 883 | arraysize(data_reads)); |
| 884 | EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH, out.rv); |
| 885 | } |
| 886 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 887 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 888 | DuplicateContentLengthHeadersNoTransferEncoding) { |
| 889 | MockRead data_reads[] = { |
| 890 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 891 | MockRead("Content-Length: 5\r\n"), |
| 892 | MockRead("Content-Length: 5\r\n\r\n"), |
| 893 | MockRead("Hello"), |
| 894 | }; |
| 895 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 896 | arraysize(data_reads)); |
| 897 | EXPECT_EQ(OK, out.rv); |
| 898 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 899 | EXPECT_EQ("Hello", out.response_data); |
| 900 | } |
| 901 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 902 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 903 | ComplexContentLengthHeadersNoTransferEncoding) { |
| 904 | // More than 2 dupes. |
| 905 | { |
| 906 | MockRead data_reads[] = { |
| 907 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 908 | MockRead("Content-Length: 5\r\n"), |
| 909 | MockRead("Content-Length: 5\r\n"), |
| 910 | MockRead("Content-Length: 5\r\n\r\n"), |
| 911 | MockRead("Hello"), |
| 912 | }; |
| 913 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 914 | arraysize(data_reads)); |
| 915 | EXPECT_EQ(OK, out.rv); |
| 916 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 917 | EXPECT_EQ("Hello", out.response_data); |
| 918 | } |
| 919 | // HTTP/1.0 |
| 920 | { |
| 921 | MockRead data_reads[] = { |
| 922 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 923 | MockRead("Content-Length: 5\r\n"), |
| 924 | MockRead("Content-Length: 5\r\n"), |
| 925 | MockRead("Content-Length: 5\r\n\r\n"), |
| 926 | MockRead("Hello"), |
| 927 | }; |
| 928 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 929 | arraysize(data_reads)); |
| 930 | EXPECT_EQ(OK, out.rv); |
| 931 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 932 | EXPECT_EQ("Hello", out.response_data); |
| 933 | } |
| 934 | // 2 dupes and one mismatched. |
| 935 | { |
| 936 | MockRead data_reads[] = { |
| 937 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 938 | MockRead("Content-Length: 10\r\n"), |
| 939 | MockRead("Content-Length: 10\r\n"), |
| 940 | MockRead("Content-Length: 5\r\n\r\n"), |
| 941 | }; |
| 942 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 943 | arraysize(data_reads)); |
| 944 | EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH, out.rv); |
| 945 | } |
| 946 | } |
| 947 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 948 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 949 | MultipleContentLengthHeadersTransferEncoding) { |
| 950 | MockRead data_reads[] = { |
| 951 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 952 | MockRead("Content-Length: 666\r\n"), |
| 953 | MockRead("Content-Length: 1337\r\n"), |
| 954 | MockRead("Transfer-Encoding: chunked\r\n\r\n"), |
| 955 | MockRead("5\r\nHello\r\n"), |
| 956 | MockRead("1\r\n"), |
| 957 | MockRead(" \r\n"), |
| 958 | MockRead("5\r\nworld\r\n"), |
| 959 | MockRead("0\r\n\r\nHTTP/1.1 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 960 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 961 | }; |
| 962 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 963 | arraysize(data_reads)); |
| 964 | EXPECT_EQ(OK, out.rv); |
| 965 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 966 | EXPECT_EQ("Hello world", out.response_data); |
| 967 | } |
| 968 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 969 | // Next tests deal with http://crbug.com/98895. |
| 970 | |
| 971 | // Checks that a single Content-Disposition header results in no error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 972 | TEST_P(HttpNetworkTransactionTest, SingleContentDispositionHeader) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 973 | MockRead data_reads[] = { |
| 974 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 975 | MockRead("Content-Disposition: attachment;filename=\"salutations.txt\"r\n"), |
| 976 | MockRead("Content-Length: 5\r\n\r\n"), |
| 977 | MockRead("Hello"), |
| 978 | }; |
| 979 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 980 | arraysize(data_reads)); |
| 981 | EXPECT_EQ(OK, out.rv); |
| 982 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 983 | EXPECT_EQ("Hello", out.response_data); |
| 984 | } |
| 985 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 986 | // Checks that two identical Content-Disposition headers result in no error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 987 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 988 | TwoIdenticalContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 989 | MockRead data_reads[] = { |
| 990 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 991 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 992 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 993 | MockRead("Content-Length: 5\r\n\r\n"), |
| 994 | MockRead("Hello"), |
| 995 | }; |
| 996 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 997 | arraysize(data_reads)); |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 998 | EXPECT_EQ(OK, out.rv); |
| 999 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1000 | EXPECT_EQ("Hello", out.response_data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1001 | } |
| 1002 | |
| 1003 | // Checks that two distinct Content-Disposition headers result in an error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1004 | TEST_P(HttpNetworkTransactionTest, TwoDistinctContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1005 | MockRead data_reads[] = { |
| 1006 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1007 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1008 | MockRead("Content-Disposition: attachment;filename=\"hi.txt\"r\n"), |
| 1009 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1010 | MockRead("Hello"), |
| 1011 | }; |
| 1012 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1013 | arraysize(data_reads)); |
| 1014 | EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION, out.rv); |
| 1015 | } |
| 1016 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1017 | // Checks that two identical Location headers result in no error. |
| 1018 | // Also tests Location header behavior. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1019 | TEST_P(HttpNetworkTransactionTest, TwoIdenticalLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1020 | MockRead data_reads[] = { |
| 1021 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 1022 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1023 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1024 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1025 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1026 | }; |
| 1027 | |
| 1028 | HttpRequestInfo request; |
| 1029 | request.method = "GET"; |
| 1030 | request.url = GURL("http://redirect.com/"); |
| 1031 | request.load_flags = 0; |
| 1032 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1033 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1034 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1035 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1036 | |
| 1037 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1038 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1039 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1040 | TestCompletionCallback callback; |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1041 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1042 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1043 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1044 | |
| 1045 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 1046 | |
| 1047 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1048 | ASSERT_TRUE(response != NULL && response->headers.get() != NULL); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1049 | EXPECT_EQ("HTTP/1.1 302 Redirect", response->headers->GetStatusLine()); |
| 1050 | std::string url; |
| 1051 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 1052 | EXPECT_EQ("http://good.com/", url); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 1053 | EXPECT_TRUE(response->proxy_server.IsEmpty()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1054 | } |
| 1055 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1056 | // Checks that two distinct Location headers result in an error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1057 | TEST_P(HttpNetworkTransactionTest, TwoDistinctLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1058 | MockRead data_reads[] = { |
| 1059 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 1060 | MockRead("Location: http://good.com/\r\n"), |
| 1061 | MockRead("Location: http://evil.com/\r\n"), |
| 1062 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1063 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1064 | }; |
| 1065 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1066 | arraysize(data_reads)); |
| 1067 | EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_LOCATION, out.rv); |
| 1068 | } |
| 1069 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1070 | // Do a request using the HEAD method. Verify that we don't try to read the |
| 1071 | // message body (since HEAD has none). |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1072 | TEST_P(HttpNetworkTransactionTest, Head) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1073 | HttpRequestInfo request; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1074 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1075 | request.url = GURL("http://www.example.org/"); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1076 | request.load_flags = 0; |
| 1077 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1078 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1079 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1080 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 1081 | BeforeProxyHeadersSentHandler proxy_headers_handler; |
| 1082 | trans->SetBeforeProxyHeadersSentCallback( |
| 1083 | base::Bind(&BeforeProxyHeadersSentHandler::OnBeforeProxyHeadersSent, |
| 1084 | base::Unretained(&proxy_headers_handler))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1085 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1086 | MockWrite data_writes1[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 1087 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 1088 | "Host: www.example.org\r\n" |
| 1089 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1090 | }; |
| 1091 | MockRead data_reads1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 1092 | MockRead("HTTP/1.1 404 Not Found\r\n"), MockRead("Server: Blah\r\n"), |
| 1093 | MockRead("Content-Length: 1234\r\n\r\n"), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1094 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 1095 | // No response body because the test stops reading here. |
| 1096 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1097 | }; |
| 1098 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1099 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 1100 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1101 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1102 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1103 | TestCompletionCallback callback1; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1104 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1105 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1106 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1107 | |
| 1108 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1109 | EXPECT_EQ(OK, rv); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1110 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1111 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1112 | ASSERT_TRUE(response != NULL); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1113 | |
| 1114 | // Check that the headers got parsed. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1115 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1116 | EXPECT_EQ(1234, response->headers->GetContentLength()); |
| 1117 | EXPECT_EQ("HTTP/1.1 404 Not Found", response->headers->GetStatusLine()); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 1118 | EXPECT_TRUE(response->proxy_server.IsEmpty()); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 1119 | EXPECT_FALSE(proxy_headers_handler.observed_before_proxy_headers_sent()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1120 | |
| 1121 | std::string server_header; |
olli.raula | ee489a5 | 2016-01-25 08:37:10 | [diff] [blame] | 1122 | size_t iter = 0; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1123 | bool has_server_header = response->headers->EnumerateHeader( |
| 1124 | &iter, "Server", &server_header); |
| 1125 | EXPECT_TRUE(has_server_header); |
| 1126 | EXPECT_EQ("Blah", server_header); |
| 1127 | |
| 1128 | // Reading should give EOF right away, since there is no message body |
| 1129 | // (despite non-zero content-length). |
| 1130 | std::string response_data; |
| 1131 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1132 | EXPECT_EQ(OK, rv); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1133 | EXPECT_EQ("", response_data); |
| 1134 | } |
| 1135 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1136 | TEST_P(HttpNetworkTransactionTest, ReuseConnection) { |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1137 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1138 | |
| 1139 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1140 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1141 | MockRead("hello"), |
| 1142 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1143 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1144 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1145 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1146 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1147 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1148 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1149 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1150 | "hello", "world" |
| 1151 | }; |
| 1152 | |
| 1153 | for (int i = 0; i < 2; ++i) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1154 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1155 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1156 | request.url = GURL("http://www.example.org/"); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1157 | request.load_flags = 0; |
| 1158 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1159 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1160 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [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()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1165 | EXPECT_EQ(ERR_IO_PENDING, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1166 | |
| 1167 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1168 | EXPECT_EQ(OK, rv); |
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(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1171 | ASSERT_TRUE(response != NULL); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1172 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1173 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1174 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 1175 | EXPECT_TRUE(response->proxy_server.IsEmpty()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1176 | |
| 1177 | std::string response_data; |
[email protected] | af4876d | 2008-10-21 23:10:57 | [diff] [blame] | 1178 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1179 | EXPECT_EQ(OK, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1180 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1181 | } |
| 1182 | } |
| 1183 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1184 | TEST_P(HttpNetworkTransactionTest, Ignores100) { |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 1185 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 1186 | element_readers.push_back( |
| 1187 | make_scoped_ptr(new UploadBytesElementReader("foo", 3))); |
| 1188 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1189 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1190 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1191 | request.method = "POST"; |
| 1192 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1193 | request.upload_data_stream = &upload_data_stream; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1194 | request.load_flags = 0; |
| 1195 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1196 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1197 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1198 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1199 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1200 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1201 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 1202 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 1203 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1204 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1205 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1206 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1207 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1208 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1209 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1210 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1211 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1212 | EXPECT_EQ(ERR_IO_PENDING, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1213 | |
| 1214 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1215 | EXPECT_EQ(OK, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1216 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1217 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1218 | ASSERT_TRUE(response != NULL); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1219 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1220 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1221 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1222 | |
| 1223 | std::string response_data; |
[email protected] | af4876d | 2008-10-21 23:10:57 | [diff] [blame] | 1224 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1225 | EXPECT_EQ(OK, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1226 | EXPECT_EQ("hello world", response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1227 | } |
| 1228 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1229 | // This test is almost the same as Ignores100 above, but the response contains |
| 1230 | // 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] | 1231 | // HTTP/1.1 and the two status headers are read in one read. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1232 | TEST_P(HttpNetworkTransactionTest, Ignores1xx) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1233 | HttpRequestInfo request; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1234 | request.method = "GET"; |
| 1235 | request.url = GURL("http://www.foo.com/"); |
| 1236 | request.load_flags = 0; |
| 1237 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1238 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1239 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1240 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1241 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1242 | MockRead data_reads[] = { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1243 | MockRead("HTTP/1.1 102 Unspecified status code\r\n\r\n" |
| 1244 | "HTTP/1.1 200 OK\r\n\r\n"), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1245 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1246 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1247 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1248 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1249 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1250 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1251 | TestCompletionCallback callback; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1252 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1253 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1254 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1255 | |
| 1256 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1257 | EXPECT_EQ(OK, rv); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1258 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1259 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1260 | ASSERT_TRUE(response != NULL); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1261 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1262 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1263 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1264 | |
| 1265 | std::string response_data; |
| 1266 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1267 | EXPECT_EQ(OK, rv); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1268 | EXPECT_EQ("hello world", response_data); |
| 1269 | } |
| 1270 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1271 | TEST_P(HttpNetworkTransactionTest, Incomplete100ThenEOF) { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1272 | HttpRequestInfo request; |
| 1273 | request.method = "POST"; |
| 1274 | request.url = GURL("http://www.foo.com/"); |
| 1275 | request.load_flags = 0; |
| 1276 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1277 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1278 | scoped_ptr<HttpTransaction> trans( |
| 1279 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 1280 | |
| 1281 | MockRead data_reads[] = { |
| 1282 | MockRead(SYNCHRONOUS, "HTTP/1.0 100 Continue\r\n"), |
| 1283 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1284 | }; |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1285 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 1286 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1287 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1288 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1289 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1290 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1291 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1292 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1293 | rv = callback.WaitForResult(); |
| 1294 | EXPECT_EQ(OK, rv); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1295 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1296 | std::string response_data; |
| 1297 | rv = ReadTransaction(trans.get(), &response_data); |
| 1298 | EXPECT_EQ(OK, rv); |
| 1299 | EXPECT_EQ("", response_data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1300 | } |
| 1301 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1302 | TEST_P(HttpNetworkTransactionTest, EmptyResponse) { |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1303 | HttpRequestInfo request; |
| 1304 | request.method = "POST"; |
| 1305 | request.url = GURL("http://www.foo.com/"); |
| 1306 | request.load_flags = 0; |
| 1307 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1308 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1309 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1310 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1311 | |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1312 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1313 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1314 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1315 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1316 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1317 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1318 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1319 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1320 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1321 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1322 | |
| 1323 | rv = callback.WaitForResult(); |
| 1324 | EXPECT_EQ(ERR_EMPTY_RESPONSE, rv); |
| 1325 | } |
| 1326 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1327 | void HttpNetworkTransactionTest::KeepAliveConnectionResendRequestTest( |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1328 | const MockWrite* write_failure, |
| 1329 | const MockRead* read_failure) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1330 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1331 | request.method = "GET"; |
| 1332 | request.url = GURL("http://www.foo.com/"); |
| 1333 | request.load_flags = 0; |
| 1334 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1335 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1336 | session_deps_.net_log = &net_log; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1337 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1338 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1339 | // Written data for successfully sending both requests. |
| 1340 | MockWrite data1_writes[] = { |
| 1341 | MockWrite("GET / HTTP/1.1\r\n" |
| 1342 | "Host: www.foo.com\r\n" |
| 1343 | "Connection: keep-alive\r\n\r\n"), |
| 1344 | MockWrite("GET / HTTP/1.1\r\n" |
| 1345 | "Host: www.foo.com\r\n" |
| 1346 | "Connection: keep-alive\r\n\r\n") |
| 1347 | }; |
| 1348 | |
| 1349 | // Read results for the first request. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1350 | MockRead data1_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1351 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1352 | MockRead("hello"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1353 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1354 | }; |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1355 | |
| 1356 | if (write_failure) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1357 | ASSERT_FALSE(read_failure); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1358 | data1_writes[1] = *write_failure; |
| 1359 | } else { |
| 1360 | ASSERT_TRUE(read_failure); |
| 1361 | data1_reads[2] = *read_failure; |
| 1362 | } |
| 1363 | |
| 1364 | StaticSocketDataProvider data1(data1_reads, arraysize(data1_reads), |
| 1365 | data1_writes, arraysize(data1_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1366 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1367 | |
| 1368 | MockRead data2_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1369 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1370 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1371 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1372 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1373 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1374 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1375 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 1376 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1377 | "hello", "world" |
| 1378 | }; |
| 1379 | |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 1380 | uint32_t first_socket_log_id = NetLog::Source::kInvalidId; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1381 | for (int i = 0; i < 2; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1382 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1383 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1384 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1385 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1386 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1387 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1388 | EXPECT_EQ(ERR_IO_PENDING, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1389 | |
| 1390 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1391 | EXPECT_EQ(OK, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1392 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1393 | LoadTimingInfo load_timing_info; |
| 1394 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 1395 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1396 | if (i == 0) { |
| 1397 | first_socket_log_id = load_timing_info.socket_log_id; |
| 1398 | } else { |
| 1399 | // The second request should be using a new socket. |
| 1400 | EXPECT_NE(first_socket_log_id, load_timing_info.socket_log_id); |
| 1401 | } |
| 1402 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1403 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1404 | ASSERT_TRUE(response != NULL); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1405 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1406 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1407 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1408 | |
| 1409 | std::string response_data; |
[email protected] | af4876d | 2008-10-21 23:10:57 | [diff] [blame] | 1410 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1411 | EXPECT_EQ(OK, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1412 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1413 | } |
| 1414 | } |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1415 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1416 | void HttpNetworkTransactionTest::PreconnectErrorResendRequestTest( |
| 1417 | const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1418 | const MockRead* read_failure, |
| 1419 | bool use_spdy) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1420 | HttpRequestInfo request; |
| 1421 | request.method = "GET"; |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1422 | request.url = GURL("https://www.foo.com/"); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1423 | request.load_flags = 0; |
| 1424 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1425 | TestNetLog net_log; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1426 | session_deps_.net_log = &net_log; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1427 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1428 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1429 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 1430 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 1431 | if (use_spdy) { |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 1432 | ssl1.SetNextProto(GetProtocol()); |
| 1433 | ssl2.SetNextProto(GetProtocol()); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1434 | } |
| 1435 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 1436 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1437 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1438 | // SPDY versions of the request and response. |
| 1439 | scoped_ptr<SpdyFrame> spdy_request(spdy_util_.ConstructSpdyGet( |
| 1440 | request.url.spec().c_str(), false, 1, DEFAULT_PRIORITY)); |
| 1441 | scoped_ptr<SpdyFrame> spdy_response( |
| 1442 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 1443 | scoped_ptr<SpdyFrame> spdy_data( |
| 1444 | spdy_util_.ConstructSpdyBodyFrame(1, "hello", 5, true)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1445 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1446 | // HTTP/1.1 versions of the request and response. |
| 1447 | const char kHttpRequest[] = "GET / HTTP/1.1\r\n" |
| 1448 | "Host: www.foo.com\r\n" |
| 1449 | "Connection: keep-alive\r\n\r\n"; |
| 1450 | const char kHttpResponse[] = "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"; |
| 1451 | const char kHttpData[] = "hello"; |
| 1452 | |
| 1453 | std::vector<MockRead> data1_reads; |
| 1454 | std::vector<MockWrite> data1_writes; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1455 | if (write_failure) { |
| 1456 | ASSERT_FALSE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1457 | data1_writes.push_back(*write_failure); |
| 1458 | data1_reads.push_back(MockRead(ASYNC, OK)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1459 | } else { |
| 1460 | ASSERT_TRUE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1461 | if (use_spdy) { |
| 1462 | data1_writes.push_back(CreateMockWrite(*spdy_request)); |
| 1463 | } else { |
| 1464 | data1_writes.push_back(MockWrite(kHttpRequest)); |
| 1465 | } |
| 1466 | data1_reads.push_back(*read_failure); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1467 | } |
| 1468 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1469 | StaticSocketDataProvider data1(&data1_reads[0], data1_reads.size(), |
| 1470 | &data1_writes[0], data1_writes.size()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1471 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1472 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1473 | std::vector<MockRead> data2_reads; |
| 1474 | std::vector<MockWrite> data2_writes; |
| 1475 | |
| 1476 | if (use_spdy) { |
| 1477 | data2_writes.push_back(CreateMockWrite(*spdy_request, 0, ASYNC)); |
| 1478 | |
| 1479 | data2_reads.push_back(CreateMockRead(*spdy_response, 1, ASYNC)); |
| 1480 | data2_reads.push_back(CreateMockRead(*spdy_data, 2, ASYNC)); |
| 1481 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1482 | } else { |
| 1483 | data2_writes.push_back( |
| 1484 | MockWrite(ASYNC, kHttpRequest, strlen(kHttpRequest), 0)); |
| 1485 | |
| 1486 | data2_reads.push_back( |
| 1487 | MockRead(ASYNC, kHttpResponse, strlen(kHttpResponse), 1)); |
| 1488 | data2_reads.push_back(MockRead(ASYNC, kHttpData, strlen(kHttpData), 2)); |
| 1489 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1490 | } |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 1491 | SequencedSocketData data2(&data2_reads[0], data2_reads.size(), |
| 1492 | &data2_writes[0], data2_writes.size()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1493 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1494 | |
| 1495 | // Preconnect a socket. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 1496 | SSLConfig ssl_config; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1497 | session->ssl_config_service()->GetSSLConfig(&ssl_config); |
bnc | 1f29537 | 2015-10-21 23:24:22 | [diff] [blame] | 1498 | session->GetAlpnProtos(&ssl_config.alpn_protos); |
| 1499 | session->GetNpnProtos(&ssl_config.npn_protos); |
mmenke | d1205bd | 2015-07-15 22:26:35 | [diff] [blame] | 1500 | session->http_stream_factory()->PreconnectStreams(1, request, ssl_config, |
| 1501 | ssl_config); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1502 | // Wait for the preconnect to complete. |
| 1503 | // TODO(davidben): Some way to wait for an idle socket count might be handy. |
| 1504 | base::RunLoop().RunUntilIdle(); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1505 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1506 | |
| 1507 | // Make the request. |
| 1508 | TestCompletionCallback callback; |
| 1509 | |
| 1510 | scoped_ptr<HttpTransaction> trans( |
| 1511 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 1512 | |
| 1513 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1514 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1515 | |
| 1516 | rv = callback.WaitForResult(); |
| 1517 | EXPECT_EQ(OK, rv); |
| 1518 | |
| 1519 | LoadTimingInfo load_timing_info; |
| 1520 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1521 | TestLoadTimingNotReused( |
| 1522 | load_timing_info, |
| 1523 | CONNECT_TIMING_HAS_DNS_TIMES|CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1524 | |
| 1525 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 1526 | ASSERT_TRUE(response != NULL); |
| 1527 | |
| 1528 | EXPECT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1529 | if (response->was_fetched_via_spdy) { |
| 1530 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 1531 | } else { |
| 1532 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1533 | } |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1534 | |
| 1535 | std::string response_data; |
| 1536 | rv = ReadTransaction(trans.get(), &response_data); |
| 1537 | EXPECT_EQ(OK, rv); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1538 | EXPECT_EQ(kHttpData, response_data); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1539 | } |
| 1540 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1541 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 1542 | KeepAliveConnectionNotConnectedOnWrite) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1543 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1544 | KeepAliveConnectionResendRequestTest(&write_failure, NULL); |
| 1545 | } |
| 1546 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1547 | TEST_P(HttpNetworkTransactionTest, KeepAliveConnectionReset) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1548 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1549 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1550 | } |
| 1551 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1552 | TEST_P(HttpNetworkTransactionTest, KeepAliveConnectionEOF) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1553 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1554 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1555 | } |
| 1556 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1557 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1558 | // if the socket was a reused keep alive socket. |
| 1559 | TEST_P(HttpNetworkTransactionTest, KeepAlive408) { |
| 1560 | MockRead read_failure(SYNCHRONOUS, |
| 1561 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1562 | "Connection: Keep-Alive\r\n" |
| 1563 | "Content-Length: 6\r\n\r\n" |
| 1564 | "Pickle"); |
| 1565 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
| 1566 | } |
| 1567 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1568 | TEST_P(HttpNetworkTransactionTest, |
| 1569 | PreconnectErrorNotConnectedOnWrite) { |
| 1570 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1571 | PreconnectErrorResendRequestTest(&write_failure, NULL, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1572 | } |
| 1573 | |
| 1574 | TEST_P(HttpNetworkTransactionTest, PreconnectErrorReset) { |
| 1575 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1576 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1577 | } |
| 1578 | |
| 1579 | TEST_P(HttpNetworkTransactionTest, PreconnectErrorEOF) { |
| 1580 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1581 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1582 | } |
| 1583 | |
| 1584 | TEST_P(HttpNetworkTransactionTest, PreconnectErrorAsyncEOF) { |
| 1585 | MockRead read_failure(ASYNC, OK); // EOF |
| 1586 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1587 | } |
| 1588 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1589 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1590 | // if the socket was a preconnected (UNUSED_IDLE) socket. |
| 1591 | TEST_P(HttpNetworkTransactionTest, RetryOnIdle408) { |
| 1592 | MockRead read_failure(SYNCHRONOUS, |
| 1593 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1594 | "Connection: Keep-Alive\r\n" |
| 1595 | "Content-Length: 6\r\n\r\n" |
| 1596 | "Pickle"); |
| 1597 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
| 1598 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1599 | } |
| 1600 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1601 | TEST_P(HttpNetworkTransactionTest, |
| 1602 | SpdyPreconnectErrorNotConnectedOnWrite) { |
| 1603 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
| 1604 | PreconnectErrorResendRequestTest(&write_failure, NULL, true); |
| 1605 | } |
| 1606 | |
| 1607 | TEST_P(HttpNetworkTransactionTest, SpdyPreconnectErrorReset) { |
| 1608 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
| 1609 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
| 1610 | } |
| 1611 | |
| 1612 | TEST_P(HttpNetworkTransactionTest, SpdyPreconnectErrorEOF) { |
| 1613 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
| 1614 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
| 1615 | } |
| 1616 | |
| 1617 | TEST_P(HttpNetworkTransactionTest, SpdyPreconnectErrorAsyncEOF) { |
| 1618 | MockRead read_failure(ASYNC, OK); // EOF |
| 1619 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1620 | } |
| 1621 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1622 | TEST_P(HttpNetworkTransactionTest, NonKeepAliveConnectionReset) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1623 | HttpRequestInfo request; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1624 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1625 | request.url = GURL("http://www.example.org/"); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1626 | request.load_flags = 0; |
| 1627 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1628 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1629 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1630 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1631 | |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1632 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1633 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1634 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 1635 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1636 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1637 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1638 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1639 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1640 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1641 | TestCompletionCallback callback; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1642 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1643 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1644 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1645 | |
| 1646 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1647 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 1648 | |
| 1649 | IPEndPoint endpoint; |
| 1650 | EXPECT_TRUE(trans->GetRemoteEndpoint(&endpoint)); |
| 1651 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1652 | } |
| 1653 | |
| 1654 | // What do various browsers do when the server closes a non-keepalive |
| 1655 | // connection without sending any response header or body? |
| 1656 | // |
| 1657 | // IE7: error page |
| 1658 | // Safari 3.1.2 (Windows): error page |
| 1659 | // Firefox 3.0.1: blank page |
| 1660 | // Opera 9.52: after five attempts, blank page |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1661 | // Us with WinHTTP: error page (ERR_INVALID_RESPONSE) |
| 1662 | // Us: error page (EMPTY_RESPONSE) |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1663 | TEST_P(HttpNetworkTransactionTest, NonKeepAliveConnectionEOF) { |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1664 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1665 | MockRead(SYNCHRONOUS, OK), // EOF |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1666 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 1667 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1668 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1669 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1670 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1671 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1672 | EXPECT_EQ(ERR_EMPTY_RESPONSE, out.rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1673 | } |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1674 | |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1675 | // Test that network access can be deferred and resumed. |
| 1676 | TEST_P(HttpNetworkTransactionTest, ThrottleBeforeNetworkStart) { |
| 1677 | HttpRequestInfo request; |
| 1678 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1679 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1680 | request.load_flags = 0; |
| 1681 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1682 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1683 | scoped_ptr<HttpTransaction> trans( |
| 1684 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 1685 | |
| 1686 | // Defer on OnBeforeNetworkStart. |
| 1687 | BeforeNetworkStartHandler net_start_handler(true); // defer |
| 1688 | trans->SetBeforeNetworkStartCallback( |
| 1689 | base::Bind(&BeforeNetworkStartHandler::OnBeforeNetworkStart, |
| 1690 | base::Unretained(&net_start_handler))); |
| 1691 | |
| 1692 | MockRead data_reads[] = { |
| 1693 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1694 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1695 | MockRead("hello"), |
| 1696 | MockRead(SYNCHRONOUS, 0), |
| 1697 | }; |
| 1698 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 1699 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 1700 | |
| 1701 | TestCompletionCallback callback; |
| 1702 | |
| 1703 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1704 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1705 | base::MessageLoop::current()->RunUntilIdle(); |
| 1706 | |
| 1707 | // Should have deferred for network start. |
| 1708 | EXPECT_TRUE(net_start_handler.observed_before_network_start()); |
| 1709 | EXPECT_EQ(LOAD_STATE_WAITING_FOR_DELEGATE, trans->GetLoadState()); |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1710 | |
| 1711 | trans->ResumeNetworkStart(); |
| 1712 | rv = callback.WaitForResult(); |
| 1713 | EXPECT_EQ(OK, rv); |
| 1714 | EXPECT_TRUE(trans->GetResponseInfo() != NULL); |
| 1715 | |
| 1716 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
| 1717 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
| 1718 | if (rv == ERR_IO_PENDING) |
| 1719 | rv = callback.WaitForResult(); |
| 1720 | EXPECT_EQ(5, rv); |
| 1721 | trans.reset(); |
| 1722 | } |
| 1723 | |
| 1724 | // Test that network use can be deferred and canceled. |
| 1725 | TEST_P(HttpNetworkTransactionTest, ThrottleAndCancelBeforeNetworkStart) { |
| 1726 | HttpRequestInfo request; |
| 1727 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1728 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1729 | request.load_flags = 0; |
| 1730 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1731 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1732 | scoped_ptr<HttpTransaction> trans( |
| 1733 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 1734 | |
| 1735 | // Defer on OnBeforeNetworkStart. |
| 1736 | BeforeNetworkStartHandler net_start_handler(true); // defer |
| 1737 | trans->SetBeforeNetworkStartCallback( |
| 1738 | base::Bind(&BeforeNetworkStartHandler::OnBeforeNetworkStart, |
| 1739 | base::Unretained(&net_start_handler))); |
| 1740 | |
| 1741 | TestCompletionCallback callback; |
| 1742 | |
| 1743 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1744 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1745 | base::MessageLoop::current()->RunUntilIdle(); |
| 1746 | |
| 1747 | // Should have deferred for network start. |
| 1748 | EXPECT_TRUE(net_start_handler.observed_before_network_start()); |
| 1749 | EXPECT_EQ(LOAD_STATE_WAITING_FOR_DELEGATE, trans->GetLoadState()); |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1750 | } |
| 1751 | |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1752 | // Next 2 cases (KeepAliveEarlyClose and KeepAliveEarlyClose2) are regression |
| 1753 | // tests. There was a bug causing HttpNetworkTransaction to hang in the |
| 1754 | // destructor in such situations. |
| 1755 | // See http://crbug.com/154712 and http://crbug.com/156609. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1756 | TEST_P(HttpNetworkTransactionTest, KeepAliveEarlyClose) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1757 | HttpRequestInfo request; |
| 1758 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1759 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1760 | request.load_flags = 0; |
| 1761 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1762 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1763 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1764 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1765 | |
| 1766 | MockRead data_reads[] = { |
| 1767 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1768 | MockRead("Connection: keep-alive\r\n"), |
| 1769 | MockRead("Content-Length: 100\r\n\r\n"), |
| 1770 | MockRead("hello"), |
| 1771 | MockRead(SYNCHRONOUS, 0), |
| 1772 | }; |
| 1773 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1774 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1775 | |
| 1776 | TestCompletionCallback callback; |
| 1777 | |
| 1778 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1779 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1780 | |
| 1781 | rv = callback.WaitForResult(); |
| 1782 | EXPECT_EQ(OK, rv); |
| 1783 | |
| 1784 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1785 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1786 | if (rv == ERR_IO_PENDING) |
| 1787 | rv = callback.WaitForResult(); |
| 1788 | EXPECT_EQ(5, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1789 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1790 | EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, rv); |
| 1791 | |
| 1792 | trans.reset(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 1793 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1794 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 1795 | } |
| 1796 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1797 | TEST_P(HttpNetworkTransactionTest, KeepAliveEarlyClose2) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1798 | HttpRequestInfo request; |
| 1799 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1800 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1801 | request.load_flags = 0; |
| 1802 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1803 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1804 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1805 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1806 | |
| 1807 | MockRead data_reads[] = { |
| 1808 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1809 | MockRead("Connection: keep-alive\r\n"), |
| 1810 | MockRead("Content-Length: 100\r\n\r\n"), |
| 1811 | MockRead(SYNCHRONOUS, 0), |
| 1812 | }; |
| 1813 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1814 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1815 | |
| 1816 | TestCompletionCallback callback; |
| 1817 | |
| 1818 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1819 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1820 | |
| 1821 | rv = callback.WaitForResult(); |
| 1822 | EXPECT_EQ(OK, rv); |
| 1823 | |
| 1824 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1825 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1826 | if (rv == ERR_IO_PENDING) |
| 1827 | rv = callback.WaitForResult(); |
| 1828 | EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, rv); |
| 1829 | |
| 1830 | trans.reset(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 1831 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1832 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 1833 | } |
| 1834 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1835 | // Test that we correctly reuse a keep-alive connection after not explicitly |
| 1836 | // reading the body. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1837 | TEST_P(HttpNetworkTransactionTest, KeepAliveAfterUnreadBody) { |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1838 | HttpRequestInfo request; |
| 1839 | request.method = "GET"; |
| 1840 | request.url = GURL("http://www.foo.com/"); |
| 1841 | request.load_flags = 0; |
| 1842 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1843 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1844 | session_deps_.net_log = &net_log; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1845 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1846 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1847 | const char* request_data = |
| 1848 | "GET / HTTP/1.1\r\n" |
| 1849 | "Host: www.foo.com\r\n" |
| 1850 | "Connection: keep-alive\r\n\r\n"; |
| 1851 | MockWrite data_writes[] = { |
| 1852 | MockWrite(ASYNC, 0, request_data), MockWrite(ASYNC, 2, request_data), |
| 1853 | MockWrite(ASYNC, 4, request_data), MockWrite(ASYNC, 6, request_data), |
| 1854 | MockWrite(ASYNC, 8, request_data), MockWrite(ASYNC, 10, request_data), |
| 1855 | MockWrite(ASYNC, 12, request_data), MockWrite(ASYNC, 14, request_data), |
| 1856 | MockWrite(ASYNC, 17, request_data), MockWrite(ASYNC, 20, request_data), |
| 1857 | }; |
| 1858 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1859 | // Note that because all these reads happen in the same |
| 1860 | // StaticSocketDataProvider, it shows that the same socket is being reused for |
| 1861 | // all transactions. |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1862 | MockRead data_reads[] = { |
| 1863 | MockRead(ASYNC, 1, "HTTP/1.1 204 No Content\r\n\r\n"), |
| 1864 | MockRead(ASYNC, 3, "HTTP/1.1 205 Reset Content\r\n\r\n"), |
| 1865 | MockRead(ASYNC, 5, "HTTP/1.1 304 Not Modified\r\n\r\n"), |
| 1866 | MockRead(ASYNC, 7, |
| 1867 | "HTTP/1.1 302 Found\r\n" |
| 1868 | "Content-Length: 0\r\n\r\n"), |
| 1869 | MockRead(ASYNC, 9, |
| 1870 | "HTTP/1.1 302 Found\r\n" |
| 1871 | "Content-Length: 5\r\n\r\n" |
| 1872 | "hello"), |
| 1873 | MockRead(ASYNC, 11, |
| 1874 | "HTTP/1.1 301 Moved Permanently\r\n" |
| 1875 | "Content-Length: 0\r\n\r\n"), |
| 1876 | MockRead(ASYNC, 13, |
| 1877 | "HTTP/1.1 301 Moved Permanently\r\n" |
| 1878 | "Content-Length: 5\r\n\r\n" |
| 1879 | "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1880 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1881 | // In the next two rounds, IsConnectedAndIdle returns false, due to |
| 1882 | // the set_busy_before_sync_reads(true) call, while the |
| 1883 | // HttpNetworkTransaction is being shut down, but the socket is still |
| 1884 | // reuseable. See http://crbug.com/544255. |
| 1885 | MockRead(ASYNC, 15, |
| 1886 | "HTTP/1.1 200 Hunky-Dory\r\n" |
| 1887 | "Content-Length: 5\r\n\r\n"), |
| 1888 | MockRead(SYNCHRONOUS, 16, "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1889 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1890 | MockRead(ASYNC, 18, |
| 1891 | "HTTP/1.1 200 Hunky-Dory\r\n" |
| 1892 | "Content-Length: 5\r\n\r\n" |
| 1893 | "he"), |
| 1894 | MockRead(SYNCHRONOUS, 19, "llo"), |
| 1895 | |
| 1896 | // The body of the final request is actually read. |
| 1897 | MockRead(ASYNC, 21, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1898 | MockRead(ASYNC, 22, "hello"), |
| 1899 | }; |
| 1900 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 1901 | arraysize(data_writes)); |
| 1902 | data.set_busy_before_sync_reads(true); |
| 1903 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 1904 | |
| 1905 | const int kNumUnreadBodies = arraysize(data_writes) - 1; |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1906 | std::string response_lines[kNumUnreadBodies]; |
| 1907 | |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 1908 | uint32_t first_socket_log_id = NetLog::Source::kInvalidId; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1909 | for (size_t i = 0; i < kNumUnreadBodies; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1910 | TestCompletionCallback callback; |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1911 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1912 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1913 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1914 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1915 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1916 | EXPECT_EQ(OK, callback.GetResult(rv)); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1917 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1918 | LoadTimingInfo load_timing_info; |
| 1919 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 1920 | if (i == 0) { |
| 1921 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1922 | first_socket_log_id = load_timing_info.socket_log_id; |
| 1923 | } else { |
| 1924 | TestLoadTimingReused(load_timing_info); |
| 1925 | EXPECT_EQ(first_socket_log_id, load_timing_info.socket_log_id); |
| 1926 | } |
| 1927 | |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1928 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1929 | ASSERT_TRUE(response); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1930 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1931 | ASSERT_TRUE(response->headers); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1932 | response_lines[i] = response->headers->GetStatusLine(); |
| 1933 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1934 | // Delete the transaction without reading the response bodies. Then spin |
| 1935 | // the message loop, so the response bodies are drained. |
| 1936 | trans.reset(); |
| 1937 | base::RunLoop().RunUntilIdle(); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1938 | } |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1939 | |
| 1940 | const char* const kStatusLines[] = { |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1941 | "HTTP/1.1 204 No Content", |
| 1942 | "HTTP/1.1 205 Reset Content", |
| 1943 | "HTTP/1.1 304 Not Modified", |
| 1944 | "HTTP/1.1 302 Found", |
| 1945 | "HTTP/1.1 302 Found", |
| 1946 | "HTTP/1.1 301 Moved Permanently", |
| 1947 | "HTTP/1.1 301 Moved Permanently", |
| 1948 | "HTTP/1.1 200 Hunky-Dory", |
| 1949 | "HTTP/1.1 200 Hunky-Dory", |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1950 | }; |
| 1951 | |
mostynb | 91e0da98 | 2015-01-20 19:17:27 | [diff] [blame] | 1952 | static_assert(kNumUnreadBodies == arraysize(kStatusLines), |
| 1953 | "forgot to update kStatusLines"); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1954 | |
| 1955 | for (int i = 0; i < kNumUnreadBodies; ++i) |
| 1956 | EXPECT_EQ(kStatusLines[i], response_lines[i]); |
| 1957 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1958 | TestCompletionCallback callback; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1959 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1960 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1961 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1962 | EXPECT_EQ(OK, callback.GetResult(rv)); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1963 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1964 | ASSERT_TRUE(response); |
| 1965 | ASSERT_TRUE(response->headers); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1966 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1967 | std::string response_data; |
| 1968 | rv = ReadTransaction(trans.get(), &response_data); |
| 1969 | EXPECT_EQ(OK, rv); |
| 1970 | EXPECT_EQ("hello", response_data); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1971 | } |
| 1972 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1973 | // Test the request-challenge-retry sequence for basic auth. |
| 1974 | // (basic auth is the easiest to mock, because it has no randomness). |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1975 | TEST_P(HttpNetworkTransactionTest, BasicAuth) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1976 | HttpRequestInfo request; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1977 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1978 | request.url = GURL("http://www.example.org/"); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1979 | request.load_flags = 0; |
| 1980 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1981 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1982 | session_deps_.net_log = &log; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1983 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1984 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1985 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1986 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 1987 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1988 | MockWrite( |
| 1989 | "GET / HTTP/1.1\r\n" |
| 1990 | "Host: www.example.org\r\n" |
| 1991 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 1992 | }; |
| 1993 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1994 | MockRead data_reads1[] = { |
| 1995 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 1996 | // Give a couple authenticate options (only the middle one is actually |
| 1997 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 1998 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1999 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2000 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2001 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2002 | // Large content-length -- won't matter, as connection will be reset. |
| 2003 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2004 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2005 | }; |
| 2006 | |
| 2007 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2008 | // be issuing -- the final header line contains the credentials. |
| 2009 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2010 | MockWrite( |
| 2011 | "GET / HTTP/1.1\r\n" |
| 2012 | "Host: www.example.org\r\n" |
| 2013 | "Connection: keep-alive\r\n" |
| 2014 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2015 | }; |
| 2016 | |
| 2017 | // Lastly, the server responds with the actual content. |
| 2018 | MockRead data_reads2[] = { |
| 2019 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2020 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2021 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2022 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2023 | }; |
| 2024 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2025 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2026 | data_writes1, arraysize(data_writes1)); |
| 2027 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2028 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2029 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2030 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2031 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2032 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2033 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2034 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2035 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2036 | |
| 2037 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2038 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2039 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2040 | LoadTimingInfo load_timing_info1; |
| 2041 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info1)); |
| 2042 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2043 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2044 | int64_t writes_size1 = CountWriteBytes(data_writes1, arraysize(data_writes1)); |
| 2045 | EXPECT_EQ(writes_size1, trans->GetTotalSentBytes()); |
| 2046 | int64_t reads_size1 = CountReadBytes(data_reads1, arraysize(data_reads1)); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2047 | EXPECT_EQ(reads_size1, trans->GetTotalReceivedBytes()); |
| 2048 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2049 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2050 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2051 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2052 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2053 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2054 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2055 | rv = trans->RestartWithAuth( |
| 2056 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2057 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2058 | |
| 2059 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2060 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2061 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2062 | LoadTimingInfo load_timing_info2; |
| 2063 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info2)); |
| 2064 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2065 | // The load timing after restart should have a new socket ID, and times after |
| 2066 | // those of the first load timing. |
| 2067 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2068 | load_timing_info2.connect_timing.connect_start); |
| 2069 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2070 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2071 | int64_t writes_size2 = CountWriteBytes(data_writes2, arraysize(data_writes2)); |
| 2072 | EXPECT_EQ(writes_size1 + writes_size2, trans->GetTotalSentBytes()); |
| 2073 | int64_t reads_size2 = CountReadBytes(data_reads2, arraysize(data_reads2)); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2074 | EXPECT_EQ(reads_size1 + reads_size2, trans->GetTotalReceivedBytes()); |
| 2075 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2076 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2077 | ASSERT_TRUE(response != NULL); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2078 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 2079 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2080 | } |
| 2081 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2082 | // Test the request-challenge-retry sequence for basic auth. |
| 2083 | // (basic auth is the easiest to mock, because it has no randomness). |
| 2084 | TEST_P(HttpNetworkTransactionTest, BasicAuthWithAddressChange) { |
| 2085 | HttpRequestInfo request; |
| 2086 | request.method = "GET"; |
| 2087 | request.url = GURL("http://www.example.org/"); |
| 2088 | request.load_flags = 0; |
| 2089 | |
| 2090 | TestNetLog log; |
| 2091 | MockHostResolver* resolver = new MockHostResolver(); |
| 2092 | session_deps_.net_log = &log; |
| 2093 | session_deps_.host_resolver.reset(resolver); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 2094 | scoped_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2095 | scoped_ptr<HttpTransaction> trans( |
| 2096 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 2097 | |
| 2098 | resolver->rules()->ClearRules(); |
| 2099 | resolver->rules()->AddRule("www.example.org", "127.0.0.1"); |
| 2100 | |
| 2101 | MockWrite data_writes1[] = { |
| 2102 | MockWrite("GET / HTTP/1.1\r\n" |
| 2103 | "Host: www.example.org\r\n" |
| 2104 | "Connection: keep-alive\r\n\r\n"), |
| 2105 | }; |
| 2106 | |
| 2107 | MockRead data_reads1[] = { |
| 2108 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2109 | // Give a couple authenticate options (only the middle one is actually |
| 2110 | // supported). |
| 2111 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 2112 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2113 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2114 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2115 | // Large content-length -- won't matter, as connection will be reset. |
| 2116 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 2117 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 2118 | }; |
| 2119 | |
| 2120 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2121 | // be issuing -- the final header line contains the credentials. |
| 2122 | MockWrite data_writes2[] = { |
| 2123 | MockWrite("GET / HTTP/1.1\r\n" |
| 2124 | "Host: www.example.org\r\n" |
| 2125 | "Connection: keep-alive\r\n" |
| 2126 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2127 | }; |
| 2128 | |
| 2129 | // Lastly, the server responds with the actual content. |
| 2130 | MockRead data_reads2[] = { |
| 2131 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2132 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2133 | MockRead("Content-Length: 100\r\n\r\n"), MockRead(SYNCHRONOUS, OK), |
| 2134 | }; |
| 2135 | |
| 2136 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2137 | data_writes1, arraysize(data_writes1)); |
| 2138 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2139 | data_writes2, arraysize(data_writes2)); |
| 2140 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2141 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2142 | |
| 2143 | TestCompletionCallback callback1; |
| 2144 | |
| 2145 | EXPECT_EQ(OK, callback1.GetResult(trans->Start(&request, callback1.callback(), |
| 2146 | BoundNetLog()))); |
| 2147 | |
| 2148 | LoadTimingInfo load_timing_info1; |
| 2149 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info1)); |
| 2150 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2151 | |
| 2152 | int64_t writes_size1 = CountWriteBytes(data_writes1, arraysize(data_writes1)); |
| 2153 | EXPECT_EQ(writes_size1, trans->GetTotalSentBytes()); |
| 2154 | int64_t reads_size1 = CountReadBytes(data_reads1, arraysize(data_reads1)); |
| 2155 | EXPECT_EQ(reads_size1, trans->GetTotalReceivedBytes()); |
| 2156 | |
| 2157 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 2158 | ASSERT_TRUE(response); |
| 2159 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 2160 | |
| 2161 | IPEndPoint endpoint; |
| 2162 | EXPECT_TRUE(trans->GetRemoteEndpoint(&endpoint)); |
| 2163 | ASSERT_FALSE(endpoint.address().empty()); |
| 2164 | EXPECT_EQ("127.0.0.1:80", endpoint.ToString()); |
| 2165 | |
| 2166 | resolver->rules()->ClearRules(); |
| 2167 | resolver->rules()->AddRule("www.example.org", "127.0.0.2"); |
| 2168 | |
| 2169 | TestCompletionCallback callback2; |
| 2170 | |
| 2171 | EXPECT_EQ(OK, callback2.GetResult(trans->RestartWithAuth( |
| 2172 | AuthCredentials(kFoo, kBar), callback2.callback()))); |
| 2173 | |
| 2174 | LoadTimingInfo load_timing_info2; |
| 2175 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info2)); |
| 2176 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2177 | // The load timing after restart should have a new socket ID, and times after |
| 2178 | // those of the first load timing. |
| 2179 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2180 | load_timing_info2.connect_timing.connect_start); |
| 2181 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2182 | |
| 2183 | int64_t writes_size2 = CountWriteBytes(data_writes2, arraysize(data_writes2)); |
| 2184 | EXPECT_EQ(writes_size1 + writes_size2, trans->GetTotalSentBytes()); |
| 2185 | int64_t reads_size2 = CountReadBytes(data_reads2, arraysize(data_reads2)); |
| 2186 | EXPECT_EQ(reads_size1 + reads_size2, trans->GetTotalReceivedBytes()); |
| 2187 | |
| 2188 | response = trans->GetResponseInfo(); |
| 2189 | ASSERT_TRUE(response); |
| 2190 | EXPECT_FALSE(response->auth_challenge.get()); |
| 2191 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 2192 | |
| 2193 | EXPECT_TRUE(trans->GetRemoteEndpoint(&endpoint)); |
| 2194 | ASSERT_FALSE(endpoint.address().empty()); |
| 2195 | EXPECT_EQ("127.0.0.2:80", endpoint.ToString()); |
| 2196 | } |
| 2197 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2198 | TEST_P(HttpNetworkTransactionTest, DoNotSendAuth) { |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2199 | HttpRequestInfo request; |
| 2200 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2201 | request.url = GURL("http://www.example.org/"); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2202 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2203 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 2204 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2205 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 2206 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2207 | |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2208 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2209 | MockWrite( |
| 2210 | "GET / HTTP/1.1\r\n" |
| 2211 | "Host: www.example.org\r\n" |
| 2212 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2213 | }; |
| 2214 | |
| 2215 | MockRead data_reads[] = { |
| 2216 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2217 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2218 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2219 | // Large content-length -- won't matter, as connection will be reset. |
| 2220 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2221 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2222 | }; |
| 2223 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2224 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 2225 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2226 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2227 | TestCompletionCallback callback; |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2228 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2229 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2230 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2231 | |
| 2232 | rv = callback.WaitForResult(); |
| 2233 | EXPECT_EQ(0, rv); |
| 2234 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2235 | int64_t writes_size = CountWriteBytes(data_writes, arraysize(data_writes)); |
| 2236 | EXPECT_EQ(writes_size, trans->GetTotalSentBytes()); |
| 2237 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2238 | EXPECT_EQ(reads_size, trans->GetTotalReceivedBytes()); |
| 2239 | |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2240 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2241 | ASSERT_TRUE(response != NULL); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2242 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 2243 | } |
| 2244 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2245 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2246 | // connection. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2247 | TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAlive) { |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2248 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 2249 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 2250 | // reused. See http://crbug.com/544255. |
| 2251 | for (int i = 0; i < 2; ++i) { |
| 2252 | HttpRequestInfo request; |
| 2253 | request.method = "GET"; |
| 2254 | request.url = GURL("http://www.example.org/"); |
| 2255 | request.load_flags = 0; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2256 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2257 | TestNetLog log; |
| 2258 | session_deps_.net_log = &log; |
| 2259 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2260 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2261 | MockWrite data_writes[] = { |
| 2262 | MockWrite(ASYNC, 0, |
| 2263 | "GET / HTTP/1.1\r\n" |
| 2264 | "Host: www.example.org\r\n" |
| 2265 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2266 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2267 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2268 | // be issuing -- the final header line contains the credentials. |
| 2269 | MockWrite(ASYNC, 6, |
| 2270 | "GET / HTTP/1.1\r\n" |
| 2271 | "Host: www.example.org\r\n" |
| 2272 | "Connection: keep-alive\r\n" |
| 2273 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2274 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2275 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2276 | MockRead data_reads[] = { |
| 2277 | MockRead(ASYNC, 1, "HTTP/1.1 401 Unauthorized\r\n"), |
| 2278 | MockRead(ASYNC, 2, "WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2279 | MockRead(ASYNC, 3, "Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2280 | MockRead(ASYNC, 4, "Content-Length: 14\r\n\r\n"), |
| 2281 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 5, "Unauthorized\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2282 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2283 | // Lastly, the server responds with the actual content. |
| 2284 | MockRead(ASYNC, 7, "HTTP/1.1 200 OK\r\n"), |
| 2285 | MockRead(ASYNC, 8, "Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2286 | MockRead(ASYNC, 9, "Content-Length: 5\r\n\r\n"), |
| 2287 | MockRead(ASYNC, 10, "Hello"), |
| 2288 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2289 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2290 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 2291 | arraysize(data_writes)); |
| 2292 | data.set_busy_before_sync_reads(true); |
| 2293 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2294 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2295 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2296 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2297 | scoped_ptr<HttpTransaction> trans( |
| 2298 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 2299 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
| 2300 | ASSERT_EQ(OK, callback1.GetResult(rv)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2301 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2302 | LoadTimingInfo load_timing_info1; |
| 2303 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info1)); |
| 2304 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2305 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2306 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 2307 | ASSERT_TRUE(response); |
| 2308 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2309 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2310 | TestCompletionCallback callback2; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2311 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2312 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 2313 | callback2.callback()); |
| 2314 | ASSERT_EQ(OK, callback2.GetResult(rv)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2315 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2316 | LoadTimingInfo load_timing_info2; |
| 2317 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info2)); |
| 2318 | TestLoadTimingReused(load_timing_info2); |
| 2319 | // The load timing after restart should have the same socket ID, and times |
| 2320 | // those of the first load timing. |
| 2321 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2322 | load_timing_info2.send_start); |
| 2323 | 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] | 2324 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2325 | response = trans->GetResponseInfo(); |
| 2326 | ASSERT_TRUE(response); |
| 2327 | EXPECT_FALSE(response->auth_challenge); |
| 2328 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2329 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2330 | std::string response_data; |
| 2331 | EXPECT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2332 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2333 | int64_t writes_size = CountWriteBytes(data_writes, arraysize(data_writes)); |
| 2334 | EXPECT_EQ(writes_size, trans->GetTotalSentBytes()); |
| 2335 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 2336 | EXPECT_EQ(reads_size, trans->GetTotalReceivedBytes()); |
| 2337 | } |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2338 | } |
| 2339 | |
| 2340 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2341 | // connection and with no response body to drain. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2342 | TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAliveNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2343 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2344 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2345 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2346 | request.load_flags = 0; |
| 2347 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 2348 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2349 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2350 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2351 | MockWrite( |
| 2352 | "GET / HTTP/1.1\r\n" |
| 2353 | "Host: www.example.org\r\n" |
| 2354 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2355 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2356 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2357 | // be issuing -- the final header line contains the credentials. |
| 2358 | MockWrite( |
| 2359 | "GET / HTTP/1.1\r\n" |
| 2360 | "Host: www.example.org\r\n" |
| 2361 | "Connection: keep-alive\r\n" |
| 2362 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2363 | }; |
| 2364 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2365 | MockRead data_reads1[] = { |
| 2366 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2367 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2368 | MockRead("Content-Length: 0\r\n\r\n"), // No response body. |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2369 | |
| 2370 | // Lastly, the server responds with the actual content. |
| 2371 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2372 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2373 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2374 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2375 | }; |
| 2376 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2377 | // An incorrect reconnect would cause this to be read. |
| 2378 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2379 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2380 | }; |
| 2381 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2382 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2383 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2384 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2385 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2386 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2387 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2388 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2389 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2390 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2391 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2392 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2393 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2394 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2395 | |
| 2396 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2397 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2398 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2399 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2400 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2401 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2402 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2403 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2404 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2405 | rv = trans->RestartWithAuth( |
| 2406 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2407 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2408 | |
| 2409 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2410 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2411 | |
| 2412 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2413 | ASSERT_TRUE(response != NULL); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2414 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2415 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2416 | } |
| 2417 | |
| 2418 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2419 | // connection and with a large response body to drain. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2420 | TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAliveLargeBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2421 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2422 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2423 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2424 | request.load_flags = 0; |
| 2425 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 2426 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2427 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2428 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2429 | MockWrite( |
| 2430 | "GET / HTTP/1.1\r\n" |
| 2431 | "Host: www.example.org\r\n" |
| 2432 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2433 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2434 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2435 | // be issuing -- the final header line contains the credentials. |
| 2436 | MockWrite( |
| 2437 | "GET / HTTP/1.1\r\n" |
| 2438 | "Host: www.example.org\r\n" |
| 2439 | "Connection: keep-alive\r\n" |
| 2440 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2441 | }; |
| 2442 | |
| 2443 | // Respond with 5 kb of response body. |
| 2444 | std::string large_body_string("Unauthorized"); |
| 2445 | large_body_string.append(5 * 1024, ' '); |
| 2446 | large_body_string.append("\r\n"); |
| 2447 | |
| 2448 | MockRead data_reads1[] = { |
| 2449 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2450 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2451 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2452 | // 5134 = 12 + 5 * 1024 + 2 |
| 2453 | MockRead("Content-Length: 5134\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2454 | MockRead(ASYNC, large_body_string.data(), large_body_string.size()), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2455 | |
| 2456 | // Lastly, the server responds with the actual content. |
| 2457 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2458 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2459 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2460 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2461 | }; |
| 2462 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2463 | // An incorrect reconnect would cause this to be read. |
| 2464 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2465 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2466 | }; |
| 2467 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2468 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2469 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2470 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2471 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2472 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2473 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2474 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2475 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2476 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2477 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2478 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2479 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2480 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2481 | |
| 2482 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2483 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2484 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2485 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2486 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2487 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2488 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2489 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2490 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2491 | rv = trans->RestartWithAuth( |
| 2492 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2493 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2494 | |
| 2495 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2496 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2497 | |
| 2498 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2499 | ASSERT_TRUE(response != NULL); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2500 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2501 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2502 | } |
| 2503 | |
| 2504 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2505 | // connection, but the server gets impatient and closes the connection. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2506 | TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAliveImpatientServer) { |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2507 | HttpRequestInfo request; |
| 2508 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2509 | request.url = GURL("http://www.example.org/"); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2510 | request.load_flags = 0; |
| 2511 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 2512 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2513 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2514 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2515 | MockWrite( |
| 2516 | "GET / HTTP/1.1\r\n" |
| 2517 | "Host: www.example.org\r\n" |
| 2518 | "Connection: keep-alive\r\n\r\n"), |
| 2519 | // This simulates the seemingly successful write to a closed connection |
| 2520 | // if the bug is not fixed. |
| 2521 | MockWrite( |
| 2522 | "GET / HTTP/1.1\r\n" |
| 2523 | "Host: www.example.org\r\n" |
| 2524 | "Connection: keep-alive\r\n" |
| 2525 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2526 | }; |
| 2527 | |
| 2528 | MockRead data_reads1[] = { |
| 2529 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2530 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2531 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2532 | MockRead("Content-Length: 14\r\n\r\n"), |
| 2533 | // Tell MockTCPClientSocket to simulate the server closing the connection. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2534 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2535 | MockRead("Unauthorized\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2536 | MockRead(SYNCHRONOUS, OK), // The server closes the connection. |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2537 | }; |
| 2538 | |
| 2539 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2540 | // be issuing -- the final header line contains the credentials. |
| 2541 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2542 | MockWrite( |
| 2543 | "GET / HTTP/1.1\r\n" |
| 2544 | "Host: www.example.org\r\n" |
| 2545 | "Connection: keep-alive\r\n" |
| 2546 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2547 | }; |
| 2548 | |
| 2549 | // Lastly, the server responds with the actual content. |
| 2550 | MockRead data_reads2[] = { |
| 2551 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2552 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2553 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2554 | MockRead("hello"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2555 | }; |
| 2556 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2557 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2558 | data_writes1, arraysize(data_writes1)); |
| 2559 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2560 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2561 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2562 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2563 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2564 | TestCompletionCallback callback1; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2565 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2566 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2567 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2568 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2569 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2570 | |
| 2571 | rv = callback1.WaitForResult(); |
| 2572 | EXPECT_EQ(OK, rv); |
| 2573 | |
| 2574 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2575 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2576 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2577 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2578 | TestCompletionCallback callback2; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2579 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2580 | rv = trans->RestartWithAuth( |
| 2581 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2582 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2583 | |
| 2584 | rv = callback2.WaitForResult(); |
| 2585 | EXPECT_EQ(OK, rv); |
| 2586 | |
| 2587 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2588 | ASSERT_TRUE(response != NULL); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2589 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2590 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2591 | } |
| 2592 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2593 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 2594 | // that requires a restart when setting up an SSL tunnel. |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2595 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp10) { |
| 2596 | HttpRequestInfo request; |
| 2597 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2598 | request.url = GURL("https://www.example.org/"); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2599 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2600 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2601 | |
| 2602 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 2603 | session_deps_.proxy_service = |
| 2604 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2605 | BoundTestNetLog log; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2606 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 2607 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2608 | |
| 2609 | // Since we have proxy, should try to establish tunnel. |
| 2610 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2611 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 2612 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2613 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2614 | }; |
| 2615 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2616 | // The proxy responds to the connect with a 407, using a non-persistent |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2617 | // connection. |
| 2618 | MockRead data_reads1[] = { |
| 2619 | // No credentials. |
| 2620 | MockRead("HTTP/1.0 407 Proxy Authentication Required\r\n"), |
| 2621 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n\r\n"), |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2622 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2623 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2624 | // Since the first connection couldn't be reused, need to establish another |
| 2625 | // once given credentials. |
| 2626 | MockWrite data_writes2[] = { |
| 2627 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2628 | // be issuing -- the final header line contains the credentials. |
| 2629 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 2630 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2631 | "Proxy-Connection: keep-alive\r\n" |
| 2632 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2633 | |
| 2634 | MockWrite("GET / HTTP/1.1\r\n" |
| 2635 | "Host: www.example.org\r\n" |
| 2636 | "Connection: keep-alive\r\n\r\n"), |
| 2637 | }; |
| 2638 | |
| 2639 | MockRead data_reads2[] = { |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2640 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 2641 | |
| 2642 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2643 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2644 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2645 | MockRead(SYNCHRONOUS, "hello"), |
| 2646 | }; |
| 2647 | |
| 2648 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2649 | data_writes1, arraysize(data_writes1)); |
| 2650 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2651 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2652 | data_writes2, arraysize(data_writes2)); |
| 2653 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2654 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 2655 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 2656 | |
| 2657 | TestCompletionCallback callback1; |
| 2658 | |
| 2659 | scoped_ptr<HttpTransaction> trans( |
| 2660 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 2661 | |
| 2662 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 2663 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2664 | |
| 2665 | rv = callback1.WaitForResult(); |
| 2666 | EXPECT_EQ(OK, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 2667 | TestNetLogEntry::List entries; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2668 | log.GetEntries(&entries); |
| 2669 | size_t pos = ExpectLogContainsSomewhere( |
| 2670 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 2671 | NetLog::PHASE_NONE); |
| 2672 | ExpectLogContainsSomewhere( |
| 2673 | entries, pos, NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 2674 | NetLog::PHASE_NONE); |
| 2675 | |
| 2676 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 2677 | ASSERT_TRUE(response != NULL); |
| 2678 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
| 2679 | ASSERT_FALSE(response->headers.get() == NULL); |
| 2680 | EXPECT_EQ(407, response->headers->response_code()); |
| 2681 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 2682 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 2683 | |
| 2684 | LoadTimingInfo load_timing_info; |
| 2685 | // CONNECT requests and responses are handled at the connect job level, so |
| 2686 | // the transaction does not yet have a connection. |
| 2687 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2688 | |
| 2689 | TestCompletionCallback callback2; |
| 2690 | |
| 2691 | rv = |
| 2692 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
| 2693 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2694 | |
| 2695 | rv = callback2.WaitForResult(); |
| 2696 | EXPECT_EQ(OK, rv); |
| 2697 | |
| 2698 | response = trans->GetResponseInfo(); |
| 2699 | ASSERT_TRUE(response != NULL); |
| 2700 | |
| 2701 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2702 | EXPECT_EQ(200, response->headers->response_code()); |
| 2703 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 2704 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 2705 | |
| 2706 | // The password prompt info should not be set. |
| 2707 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 2708 | |
| 2709 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2710 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 2711 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 2712 | |
| 2713 | trans.reset(); |
| 2714 | session->CloseAllConnections(); |
| 2715 | } |
| 2716 | |
| 2717 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 2718 | // that requires a restart when setting up an SSL tunnel. |
| 2719 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp11) { |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2720 | HttpRequestInfo request; |
| 2721 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2722 | request.url = GURL("https://www.example.org/"); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2723 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2724 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2725 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2726 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 2727 | session_deps_.proxy_service = |
| 2728 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2729 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2730 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 2731 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2732 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2733 | // Since we have proxy, should try to establish tunnel. |
| 2734 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2735 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 2736 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2737 | "Proxy-Connection: keep-alive\r\n\r\n"), |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 2738 | }; |
| 2739 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2740 | // The proxy responds to the connect with a 407, using a non-persistent |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 2741 | // connection. |
| 2742 | MockRead data_reads1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2743 | // No credentials. |
| 2744 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 2745 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2746 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 2747 | }; |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 2748 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2749 | MockWrite data_writes2[] = { |
| 2750 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2751 | // be issuing -- the final header line contains the credentials. |
| 2752 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 2753 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2754 | "Proxy-Connection: keep-alive\r\n" |
| 2755 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 2756 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2757 | MockWrite("GET / HTTP/1.1\r\n" |
| 2758 | "Host: www.example.org\r\n" |
| 2759 | "Connection: keep-alive\r\n\r\n"), |
| 2760 | }; |
| 2761 | |
| 2762 | MockRead data_reads2[] = { |
| 2763 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 2764 | |
| 2765 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2766 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2767 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2768 | MockRead(SYNCHRONOUS, "hello"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2769 | }; |
| 2770 | |
| 2771 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2772 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2773 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2774 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2775 | data_writes2, arraysize(data_writes2)); |
| 2776 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2777 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2778 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2779 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2780 | TestCompletionCallback callback1; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2781 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2782 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2783 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2784 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2785 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2786 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2787 | |
| 2788 | rv = callback1.WaitForResult(); |
| 2789 | EXPECT_EQ(OK, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 2790 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2791 | log.GetEntries(&entries); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2792 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2793 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2794 | NetLog::PHASE_NONE); |
| 2795 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2796 | entries, pos, |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2797 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 2798 | NetLog::PHASE_NONE); |
| 2799 | |
| 2800 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2801 | ASSERT_TRUE(response != NULL); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2802 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2803 | ASSERT_FALSE(response->headers.get() == NULL); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2804 | EXPECT_EQ(407, response->headers->response_code()); |
| 2805 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2806 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2807 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2808 | LoadTimingInfo load_timing_info; |
| 2809 | // CONNECT requests and responses are handled at the connect job level, so |
| 2810 | // the transaction does not yet have a connection. |
| 2811 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2812 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2813 | TestCompletionCallback callback2; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2814 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2815 | rv = trans->RestartWithAuth( |
| 2816 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2817 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2818 | |
| 2819 | rv = callback2.WaitForResult(); |
| 2820 | EXPECT_EQ(OK, rv); |
| 2821 | |
| 2822 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2823 | ASSERT_TRUE(response != NULL); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2824 | |
| 2825 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2826 | EXPECT_EQ(200, response->headers->response_code()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2827 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2828 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 2829 | |
| 2830 | // The password prompt info should not be set. |
| 2831 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2832 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2833 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2834 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 2835 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 2836 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2837 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 2838 | session->CloseAllConnections(); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2839 | } |
| 2840 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2841 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2842 | // proxy connection with HTTP/1.0 responses, when setting up an SSL tunnel. |
| 2843 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp10) { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 2844 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 2845 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 2846 | // reused. See http://crbug.com/544255. |
| 2847 | for (int i = 0; i < 2; ++i) { |
| 2848 | HttpRequestInfo request; |
| 2849 | request.method = "GET"; |
| 2850 | request.url = GURL("https://www.example.org/"); |
| 2851 | // Ensure that proxy authentication is attempted even |
| 2852 | // when the no authentication data flag is set. |
| 2853 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2854 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 2855 | // Configure against proxy server "myproxy:70". |
| 2856 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
| 2857 | BoundTestNetLog log; |
| 2858 | session_deps_.net_log = log.bound().net_log(); |
| 2859 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2860 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 2861 | scoped_ptr<HttpTransaction> trans( |
| 2862 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2863 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 2864 | // Since we have proxy, should try to establish tunnel. |
| 2865 | MockWrite data_writes1[] = { |
| 2866 | MockWrite(ASYNC, 0, |
| 2867 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2868 | "Host: www.example.org:443\r\n" |
| 2869 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2870 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 2871 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2872 | // be issuing -- the final header line contains the credentials. |
| 2873 | MockWrite(ASYNC, 3, |
| 2874 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2875 | "Host: www.example.org:443\r\n" |
| 2876 | "Proxy-Connection: keep-alive\r\n" |
| 2877 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 2878 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2879 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 2880 | // The proxy responds to the connect with a 407, using a persistent |
| 2881 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 2882 | MockRead data_reads1[] = { |
| 2883 | // No credentials. |
| 2884 | MockRead(ASYNC, 1, |
| 2885 | "HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 2886 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 2887 | "Proxy-Connection: keep-alive\r\n" |
| 2888 | "Content-Length: 10\r\n\r\n"), |
| 2889 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 2, "0123456789"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2890 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 2891 | // Wrong credentials (wrong password). |
| 2892 | MockRead(ASYNC, 4, |
| 2893 | "HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 2894 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 2895 | "Proxy-Connection: keep-alive\r\n" |
| 2896 | "Content-Length: 10\r\n\r\n"), |
| 2897 | // No response body because the test stops reading here. |
| 2898 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 5), |
| 2899 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2900 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 2901 | SequencedSocketData data1(data_reads1, arraysize(data_reads1), data_writes1, |
| 2902 | arraysize(data_writes1)); |
| 2903 | data1.set_busy_before_sync_reads(true); |
| 2904 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2905 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 2906 | TestCompletionCallback callback1; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2907 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 2908 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 2909 | EXPECT_EQ(OK, callback1.GetResult(rv)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2910 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 2911 | TestNetLogEntry::List entries; |
| 2912 | log.GetEntries(&entries); |
| 2913 | size_t pos = ExpectLogContainsSomewhere( |
| 2914 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 2915 | NetLog::PHASE_NONE); |
| 2916 | ExpectLogContainsSomewhere( |
| 2917 | entries, pos, |
| 2918 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 2919 | NetLog::PHASE_NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2920 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 2921 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 2922 | ASSERT_TRUE(response); |
| 2923 | ASSERT_TRUE(response->headers); |
| 2924 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2925 | EXPECT_EQ(407, response->headers->response_code()); |
| 2926 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 2927 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 2928 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2929 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 2930 | TestCompletionCallback callback2; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2931 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 2932 | // Wrong password (should be "bar"). |
| 2933 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBaz), |
| 2934 | callback2.callback()); |
| 2935 | EXPECT_EQ(OK, callback2.GetResult(rv)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2936 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 2937 | response = trans->GetResponseInfo(); |
| 2938 | ASSERT_TRUE(response); |
| 2939 | ASSERT_TRUE(response->headers); |
| 2940 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2941 | EXPECT_EQ(407, response->headers->response_code()); |
| 2942 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 2943 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 2944 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2945 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 2946 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 2947 | // out of scope. |
| 2948 | session->CloseAllConnections(); |
| 2949 | } |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2950 | } |
| 2951 | |
| 2952 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2953 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel. |
| 2954 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp11) { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 2955 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 2956 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 2957 | // reused. See http://crbug.com/544255. |
| 2958 | for (int i = 0; i < 2; ++i) { |
| 2959 | HttpRequestInfo request; |
| 2960 | request.method = "GET"; |
| 2961 | request.url = GURL("https://www.example.org/"); |
| 2962 | // Ensure that proxy authentication is attempted even |
| 2963 | // when the no authentication data flag is set. |
| 2964 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
| 2965 | |
| 2966 | // Configure against proxy server "myproxy:70". |
| 2967 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
| 2968 | BoundTestNetLog log; |
| 2969 | session_deps_.net_log = log.bound().net_log(); |
| 2970 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2971 | |
| 2972 | scoped_ptr<HttpTransaction> trans( |
| 2973 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 2974 | |
| 2975 | // Since we have proxy, should try to establish tunnel. |
| 2976 | MockWrite data_writes1[] = { |
| 2977 | MockWrite(ASYNC, 0, |
| 2978 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2979 | "Host: www.example.org:443\r\n" |
| 2980 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 2981 | |
| 2982 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2983 | // be issuing -- the final header line contains the credentials. |
| 2984 | MockWrite(ASYNC, 3, |
| 2985 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2986 | "Host: www.example.org:443\r\n" |
| 2987 | "Proxy-Connection: keep-alive\r\n" |
| 2988 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 2989 | }; |
| 2990 | |
| 2991 | // The proxy responds to the connect with a 407, using a persistent |
| 2992 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 2993 | MockRead data_reads1[] = { |
| 2994 | // No credentials. |
| 2995 | MockRead(ASYNC, 1, |
| 2996 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 2997 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 2998 | "Content-Length: 10\r\n\r\n"), |
| 2999 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 2, "0123456789"), |
| 3000 | |
| 3001 | // Wrong credentials (wrong password). |
| 3002 | MockRead(ASYNC, 4, |
| 3003 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3004 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3005 | "Content-Length: 10\r\n\r\n"), |
| 3006 | // No response body because the test stops reading here. |
| 3007 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 5), |
| 3008 | }; |
| 3009 | |
| 3010 | SequencedSocketData data1(data_reads1, arraysize(data_reads1), data_writes1, |
| 3011 | arraysize(data_writes1)); |
| 3012 | data1.set_busy_before_sync_reads(true); |
| 3013 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3014 | |
| 3015 | TestCompletionCallback callback1; |
| 3016 | |
| 3017 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 3018 | EXPECT_EQ(OK, callback1.GetResult(rv)); |
| 3019 | |
| 3020 | TestNetLogEntry::List entries; |
| 3021 | log.GetEntries(&entries); |
| 3022 | size_t pos = ExpectLogContainsSomewhere( |
| 3023 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3024 | NetLog::PHASE_NONE); |
| 3025 | ExpectLogContainsSomewhere( |
| 3026 | entries, pos, |
| 3027 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3028 | NetLog::PHASE_NONE); |
| 3029 | |
| 3030 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3031 | ASSERT_TRUE(response); |
| 3032 | ASSERT_TRUE(response->headers); |
| 3033 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3034 | EXPECT_EQ(407, response->headers->response_code()); |
| 3035 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3036 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3037 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3038 | |
| 3039 | TestCompletionCallback callback2; |
| 3040 | |
| 3041 | // Wrong password (should be "bar"). |
| 3042 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBaz), |
| 3043 | callback2.callback()); |
| 3044 | EXPECT_EQ(OK, callback2.GetResult(rv)); |
| 3045 | |
| 3046 | response = trans->GetResponseInfo(); |
| 3047 | ASSERT_TRUE(response); |
| 3048 | ASSERT_TRUE(response->headers); |
| 3049 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3050 | EXPECT_EQ(407, response->headers->response_code()); |
| 3051 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3052 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3053 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3054 | |
| 3055 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 3056 | // out of scope. |
| 3057 | session->CloseAllConnections(); |
| 3058 | } |
| 3059 | } |
| 3060 | |
| 3061 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3062 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel, in |
| 3063 | // the case the server sends extra data on the original socket, so it can't be |
| 3064 | // reused. |
| 3065 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveExtraData) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3066 | HttpRequestInfo request; |
| 3067 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3068 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3069 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3070 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3071 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3072 | // Configure against proxy server "myproxy:70". |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3073 | session_deps_.proxy_service = |
| 3074 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3075 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3076 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 3077 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3078 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3079 | // Since we have proxy, should try to establish tunnel. |
| 3080 | MockWrite data_writes1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3081 | MockWrite(ASYNC, 0, |
| 3082 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3083 | "Host: www.example.org:443\r\n" |
| 3084 | "Proxy-Connection: keep-alive\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3085 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3086 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3087 | // The proxy responds to the connect with a 407, using a persistent, but sends |
| 3088 | // extra data, so the socket cannot be reused. |
| 3089 | MockRead data_reads1[] = { |
| 3090 | // No credentials. |
| 3091 | MockRead(ASYNC, 1, |
| 3092 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3093 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3094 | "Content-Length: 10\r\n\r\n"), |
| 3095 | MockRead(SYNCHRONOUS, 2, "0123456789"), |
| 3096 | MockRead(SYNCHRONOUS, 3, "I'm broken!"), |
| 3097 | }; |
| 3098 | |
| 3099 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3100 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3101 | // be issuing -- the final header line contains the credentials. |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3102 | MockWrite(ASYNC, 0, |
| 3103 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3104 | "Host: www.example.org:443\r\n" |
| 3105 | "Proxy-Connection: keep-alive\r\n" |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3106 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3107 | |
| 3108 | MockWrite(ASYNC, 2, |
| 3109 | "GET / HTTP/1.1\r\n" |
| 3110 | "Host: www.example.org\r\n" |
| 3111 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3112 | }; |
| 3113 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3114 | MockRead data_reads2[] = { |
| 3115 | MockRead(ASYNC, 1, "HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3116 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3117 | MockRead(ASYNC, 3, |
| 3118 | "HTTP/1.1 200 OK\r\n" |
| 3119 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 3120 | "Content-Length: 5\r\n\r\n"), |
| 3121 | // No response body because the test stops reading here. |
| 3122 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 4), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3123 | }; |
| 3124 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3125 | SequencedSocketData data1(data_reads1, arraysize(data_reads1), data_writes1, |
| 3126 | arraysize(data_writes1)); |
| 3127 | data1.set_busy_before_sync_reads(true); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3128 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3129 | SequencedSocketData data2(data_reads2, arraysize(data_reads2), data_writes2, |
| 3130 | arraysize(data_writes2)); |
| 3131 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3132 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3133 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3134 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3135 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3136 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3137 | scoped_ptr<HttpTransaction> trans( |
| 3138 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3139 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3140 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 3141 | EXPECT_EQ(OK, callback1.GetResult(rv)); |
| 3142 | |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3143 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3144 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 3145 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3146 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 3147 | NetLog::PHASE_NONE); |
| 3148 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3149 | entries, pos, |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 3150 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3151 | NetLog::PHASE_NONE); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3152 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3153 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3154 | ASSERT_TRUE(response); |
| 3155 | ASSERT_TRUE(response->headers); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3156 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3157 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3158 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3159 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3160 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3161 | LoadTimingInfo load_timing_info; |
| 3162 | // CONNECT requests and responses are handled at the connect job level, so |
| 3163 | // the transaction does not yet have a connection. |
| 3164 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3165 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3166 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3167 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3168 | rv = |
| 3169 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
| 3170 | EXPECT_EQ(OK, callback2.GetResult(rv)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3171 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3172 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3173 | EXPECT_EQ(200, response->headers->response_code()); |
| 3174 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3175 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 3176 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3177 | // The password prompt info should not be set. |
| 3178 | EXPECT_FALSE(response->auth_challenge); |
| 3179 | |
| 3180 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3181 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3182 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3183 | |
| 3184 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3185 | session->CloseAllConnections(); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3186 | } |
| 3187 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3188 | // Test the case a proxy closes a socket while the challenge body is being |
| 3189 | // drained. |
| 3190 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHangupDuringBody) { |
| 3191 | HttpRequestInfo request; |
| 3192 | request.method = "GET"; |
| 3193 | request.url = GURL("https://www.example.org/"); |
| 3194 | // Ensure that proxy authentication is attempted even |
| 3195 | // when the no authentication data flag is set. |
| 3196 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
| 3197 | |
| 3198 | // Configure against proxy server "myproxy:70". |
| 3199 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 3200 | scoped_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3201 | |
| 3202 | scoped_ptr<HttpTransaction> trans( |
| 3203 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 3204 | |
| 3205 | // Since we have proxy, should try to establish tunnel. |
| 3206 | MockWrite data_writes1[] = { |
| 3207 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3208 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3209 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3210 | }; |
| 3211 | |
| 3212 | // The proxy responds to the connect with a 407, using a persistent |
| 3213 | // connection. |
| 3214 | MockRead data_reads1[] = { |
| 3215 | // No credentials. |
| 3216 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3217 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3218 | MockRead("Content-Length: 10\r\n\r\n"), MockRead("spam!"), |
| 3219 | // Server hands up in the middle of the body. |
| 3220 | MockRead(ASYNC, ERR_CONNECTION_CLOSED), |
| 3221 | }; |
| 3222 | |
| 3223 | MockWrite data_writes2[] = { |
| 3224 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3225 | // be issuing -- the final header line contains the credentials. |
| 3226 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3227 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3228 | "Proxy-Connection: keep-alive\r\n" |
| 3229 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3230 | |
| 3231 | MockWrite("GET / HTTP/1.1\r\n" |
| 3232 | "Host: www.example.org\r\n" |
| 3233 | "Connection: keep-alive\r\n\r\n"), |
| 3234 | }; |
| 3235 | |
| 3236 | MockRead data_reads2[] = { |
| 3237 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3238 | |
| 3239 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3240 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3241 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3242 | MockRead(SYNCHRONOUS, "hello"), |
| 3243 | }; |
| 3244 | |
| 3245 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3246 | data_writes1, arraysize(data_writes1)); |
| 3247 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3248 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3249 | data_writes2, arraysize(data_writes2)); |
| 3250 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3251 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3252 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3253 | |
| 3254 | TestCompletionCallback callback; |
| 3255 | |
| 3256 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 3257 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 3258 | |
| 3259 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3260 | ASSERT_TRUE(response); |
| 3261 | ASSERT_TRUE(response->headers); |
| 3262 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3263 | EXPECT_EQ(407, response->headers->response_code()); |
| 3264 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3265 | |
| 3266 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
| 3267 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 3268 | |
| 3269 | response = trans->GetResponseInfo(); |
| 3270 | ASSERT_TRUE(response); |
| 3271 | ASSERT_TRUE(response->headers); |
| 3272 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3273 | EXPECT_EQ(200, response->headers->response_code()); |
| 3274 | std::string body; |
| 3275 | EXPECT_EQ(OK, ReadTransaction(trans.get(), &body)); |
| 3276 | EXPECT_EQ("hello", body); |
| 3277 | } |
| 3278 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3279 | // Test that we don't read the response body when we fail to establish a tunnel, |
| 3280 | // even if the user cancels the proxy's auth attempt. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3281 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyCancelTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3282 | HttpRequestInfo request; |
| 3283 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3284 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3285 | request.load_flags = 0; |
| 3286 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3287 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3288 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3289 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 3290 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3291 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3292 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3293 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3294 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3295 | // Since we have proxy, should try to establish tunnel. |
| 3296 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3297 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3298 | "Host: www.example.org:443\r\n" |
| 3299 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3300 | }; |
| 3301 | |
| 3302 | // The proxy responds to the connect with a 407. |
| 3303 | MockRead data_reads[] = { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3304 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3305 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3306 | MockRead("Content-Length: 10\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3307 | MockRead("0123456789"), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3308 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3309 | }; |
| 3310 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 3311 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 3312 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3313 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3314 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3315 | TestCompletionCallback callback; |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3316 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3317 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3318 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3319 | |
| 3320 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3321 | EXPECT_EQ(OK, rv); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3322 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3323 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3324 | ASSERT_TRUE(response); |
| 3325 | ASSERT_TRUE(response->headers); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3326 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3327 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3328 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3329 | |
| 3330 | std::string response_data; |
| 3331 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3332 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 3333 | |
| 3334 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3335 | session->CloseAllConnections(); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3336 | } |
| 3337 | |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3338 | // Test that we don't pass extraneous headers from the proxy's response to the |
| 3339 | // caller when the proxy responds to CONNECT with 407. |
| 3340 | TEST_P(HttpNetworkTransactionTest, SanitizeProxyAuthHeaders) { |
| 3341 | HttpRequestInfo request; |
| 3342 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3343 | request.url = GURL("https://www.example.org/"); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3344 | request.load_flags = 0; |
| 3345 | |
| 3346 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3347 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3348 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 3349 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3350 | |
| 3351 | scoped_ptr<HttpTransaction> trans( |
| 3352 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 3353 | |
| 3354 | // Since we have proxy, should try to establish tunnel. |
| 3355 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3356 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3357 | "Host: www.example.org:443\r\n" |
| 3358 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3359 | }; |
| 3360 | |
| 3361 | // The proxy responds to the connect with a 407. |
| 3362 | MockRead data_reads[] = { |
| 3363 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3364 | MockRead("X-Foo: bar\r\n"), |
| 3365 | MockRead("Set-Cookie: foo=bar\r\n"), |
| 3366 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3367 | MockRead("Content-Length: 10\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3368 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3369 | }; |
| 3370 | |
| 3371 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 3372 | arraysize(data_writes)); |
| 3373 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 3374 | |
| 3375 | TestCompletionCallback callback; |
| 3376 | |
| 3377 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 3378 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3379 | |
| 3380 | rv = callback.WaitForResult(); |
| 3381 | EXPECT_EQ(OK, rv); |
| 3382 | |
| 3383 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3384 | ASSERT_TRUE(response); |
| 3385 | ASSERT_TRUE(response->headers); |
| 3386 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3387 | EXPECT_EQ(407, response->headers->response_code()); |
| 3388 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3389 | EXPECT_FALSE(response->headers->HasHeader("X-Foo")); |
| 3390 | EXPECT_FALSE(response->headers->HasHeader("Set-Cookie")); |
| 3391 | |
| 3392 | std::string response_data; |
| 3393 | rv = ReadTransaction(trans.get(), &response_data); |
| 3394 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
| 3395 | |
| 3396 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
| 3397 | session->CloseAllConnections(); |
| 3398 | } |
| 3399 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3400 | // Test when a server (non-proxy) returns a 407 (proxy-authenticate). |
| 3401 | // The request should fail with ERR_UNEXPECTED_PROXY_AUTH. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3402 | TEST_P(HttpNetworkTransactionTest, UnexpectedProxyAuth) { |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3403 | HttpRequestInfo request; |
| 3404 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3405 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3406 | request.load_flags = 0; |
| 3407 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3408 | // We are using a DIRECT connection (i.e. no proxy) for this session. |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 3409 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3410 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 3411 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3412 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3413 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3414 | MockWrite( |
| 3415 | "GET / HTTP/1.1\r\n" |
| 3416 | "Host: www.example.org\r\n" |
| 3417 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3418 | }; |
| 3419 | |
| 3420 | MockRead data_reads1[] = { |
| 3421 | MockRead("HTTP/1.0 407 Proxy Auth required\r\n"), |
| 3422 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3423 | // Large content-length -- won't matter, as connection will be reset. |
| 3424 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3425 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3426 | }; |
| 3427 | |
| 3428 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3429 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3430 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3431 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3432 | TestCompletionCallback callback; |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3433 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3434 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3435 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3436 | |
| 3437 | rv = callback.WaitForResult(); |
| 3438 | EXPECT_EQ(ERR_UNEXPECTED_PROXY_AUTH, rv); |
| 3439 | } |
| 3440 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3441 | // Tests when an HTTPS server (non-proxy) returns a 407 (proxy-authentication) |
| 3442 | // through a non-authenticating proxy. The request should fail with |
| 3443 | // ERR_UNEXPECTED_PROXY_AUTH. |
| 3444 | // Note that it is impossible to detect if an HTTP server returns a 407 through |
| 3445 | // a non-authenticating proxy - there is nothing to indicate whether the |
| 3446 | // response came from the proxy or the server, so it is treated as if the proxy |
| 3447 | // issued the challenge. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3448 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 3449 | HttpsServerRequestsProxyAuthThroughProxy) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3450 | HttpRequestInfo request; |
| 3451 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3452 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3453 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3454 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3455 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3456 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 3457 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3458 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3459 | // Since we have proxy, should try to establish tunnel. |
| 3460 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3461 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3462 | "Host: www.example.org:443\r\n" |
| 3463 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3464 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3465 | MockWrite("GET / HTTP/1.1\r\n" |
| 3466 | "Host: www.example.org\r\n" |
| 3467 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3468 | }; |
| 3469 | |
| 3470 | MockRead data_reads1[] = { |
| 3471 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3472 | |
| 3473 | MockRead("HTTP/1.1 407 Unauthorized\r\n"), |
| 3474 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3475 | MockRead("\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3476 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3477 | }; |
| 3478 | |
| 3479 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3480 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3481 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3482 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3483 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3484 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3485 | TestCompletionCallback callback1; |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3486 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3487 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3488 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3489 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3490 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3491 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3492 | |
| 3493 | rv = callback1.WaitForResult(); |
| 3494 | EXPECT_EQ(ERR_UNEXPECTED_PROXY_AUTH, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3495 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3496 | log.GetEntries(&entries); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3497 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3498 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3499 | NetLog::PHASE_NONE); |
| 3500 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3501 | entries, pos, |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3502 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3503 | NetLog::PHASE_NONE); |
| 3504 | } |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3505 | |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3506 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 3507 | // that uses non-persistent connections. |
| 3508 | TEST_P(HttpNetworkTransactionTest, |
| 3509 | AuthAllowsDefaultCredentialsTunnelConnectionClose) { |
| 3510 | HttpRequestInfo request; |
| 3511 | request.method = "GET"; |
| 3512 | request.url = GURL("https://www.example.org/"); |
| 3513 | |
| 3514 | // Configure against proxy server "myproxy:70". |
| 3515 | session_deps_.proxy_service = |
| 3516 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 3517 | |
| 3518 | scoped_ptr<HttpAuthHandlerMock::Factory> auth_handler_factory( |
| 3519 | new HttpAuthHandlerMock::Factory()); |
| 3520 | auth_handler_factory->set_do_init_from_challenge(true); |
| 3521 | scoped_ptr<HttpAuthHandlerMock> mock_handler(new HttpAuthHandlerMock()); |
| 3522 | mock_handler->set_allows_default_credentials(true); |
| 3523 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 3524 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 3525 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3526 | |
| 3527 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 3528 | NetLog net_log; |
| 3529 | session_deps_.net_log = &net_log; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 3530 | scoped_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3531 | |
| 3532 | // Since we have proxy, should try to establish tunnel. |
| 3533 | MockWrite data_writes1[] = { |
| 3534 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3535 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3536 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3537 | }; |
| 3538 | |
| 3539 | // The proxy responds to the connect with a 407, using a non-persistent |
| 3540 | // connection. |
| 3541 | MockRead data_reads1[] = { |
| 3542 | // No credentials. |
| 3543 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3544 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 3545 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 3546 | }; |
| 3547 | |
| 3548 | // Since the first connection couldn't be reused, need to establish another |
| 3549 | // once given credentials. |
| 3550 | MockWrite data_writes2[] = { |
| 3551 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3552 | // be issuing -- the final header line contains the credentials. |
| 3553 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3554 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3555 | "Proxy-Connection: keep-alive\r\n" |
| 3556 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 3557 | |
| 3558 | MockWrite("GET / HTTP/1.1\r\n" |
| 3559 | "Host: www.example.org\r\n" |
| 3560 | "Connection: keep-alive\r\n\r\n"), |
| 3561 | }; |
| 3562 | |
| 3563 | MockRead data_reads2[] = { |
| 3564 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 3565 | |
| 3566 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3567 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3568 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3569 | MockRead(SYNCHRONOUS, "hello"), |
| 3570 | }; |
| 3571 | |
| 3572 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3573 | data_writes1, arraysize(data_writes1)); |
| 3574 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3575 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3576 | data_writes2, arraysize(data_writes2)); |
| 3577 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3578 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3579 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3580 | |
| 3581 | scoped_ptr<HttpTransaction> trans( |
| 3582 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 3583 | |
| 3584 | TestCompletionCallback callback; |
| 3585 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 3586 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 3587 | |
| 3588 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3589 | ASSERT_TRUE(response); |
| 3590 | ASSERT_TRUE(response->headers); |
| 3591 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
| 3592 | EXPECT_EQ(407, response->headers->response_code()); |
| 3593 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3594 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 3595 | EXPECT_FALSE(response->auth_challenge.get()); |
| 3596 | |
| 3597 | LoadTimingInfo load_timing_info; |
| 3598 | // CONNECT requests and responses are handled at the connect job level, so |
| 3599 | // the transaction does not yet have a connection. |
| 3600 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3601 | |
| 3602 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 3603 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 3604 | response = trans->GetResponseInfo(); |
| 3605 | ASSERT_TRUE(response); |
| 3606 | ASSERT_TRUE(response->headers); |
| 3607 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3608 | EXPECT_EQ(200, response->headers->response_code()); |
| 3609 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 3610 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3611 | |
| 3612 | // The password prompt info should not be set. |
| 3613 | EXPECT_FALSE(response->auth_challenge); |
| 3614 | |
| 3615 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3616 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3617 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3618 | |
| 3619 | trans.reset(); |
| 3620 | session->CloseAllConnections(); |
| 3621 | } |
| 3622 | |
| 3623 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 3624 | // that hangs up when credentials are initially sent. |
| 3625 | TEST_P(HttpNetworkTransactionTest, |
| 3626 | AuthAllowsDefaultCredentialsTunnelServerClosesConnection) { |
| 3627 | HttpRequestInfo request; |
| 3628 | request.method = "GET"; |
| 3629 | request.url = GURL("https://www.example.org/"); |
| 3630 | |
| 3631 | // Configure against proxy server "myproxy:70". |
| 3632 | session_deps_.proxy_service = |
| 3633 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 3634 | |
| 3635 | scoped_ptr<HttpAuthHandlerMock::Factory> auth_handler_factory( |
| 3636 | new HttpAuthHandlerMock::Factory()); |
| 3637 | auth_handler_factory->set_do_init_from_challenge(true); |
| 3638 | scoped_ptr<HttpAuthHandlerMock> mock_handler(new HttpAuthHandlerMock()); |
| 3639 | mock_handler->set_allows_default_credentials(true); |
| 3640 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 3641 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 3642 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3643 | |
| 3644 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 3645 | NetLog net_log; |
| 3646 | session_deps_.net_log = &net_log; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 3647 | scoped_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3648 | |
| 3649 | // Should try to establish tunnel. |
| 3650 | MockWrite data_writes1[] = { |
| 3651 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3652 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3653 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3654 | |
| 3655 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3656 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3657 | "Proxy-Connection: keep-alive\r\n" |
| 3658 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 3659 | }; |
| 3660 | |
| 3661 | // The proxy responds to the connect with a 407, using a non-persistent |
| 3662 | // connection. |
| 3663 | MockRead data_reads1[] = { |
| 3664 | // No credentials. |
| 3665 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3666 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 3667 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 3668 | }; |
| 3669 | |
| 3670 | // Since the first connection was closed, need to establish another once given |
| 3671 | // credentials. |
| 3672 | MockWrite data_writes2[] = { |
| 3673 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3674 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3675 | "Proxy-Connection: keep-alive\r\n" |
| 3676 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 3677 | |
| 3678 | MockWrite("GET / HTTP/1.1\r\n" |
| 3679 | "Host: www.example.org\r\n" |
| 3680 | "Connection: keep-alive\r\n\r\n"), |
| 3681 | }; |
| 3682 | |
| 3683 | MockRead data_reads2[] = { |
| 3684 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 3685 | |
| 3686 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3687 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3688 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3689 | MockRead(SYNCHRONOUS, "hello"), |
| 3690 | }; |
| 3691 | |
| 3692 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3693 | data_writes1, arraysize(data_writes1)); |
| 3694 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3695 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3696 | data_writes2, arraysize(data_writes2)); |
| 3697 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3698 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3699 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3700 | |
| 3701 | scoped_ptr<HttpTransaction> trans( |
| 3702 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 3703 | |
| 3704 | TestCompletionCallback callback; |
| 3705 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 3706 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 3707 | |
| 3708 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3709 | ASSERT_TRUE(response); |
| 3710 | ASSERT_TRUE(response->headers); |
| 3711 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3712 | EXPECT_EQ(407, response->headers->response_code()); |
| 3713 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3714 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 3715 | EXPECT_FALSE(response->auth_challenge); |
| 3716 | |
| 3717 | LoadTimingInfo load_timing_info; |
| 3718 | // CONNECT requests and responses are handled at the connect job level, so |
| 3719 | // the transaction does not yet have a connection. |
| 3720 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3721 | |
| 3722 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 3723 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 3724 | |
| 3725 | response = trans->GetResponseInfo(); |
| 3726 | ASSERT_TRUE(response); |
| 3727 | ASSERT_TRUE(response->headers); |
| 3728 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3729 | EXPECT_EQ(200, response->headers->response_code()); |
| 3730 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 3731 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3732 | |
| 3733 | // The password prompt info should not be set. |
| 3734 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 3735 | |
| 3736 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3737 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3738 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3739 | |
| 3740 | trans.reset(); |
| 3741 | session->CloseAllConnections(); |
| 3742 | } |
| 3743 | |
| 3744 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 3745 | // that hangs up when credentials are initially sent, and hangs up again when |
| 3746 | // they are retried. |
| 3747 | TEST_P(HttpNetworkTransactionTest, |
| 3748 | AuthAllowsDefaultCredentialsTunnelServerClosesConnectionTwice) { |
| 3749 | HttpRequestInfo request; |
| 3750 | request.method = "GET"; |
| 3751 | request.url = GURL("https://www.example.org/"); |
| 3752 | |
| 3753 | // Configure against proxy server "myproxy:70". |
| 3754 | session_deps_.proxy_service = |
| 3755 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 3756 | |
| 3757 | scoped_ptr<HttpAuthHandlerMock::Factory> auth_handler_factory( |
| 3758 | new HttpAuthHandlerMock::Factory()); |
| 3759 | auth_handler_factory->set_do_init_from_challenge(true); |
| 3760 | scoped_ptr<HttpAuthHandlerMock> mock_handler(new HttpAuthHandlerMock()); |
| 3761 | mock_handler->set_allows_default_credentials(true); |
| 3762 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 3763 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 3764 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3765 | |
| 3766 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 3767 | NetLog net_log; |
| 3768 | session_deps_.net_log = &net_log; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 3769 | scoped_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3770 | |
| 3771 | // Should try to establish tunnel. |
| 3772 | MockWrite data_writes1[] = { |
| 3773 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3774 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3775 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3776 | |
| 3777 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3778 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3779 | "Proxy-Connection: keep-alive\r\n" |
| 3780 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 3781 | }; |
| 3782 | |
| 3783 | // The proxy responds to the connect with a 407, and then hangs up after the |
| 3784 | // second request is sent. |
| 3785 | MockRead data_reads1[] = { |
| 3786 | // No credentials. |
| 3787 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3788 | MockRead("Content-Length: 0\r\n"), |
| 3789 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 3790 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 3791 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 3792 | }; |
| 3793 | |
| 3794 | // HttpNetworkTransaction sees a reused connection that was closed with |
| 3795 | // ERR_CONNECTION_CLOSED, realized it might have been a race, so retries the |
| 3796 | // request. |
| 3797 | MockWrite data_writes2[] = { |
| 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 | |
| 3803 | // The proxy, having had more than enough of us, just hangs up. |
| 3804 | MockRead data_reads2[] = { |
| 3805 | // No credentials. |
| 3806 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 3807 | }; |
| 3808 | |
| 3809 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3810 | data_writes1, arraysize(data_writes1)); |
| 3811 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3812 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3813 | data_writes2, arraysize(data_writes2)); |
| 3814 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3815 | |
| 3816 | scoped_ptr<HttpTransaction> trans( |
| 3817 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 3818 | |
| 3819 | TestCompletionCallback callback; |
| 3820 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 3821 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 3822 | |
| 3823 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3824 | ASSERT_TRUE(response); |
| 3825 | ASSERT_TRUE(response->headers); |
| 3826 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3827 | EXPECT_EQ(407, response->headers->response_code()); |
| 3828 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3829 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 3830 | EXPECT_FALSE(response->auth_challenge); |
| 3831 | |
| 3832 | LoadTimingInfo load_timing_info; |
| 3833 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3834 | |
| 3835 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 3836 | EXPECT_EQ(ERR_EMPTY_RESPONSE, callback.GetResult(rv)); |
| 3837 | |
| 3838 | trans.reset(); |
| 3839 | session->CloseAllConnections(); |
| 3840 | } |
| 3841 | |
| 3842 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 3843 | // that hangs up when credentials are initially sent, and sends a challenge |
| 3844 | // again they are retried. |
| 3845 | TEST_P(HttpNetworkTransactionTest, |
| 3846 | AuthAllowsDefaultCredentialsTunnelServerChallengesTwice) { |
| 3847 | HttpRequestInfo request; |
| 3848 | request.method = "GET"; |
| 3849 | request.url = GURL("https://www.example.org/"); |
| 3850 | |
| 3851 | // Configure against proxy server "myproxy:70". |
| 3852 | session_deps_.proxy_service = |
| 3853 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 3854 | |
| 3855 | scoped_ptr<HttpAuthHandlerMock::Factory> auth_handler_factory( |
| 3856 | new HttpAuthHandlerMock::Factory()); |
| 3857 | auth_handler_factory->set_do_init_from_challenge(true); |
| 3858 | scoped_ptr<HttpAuthHandlerMock> mock_handler(new HttpAuthHandlerMock()); |
| 3859 | mock_handler->set_allows_default_credentials(true); |
| 3860 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 3861 | HttpAuth::AUTH_PROXY); |
| 3862 | // Add another handler for the second challenge. It supports default |
| 3863 | // credentials, but they shouldn't be used, since they were already tried. |
| 3864 | mock_handler.reset(new HttpAuthHandlerMock()); |
| 3865 | mock_handler->set_allows_default_credentials(true); |
| 3866 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 3867 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 3868 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3869 | |
| 3870 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 3871 | NetLog net_log; |
| 3872 | session_deps_.net_log = &net_log; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 3873 | scoped_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3874 | |
| 3875 | // Should try to establish tunnel. |
| 3876 | MockWrite data_writes1[] = { |
| 3877 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3878 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3879 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3880 | }; |
| 3881 | |
| 3882 | // The proxy responds to the connect with a 407, using a non-persistent |
| 3883 | // connection. |
| 3884 | MockRead data_reads1[] = { |
| 3885 | // No credentials. |
| 3886 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3887 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 3888 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 3889 | }; |
| 3890 | |
| 3891 | // Since the first connection was closed, need to establish another once given |
| 3892 | // credentials. |
| 3893 | MockWrite data_writes2[] = { |
| 3894 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3895 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3896 | "Proxy-Connection: keep-alive\r\n" |
| 3897 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 3898 | }; |
| 3899 | |
| 3900 | MockRead data_reads2[] = { |
| 3901 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3902 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 3903 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 3904 | }; |
| 3905 | |
| 3906 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3907 | data_writes1, arraysize(data_writes1)); |
| 3908 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3909 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3910 | data_writes2, arraysize(data_writes2)); |
| 3911 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3912 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3913 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3914 | |
| 3915 | scoped_ptr<HttpTransaction> trans( |
| 3916 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 3917 | |
| 3918 | TestCompletionCallback callback; |
| 3919 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 3920 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 3921 | |
| 3922 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3923 | ASSERT_TRUE(response); |
| 3924 | ASSERT_TRUE(response->headers); |
| 3925 | EXPECT_EQ(407, response->headers->response_code()); |
| 3926 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3927 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 3928 | EXPECT_FALSE(response->auth_challenge); |
| 3929 | |
| 3930 | LoadTimingInfo load_timing_info; |
| 3931 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3932 | |
| 3933 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 3934 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 3935 | response = trans->GetResponseInfo(); |
| 3936 | ASSERT_TRUE(response); |
| 3937 | ASSERT_TRUE(response->headers); |
| 3938 | EXPECT_EQ(407, response->headers->response_code()); |
| 3939 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 3940 | EXPECT_TRUE(response->auth_challenge); |
| 3941 | |
| 3942 | trans.reset(); |
| 3943 | session->CloseAllConnections(); |
| 3944 | } |
| 3945 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3946 | // Test the load timing for HTTPS requests with an HTTP proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3947 | TEST_P(HttpNetworkTransactionTest, HttpProxyLoadTimingNoPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3948 | HttpRequestInfo request1; |
| 3949 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3950 | request1.url = GURL("https://www.example.org/1"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3951 | |
| 3952 | HttpRequestInfo request2; |
| 3953 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3954 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3955 | |
| 3956 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3957 | session_deps_.proxy_service = ProxyService::CreateFixed("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3958 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3959 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 3960 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3961 | |
| 3962 | // Since we have proxy, should try to establish tunnel. |
| 3963 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3964 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3965 | "Host: www.example.org:443\r\n" |
| 3966 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3967 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3968 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 3969 | "Host: www.example.org\r\n" |
| 3970 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3971 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3972 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 3973 | "Host: www.example.org\r\n" |
| 3974 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3975 | }; |
| 3976 | |
| 3977 | // The proxy responds to the connect with a 407, using a persistent |
| 3978 | // connection. |
| 3979 | MockRead data_reads1[] = { |
| 3980 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3981 | |
| 3982 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3983 | MockRead("Content-Length: 1\r\n\r\n"), |
| 3984 | MockRead(SYNCHRONOUS, "1"), |
| 3985 | |
| 3986 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3987 | MockRead("Content-Length: 2\r\n\r\n"), |
| 3988 | MockRead(SYNCHRONOUS, "22"), |
| 3989 | }; |
| 3990 | |
| 3991 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3992 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3993 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3994 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3995 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3996 | |
| 3997 | TestCompletionCallback callback1; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3998 | scoped_ptr<HttpTransaction> trans1( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3999 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4000 | |
| 4001 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
| 4002 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4003 | |
| 4004 | rv = callback1.WaitForResult(); |
| 4005 | EXPECT_EQ(OK, rv); |
| 4006 | |
| 4007 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 4008 | ASSERT_TRUE(response1 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4009 | ASSERT_TRUE(response1->headers.get() != NULL); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4010 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 4011 | |
| 4012 | LoadTimingInfo load_timing_info1; |
| 4013 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 4014 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4015 | |
| 4016 | trans1.reset(); |
| 4017 | |
| 4018 | TestCompletionCallback callback2; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4019 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4020 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4021 | |
| 4022 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
| 4023 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4024 | |
| 4025 | rv = callback2.WaitForResult(); |
| 4026 | EXPECT_EQ(OK, rv); |
| 4027 | |
| 4028 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 4029 | ASSERT_TRUE(response2 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4030 | ASSERT_TRUE(response2->headers.get() != NULL); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4031 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 4032 | |
| 4033 | LoadTimingInfo load_timing_info2; |
| 4034 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4035 | TestLoadTimingReused(load_timing_info2); |
| 4036 | |
| 4037 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 4038 | |
| 4039 | trans2.reset(); |
| 4040 | session->CloseAllConnections(); |
| 4041 | } |
| 4042 | |
| 4043 | // Test the load timing for HTTPS requests with an HTTP proxy and a PAC script. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4044 | TEST_P(HttpNetworkTransactionTest, HttpProxyLoadTimingWithPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4045 | HttpRequestInfo request1; |
| 4046 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4047 | request1.url = GURL("https://www.example.org/1"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4048 | |
| 4049 | HttpRequestInfo request2; |
| 4050 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4051 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4052 | |
| 4053 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4054 | session_deps_.proxy_service = |
| 4055 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4056 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4057 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4058 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4059 | |
| 4060 | // Since we have proxy, should try to establish tunnel. |
| 4061 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4062 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4063 | "Host: www.example.org:443\r\n" |
| 4064 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4065 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4066 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 4067 | "Host: www.example.org\r\n" |
| 4068 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4069 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4070 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 4071 | "Host: www.example.org\r\n" |
| 4072 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4073 | }; |
| 4074 | |
| 4075 | // The proxy responds to the connect with a 407, using a persistent |
| 4076 | // connection. |
| 4077 | MockRead data_reads1[] = { |
| 4078 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 4079 | |
| 4080 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4081 | MockRead("Content-Length: 1\r\n\r\n"), |
| 4082 | MockRead(SYNCHRONOUS, "1"), |
| 4083 | |
| 4084 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4085 | MockRead("Content-Length: 2\r\n\r\n"), |
| 4086 | MockRead(SYNCHRONOUS, "22"), |
| 4087 | }; |
| 4088 | |
| 4089 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4090 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4091 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4092 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4093 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4094 | |
| 4095 | TestCompletionCallback callback1; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4096 | scoped_ptr<HttpTransaction> trans1( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4097 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4098 | |
| 4099 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
| 4100 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4101 | |
| 4102 | rv = callback1.WaitForResult(); |
| 4103 | EXPECT_EQ(OK, rv); |
| 4104 | |
| 4105 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 4106 | ASSERT_TRUE(response1 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4107 | ASSERT_TRUE(response1->headers.get() != NULL); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4108 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 4109 | |
| 4110 | LoadTimingInfo load_timing_info1; |
| 4111 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 4112 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 4113 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4114 | |
| 4115 | trans1.reset(); |
| 4116 | |
| 4117 | TestCompletionCallback callback2; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4118 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4119 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4120 | |
| 4121 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
| 4122 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4123 | |
| 4124 | rv = callback2.WaitForResult(); |
| 4125 | EXPECT_EQ(OK, rv); |
| 4126 | |
| 4127 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 4128 | ASSERT_TRUE(response2 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4129 | ASSERT_TRUE(response2->headers.get() != NULL); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4130 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 4131 | |
| 4132 | LoadTimingInfo load_timing_info2; |
| 4133 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4134 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 4135 | |
| 4136 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 4137 | |
| 4138 | trans2.reset(); |
| 4139 | session->CloseAllConnections(); |
| 4140 | } |
| 4141 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4142 | // Test a simple get through an HTTPS Proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4143 | TEST_P(HttpNetworkTransactionTest, HttpsProxyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4144 | HttpRequestInfo request; |
| 4145 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4146 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4147 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4148 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4149 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4150 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4151 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4152 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4153 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4154 | // Since we have proxy, should use full url |
| 4155 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4156 | MockWrite( |
| 4157 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 4158 | "Host: www.example.org\r\n" |
| 4159 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4160 | }; |
| 4161 | |
| 4162 | MockRead data_reads1[] = { |
| 4163 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4164 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4165 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4166 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4167 | }; |
| 4168 | |
| 4169 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4170 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4171 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4172 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4173 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4174 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4175 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4176 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4177 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4178 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4179 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4180 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4181 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4182 | |
| 4183 | rv = callback1.WaitForResult(); |
| 4184 | EXPECT_EQ(OK, rv); |
| 4185 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4186 | LoadTimingInfo load_timing_info; |
| 4187 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4188 | TestLoadTimingNotReused(load_timing_info, |
| 4189 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 4190 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4191 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4192 | ASSERT_TRUE(response != NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4193 | |
| 4194 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4195 | EXPECT_EQ(200, response->headers->response_code()); |
| 4196 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 4197 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4198 | |
| 4199 | // The password prompt info should not be set. |
| 4200 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 4201 | } |
| 4202 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4203 | // Test a SPDY get through an HTTPS Proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4204 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4205 | HttpRequestInfo request; |
| 4206 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4207 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4208 | request.load_flags = 0; |
| 4209 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4210 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4211 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4212 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4213 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4214 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4215 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4216 | // fetch http://www.example.org/ via SPDY |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4217 | scoped_ptr<SpdyFrame> req( |
| 4218 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4219 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4220 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4221 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 4222 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4223 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4224 | CreateMockRead(*resp, 1), CreateMockRead(*data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4225 | }; |
| 4226 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4227 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4228 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4229 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4230 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4231 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4232 | ssl.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4233 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4234 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4235 | TestCompletionCallback callback1; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4236 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4237 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4238 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4239 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4240 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4241 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4242 | |
| 4243 | rv = callback1.WaitForResult(); |
| 4244 | EXPECT_EQ(OK, rv); |
| 4245 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4246 | LoadTimingInfo load_timing_info; |
| 4247 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4248 | TestLoadTimingNotReused(load_timing_info, |
| 4249 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 4250 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4251 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4252 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4253 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 4254 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4255 | |
| 4256 | std::string response_data; |
| 4257 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 4258 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4259 | } |
| 4260 | |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4261 | // Verifies that a session which races and wins against the owning transaction |
| 4262 | // (completing prior to host resolution), doesn't fail the transaction. |
| 4263 | // Regression test for crbug.com/334413. |
| 4264 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyGetWithSessionRace) { |
| 4265 | HttpRequestInfo request; |
| 4266 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4267 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4268 | request.load_flags = 0; |
| 4269 | |
| 4270 | // Configure SPDY proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4271 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4272 | BoundTestNetLog log; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4273 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4274 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4275 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4276 | // Fetch http://www.example.org/ through the SPDY proxy. |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4277 | scoped_ptr<SpdyFrame> req( |
| 4278 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4279 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4280 | |
| 4281 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 4282 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 4283 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4284 | CreateMockRead(*resp, 1), CreateMockRead(*data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4285 | }; |
| 4286 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4287 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4288 | arraysize(spdy_writes)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4289 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 4290 | |
| 4291 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4292 | ssl.SetNextProto(GetProtocol()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4293 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4294 | |
| 4295 | TestCompletionCallback callback1; |
| 4296 | |
| 4297 | scoped_ptr<HttpTransaction> trans( |
| 4298 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 4299 | |
| 4300 | // Stall the hostname resolution begun by the transaction. |
| 4301 | session_deps_.host_resolver->set_synchronous_mode(false); |
| 4302 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 4303 | |
| 4304 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 4305 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4306 | |
| 4307 | // Race a session to the proxy, which completes first. |
| 4308 | session_deps_.host_resolver->set_ondemand_mode(false); |
| 4309 | SpdySessionKey key( |
| 4310 | HostPortPair("proxy", 70), ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
| 4311 | base::WeakPtr<SpdySession> spdy_session = |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4312 | CreateSecureSpdySession(session.get(), key, log.bound()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4313 | |
| 4314 | // Unstall the resolution begun by the transaction. |
| 4315 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 4316 | session_deps_.host_resolver->ResolveAllPending(); |
| 4317 | |
| 4318 | EXPECT_FALSE(callback1.have_result()); |
| 4319 | rv = callback1.WaitForResult(); |
| 4320 | EXPECT_EQ(OK, rv); |
| 4321 | |
| 4322 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4323 | ASSERT_TRUE(response != NULL); |
| 4324 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 4325 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4326 | |
| 4327 | std::string response_data; |
| 4328 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 4329 | EXPECT_EQ(kUploadData, response_data); |
| 4330 | } |
| 4331 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4332 | // Test a SPDY get through an HTTPS Proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4333 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyGetWithProxyAuth) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4334 | HttpRequestInfo request; |
| 4335 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4336 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4337 | request.load_flags = 0; |
| 4338 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4339 | // Configure against https proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4340 | session_deps_.proxy_service = ProxyService::CreateFixed("https://myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4341 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4342 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4343 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4344 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4345 | // The first request will be a bare GET, the second request will be a |
| 4346 | // GET with a Proxy-Authorization header. |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4347 | scoped_ptr<SpdyFrame> req_get( |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4348 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4349 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4350 | const char* const kExtraAuthorizationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4351 | "proxy-authorization", "Basic Zm9vOmJhcg==" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4352 | }; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4353 | scoped_ptr<SpdyFrame> req_get_authorization( |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4354 | spdy_util_.ConstructSpdyGet(kExtraAuthorizationHeaders, |
| 4355 | arraysize(kExtraAuthorizationHeaders) / 2, |
| 4356 | false, |
| 4357 | 3, |
| 4358 | LOWEST, |
| 4359 | false)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4360 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4361 | CreateMockWrite(*req_get, 0), CreateMockWrite(*req_get_authorization, 3), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4362 | }; |
| 4363 | |
| 4364 | // The first response is a 407 proxy authentication challenge, and the second |
| 4365 | // response will be a 200 response since the second request includes a valid |
| 4366 | // Authorization header. |
| 4367 | const char* const kExtraAuthenticationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4368 | "proxy-authenticate", "Basic realm=\"MyRealm1\"" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4369 | }; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4370 | scoped_ptr<SpdyFrame> resp_authentication( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4371 | spdy_util_.ConstructSpdySynReplyError( |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4372 | "407 Proxy Authentication Required", |
| 4373 | kExtraAuthenticationHeaders, arraysize(kExtraAuthenticationHeaders)/2, |
| 4374 | 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4375 | scoped_ptr<SpdyFrame> body_authentication( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4376 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 4377 | scoped_ptr<SpdyFrame> resp_data( |
| 4378 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 4379 | scoped_ptr<SpdyFrame> body_data(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4380 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4381 | CreateMockRead(*resp_authentication, 1), |
| 4382 | CreateMockRead(*body_authentication, 2), |
| 4383 | CreateMockRead(*resp_data, 4), |
| 4384 | CreateMockRead(*body_data, 5), |
| 4385 | MockRead(ASYNC, 0, 6), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4386 | }; |
| 4387 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4388 | SequencedSocketData data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4389 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4390 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4391 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4392 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4393 | ssl.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4394 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4395 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4396 | TestCompletionCallback callback1; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4397 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4398 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4399 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4400 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4401 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4402 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4403 | |
| 4404 | rv = callback1.WaitForResult(); |
| 4405 | EXPECT_EQ(OK, rv); |
| 4406 | |
| 4407 | const HttpResponseInfo* const response = trans->GetResponseInfo(); |
| 4408 | |
| 4409 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4410 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4411 | EXPECT_EQ(407, response->headers->response_code()); |
| 4412 | EXPECT_TRUE(response->was_fetched_via_spdy); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4413 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4414 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4415 | TestCompletionCallback callback2; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4416 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4417 | rv = trans->RestartWithAuth( |
| 4418 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4419 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4420 | |
| 4421 | rv = callback2.WaitForResult(); |
| 4422 | EXPECT_EQ(OK, rv); |
| 4423 | |
| 4424 | const HttpResponseInfo* const response_restart = trans->GetResponseInfo(); |
| 4425 | |
| 4426 | ASSERT_TRUE(response_restart != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4427 | ASSERT_TRUE(response_restart->headers.get() != NULL); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4428 | EXPECT_EQ(200, response_restart->headers->response_code()); |
| 4429 | // The password prompt info should not be set. |
| 4430 | EXPECT_TRUE(response_restart->auth_challenge.get() == NULL); |
| 4431 | } |
| 4432 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4433 | // Test a SPDY CONNECT through an HTTPS Proxy to an HTTPS (non-SPDY) Server. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4434 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyConnectHttps) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4435 | HttpRequestInfo request; |
| 4436 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4437 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4438 | request.load_flags = 0; |
| 4439 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4440 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4441 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4442 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4443 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4444 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4445 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4446 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4447 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4448 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4449 | // CONNECT to www.example.org:443 via SPDY |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 4450 | scoped_ptr<SpdyFrame> connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4451 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 4452 | // fetch https://www.example.org/ via HTTP |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4453 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4454 | const char get[] = |
| 4455 | "GET / HTTP/1.1\r\n" |
| 4456 | "Host: www.example.org\r\n" |
| 4457 | "Connection: keep-alive\r\n\r\n"; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4458 | scoped_ptr<SpdyFrame> wrapped_get( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4459 | spdy_util_.ConstructSpdyBodyFrame(1, get, strlen(get), false)); |
| 4460 | scoped_ptr<SpdyFrame> conn_resp( |
| 4461 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4462 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 4463 | "Content-Length: 10\r\n\r\n"; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4464 | scoped_ptr<SpdyFrame> wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4465 | spdy_util_.ConstructSpdyBodyFrame(1, resp, strlen(resp), false)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4466 | scoped_ptr<SpdyFrame> wrapped_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4467 | spdy_util_.ConstructSpdyBodyFrame(1, "1234567890", 10, false)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4468 | scoped_ptr<SpdyFrame> window_update( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 4469 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp->size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 4470 | |
| 4471 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4472 | CreateMockWrite(*connect, 0), |
| 4473 | CreateMockWrite(*wrapped_get, 2), |
| 4474 | CreateMockWrite(*window_update, 6), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 4475 | }; |
| 4476 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4477 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4478 | CreateMockRead(*conn_resp, 1, ASYNC), |
| 4479 | CreateMockRead(*wrapped_get_resp, 3, ASYNC), |
| 4480 | CreateMockRead(*wrapped_body, 4, ASYNC), |
| 4481 | CreateMockRead(*wrapped_body, 5, ASYNC), |
| 4482 | MockRead(ASYNC, 0, 7), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4483 | }; |
| 4484 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4485 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4486 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4487 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4488 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4489 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4490 | ssl.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4491 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4492 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4493 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4494 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4495 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4496 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4497 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4498 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4499 | |
| 4500 | rv = callback1.WaitForResult(); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4501 | ASSERT_EQ(OK, rv); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4502 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4503 | LoadTimingInfo load_timing_info; |
| 4504 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4505 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4506 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4507 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4508 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4509 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4510 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4511 | |
| 4512 | std::string response_data; |
| 4513 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 4514 | EXPECT_EQ("1234567890", response_data); |
| 4515 | } |
| 4516 | |
| 4517 | // Test a SPDY CONNECT through an HTTPS Proxy to a SPDY server. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4518 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyConnectSpdy) { |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4519 | SpdyTestUtil spdy_util_wrapped(GetProtocol(), GetDependenciesFromPriority()); |
| 4520 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4521 | HttpRequestInfo request; |
| 4522 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4523 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4524 | request.load_flags = 0; |
| 4525 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4526 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4527 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4528 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4529 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4530 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4531 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4532 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4533 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4534 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4535 | // CONNECT to www.example.org:443 via SPDY |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 4536 | scoped_ptr<SpdyFrame> connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4537 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 4538 | // fetch https://www.example.org/ via SPDY |
| 4539 | const char kMyUrl[] = "https://www.example.org/"; |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4540 | scoped_ptr<SpdyFrame> get( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4541 | spdy_util_wrapped.ConstructSpdyGet(kMyUrl, false, 1, LOWEST)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4542 | scoped_ptr<SpdyFrame> wrapped_get( |
| 4543 | spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
| 4544 | scoped_ptr<SpdyFrame> conn_resp( |
| 4545 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 4546 | scoped_ptr<SpdyFrame> get_resp( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4547 | spdy_util_wrapped.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4548 | scoped_ptr<SpdyFrame> wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4549 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4550 | scoped_ptr<SpdyFrame> body(spdy_util_wrapped.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4551 | scoped_ptr<SpdyFrame> wrapped_body( |
| 4552 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4553 | scoped_ptr<SpdyFrame> window_update_get_resp( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 4554 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp->size())); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4555 | scoped_ptr<SpdyFrame> window_update_body( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 4556 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body->size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 4557 | |
| 4558 | MockWrite spdy_writes[] = { |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4559 | CreateMockWrite(*connect, 0), |
| 4560 | CreateMockWrite(*wrapped_get, 2), |
| 4561 | CreateMockWrite(*window_update_get_resp, 6), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 4562 | CreateMockWrite(*window_update_body, 7), |
| 4563 | }; |
| 4564 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4565 | MockRead spdy_reads[] = { |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4566 | CreateMockRead(*conn_resp, 1, ASYNC), |
| 4567 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4568 | CreateMockRead(*wrapped_get_resp, 4, ASYNC), |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4569 | CreateMockRead(*wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4570 | MockRead(ASYNC, 0, 8), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4571 | }; |
| 4572 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4573 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4574 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4575 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4576 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4577 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4578 | ssl.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4579 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4580 | SSLSocketDataProvider ssl2(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4581 | ssl2.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4582 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4583 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4584 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4585 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4586 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4587 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4588 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4589 | // Allow the SpdyProxyClientSocket's write callback to complete. |
| 4590 | base::MessageLoop::current()->RunUntilIdle(); |
| 4591 | // Now allow the read of the response to complete. |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 4592 | spdy_data.Resume(); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4593 | rv = callback1.WaitForResult(); |
| 4594 | EXPECT_EQ(OK, rv); |
| 4595 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4596 | LoadTimingInfo load_timing_info; |
| 4597 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4598 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4599 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4600 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4601 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4602 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 4603 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4604 | |
| 4605 | std::string response_data; |
| 4606 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 4607 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4608 | } |
| 4609 | |
| 4610 | // Test a SPDY CONNECT failure through an HTTPS Proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4611 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyConnectFailure) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4612 | HttpRequestInfo request; |
| 4613 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4614 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4615 | request.load_flags = 0; |
| 4616 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4617 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4618 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4619 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4620 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4621 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4622 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4623 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4624 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4625 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4626 | // CONNECT to www.example.org:443 via SPDY |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 4627 | scoped_ptr<SpdyFrame> connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4628 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 4629 | scoped_ptr<SpdyFrame> get( |
| 4630 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4631 | |
| 4632 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4633 | CreateMockWrite(*connect, 0), CreateMockWrite(*get, 2), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4634 | }; |
| 4635 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4636 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdySynReplyError(1)); |
| 4637 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4638 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4639 | CreateMockRead(*resp, 1, ASYNC), MockRead(ASYNC, 0, 3), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4640 | }; |
| 4641 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4642 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4643 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4644 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4645 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4646 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4647 | ssl.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4648 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4649 | SSLSocketDataProvider ssl2(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4650 | ssl2.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4651 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4652 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4653 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4654 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4655 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4656 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4657 | |
| 4658 | rv = callback1.WaitForResult(); |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 4659 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4660 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 4661 | // TODO(ttuttle): Anything else to check here? |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4662 | } |
| 4663 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4664 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 4665 | // HTTPS Proxy to different servers. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4666 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4667 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsTwoServers) { |
| 4668 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4669 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4670 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4671 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4672 | scoped_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4673 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4674 | |
| 4675 | HttpRequestInfo request1; |
| 4676 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4677 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4678 | request1.load_flags = 0; |
| 4679 | |
| 4680 | HttpRequestInfo request2; |
| 4681 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4682 | request2.url = GURL("https://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4683 | request2.load_flags = 0; |
| 4684 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4685 | // CONNECT to www.example.org:443 via SPDY. |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 4686 | scoped_ptr<SpdyFrame> connect1(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4687 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4688 | scoped_ptr<SpdyFrame> conn_resp1( |
| 4689 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4690 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4691 | // Fetch https://www.example.org/ via HTTP. |
| 4692 | const char get1[] = |
| 4693 | "GET / HTTP/1.1\r\n" |
| 4694 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4695 | "Connection: keep-alive\r\n\r\n"; |
| 4696 | scoped_ptr<SpdyFrame> wrapped_get1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4697 | spdy_util_.ConstructSpdyBodyFrame(1, get1, strlen(get1), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4698 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 4699 | "Content-Length: 1\r\n\r\n"; |
| 4700 | scoped_ptr<SpdyFrame> wrapped_get_resp1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4701 | spdy_util_.ConstructSpdyBodyFrame(1, resp1, strlen(resp1), false)); |
| 4702 | scoped_ptr<SpdyFrame> wrapped_body1( |
| 4703 | spdy_util_.ConstructSpdyBodyFrame(1, "1", 1, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4704 | scoped_ptr<SpdyFrame> window_update( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 4705 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1->size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4706 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4707 | // CONNECT to mail.example.org:443 via SPDY. |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 4708 | SpdyHeaderBlock connect2_block; |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 4709 | spdy_util_.MaybeAddVersionHeader(&connect2_block); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 4710 | connect2_block[spdy_util_.GetMethodKey()] = "CONNECT"; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4711 | if (GetProtocol() == kProtoHTTP2) { |
bnc | 6b996d53 | 2015-07-29 10:51:32 | [diff] [blame] | 4712 | connect2_block[spdy_util_.GetHostKey()] = "mail.example.org:443"; |
| 4713 | } else { |
bnc | 6b996d53 | 2015-07-29 10:51:32 | [diff] [blame] | 4714 | connect2_block[spdy_util_.GetHostKey()] = "mail.example.org"; |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 4715 | connect2_block[spdy_util_.GetPathKey()] = "mail.example.org:443"; |
bnc | 6b996d53 | 2015-07-29 10:51:32 | [diff] [blame] | 4716 | } |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4717 | scoped_ptr<SpdyFrame> connect2( |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 4718 | spdy_util_.ConstructSpdySyn(3, connect2_block, LOWEST, false, false)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 4719 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4720 | scoped_ptr<SpdyFrame> conn_resp2( |
| 4721 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4722 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4723 | // Fetch https://mail.example.org/ via HTTP. |
| 4724 | const char get2[] = |
| 4725 | "GET / HTTP/1.1\r\n" |
| 4726 | "Host: mail.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4727 | "Connection: keep-alive\r\n\r\n"; |
| 4728 | scoped_ptr<SpdyFrame> wrapped_get2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4729 | spdy_util_.ConstructSpdyBodyFrame(3, get2, strlen(get2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4730 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 4731 | "Content-Length: 2\r\n\r\n"; |
| 4732 | scoped_ptr<SpdyFrame> wrapped_get_resp2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4733 | spdy_util_.ConstructSpdyBodyFrame(3, resp2, strlen(resp2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4734 | scoped_ptr<SpdyFrame> wrapped_body2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4735 | spdy_util_.ConstructSpdyBodyFrame(3, "22", 2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4736 | |
| 4737 | MockWrite spdy_writes[] = { |
| 4738 | CreateMockWrite(*connect1, 0), |
| 4739 | CreateMockWrite(*wrapped_get1, 2), |
| 4740 | CreateMockWrite(*connect2, 5), |
| 4741 | CreateMockWrite(*wrapped_get2, 7), |
| 4742 | }; |
| 4743 | |
| 4744 | MockRead spdy_reads[] = { |
| 4745 | CreateMockRead(*conn_resp1, 1, ASYNC), |
| 4746 | CreateMockRead(*wrapped_get_resp1, 3, ASYNC), |
| 4747 | CreateMockRead(*wrapped_body1, 4, ASYNC), |
| 4748 | CreateMockRead(*conn_resp2, 6, ASYNC), |
| 4749 | CreateMockRead(*wrapped_get_resp2, 8, ASYNC), |
| 4750 | CreateMockRead(*wrapped_body2, 9, ASYNC), |
| 4751 | MockRead(ASYNC, 0, 10), |
| 4752 | }; |
| 4753 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4754 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4755 | arraysize(spdy_writes)); |
| 4756 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4757 | |
| 4758 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4759 | ssl.SetNextProto(GetProtocol()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4760 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4761 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4762 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4763 | SSLSocketDataProvider ssl3(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4764 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4765 | |
| 4766 | TestCompletionCallback callback; |
| 4767 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4768 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4769 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4770 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4771 | EXPECT_EQ(OK, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4772 | |
| 4773 | LoadTimingInfo load_timing_info; |
| 4774 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4775 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4776 | |
| 4777 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4778 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4779 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4780 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4781 | |
| 4782 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 4783 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4784 | rv = trans->Read(buf.get(), 256, callback.callback()); |
| 4785 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4786 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4787 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4788 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4789 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4790 | EXPECT_EQ(OK, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4791 | |
| 4792 | LoadTimingInfo load_timing_info2; |
| 4793 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4794 | // Even though the SPDY connection is reused, a new tunnelled connection has |
| 4795 | // to be created, so the socket's load timing looks like a fresh connection. |
| 4796 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4797 | |
| 4798 | // The requests should have different IDs, since they each are using their own |
| 4799 | // separate stream. |
| 4800 | EXPECT_NE(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 4801 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4802 | rv = trans2->Read(buf.get(), 256, callback.callback()); |
| 4803 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4804 | } |
| 4805 | |
| 4806 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 4807 | // HTTPS Proxy to the same server. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4808 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4809 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsSameServer) { |
| 4810 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4811 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4812 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4813 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4814 | scoped_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4815 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4816 | |
| 4817 | HttpRequestInfo request1; |
| 4818 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4819 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4820 | request1.load_flags = 0; |
| 4821 | |
| 4822 | HttpRequestInfo request2; |
| 4823 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4824 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4825 | request2.load_flags = 0; |
| 4826 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4827 | // CONNECT to www.example.org:443 via SPDY. |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 4828 | scoped_ptr<SpdyFrame> connect1(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4829 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4830 | scoped_ptr<SpdyFrame> conn_resp1( |
| 4831 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4832 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4833 | // Fetch https://www.example.org/ via HTTP. |
| 4834 | const char get1[] = |
| 4835 | "GET / HTTP/1.1\r\n" |
| 4836 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4837 | "Connection: keep-alive\r\n\r\n"; |
| 4838 | scoped_ptr<SpdyFrame> wrapped_get1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4839 | spdy_util_.ConstructSpdyBodyFrame(1, get1, strlen(get1), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4840 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 4841 | "Content-Length: 1\r\n\r\n"; |
| 4842 | scoped_ptr<SpdyFrame> wrapped_get_resp1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4843 | spdy_util_.ConstructSpdyBodyFrame(1, resp1, strlen(resp1), false)); |
| 4844 | scoped_ptr<SpdyFrame> wrapped_body1( |
| 4845 | spdy_util_.ConstructSpdyBodyFrame(1, "1", 1, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4846 | scoped_ptr<SpdyFrame> window_update( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 4847 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1->size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4848 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4849 | // Fetch https://www.example.org/2 via HTTP. |
| 4850 | const char get2[] = |
| 4851 | "GET /2 HTTP/1.1\r\n" |
| 4852 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4853 | "Connection: keep-alive\r\n\r\n"; |
| 4854 | scoped_ptr<SpdyFrame> wrapped_get2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4855 | spdy_util_.ConstructSpdyBodyFrame(1, get2, strlen(get2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4856 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 4857 | "Content-Length: 2\r\n\r\n"; |
| 4858 | scoped_ptr<SpdyFrame> wrapped_get_resp2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4859 | spdy_util_.ConstructSpdyBodyFrame(1, resp2, strlen(resp2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4860 | scoped_ptr<SpdyFrame> wrapped_body2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4861 | spdy_util_.ConstructSpdyBodyFrame(1, "22", 2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4862 | |
| 4863 | MockWrite spdy_writes[] = { |
| 4864 | CreateMockWrite(*connect1, 0), |
| 4865 | CreateMockWrite(*wrapped_get1, 2), |
| 4866 | CreateMockWrite(*wrapped_get2, 5), |
| 4867 | }; |
| 4868 | |
| 4869 | MockRead spdy_reads[] = { |
| 4870 | CreateMockRead(*conn_resp1, 1, ASYNC), |
| 4871 | CreateMockRead(*wrapped_get_resp1, 3, ASYNC), |
| 4872 | CreateMockRead(*wrapped_body1, 4, ASYNC), |
| 4873 | CreateMockRead(*wrapped_get_resp2, 6, ASYNC), |
| 4874 | CreateMockRead(*wrapped_body2, 7, ASYNC), |
| 4875 | MockRead(ASYNC, 0, 8), |
| 4876 | }; |
| 4877 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4878 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4879 | arraysize(spdy_writes)); |
| 4880 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4881 | |
| 4882 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4883 | ssl.SetNextProto(GetProtocol()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4884 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4885 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4886 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4887 | |
| 4888 | TestCompletionCallback callback; |
| 4889 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4890 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4891 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4892 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
| 4893 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4894 | |
| 4895 | rv = callback.WaitForResult(); |
| 4896 | EXPECT_EQ(OK, rv); |
| 4897 | |
| 4898 | LoadTimingInfo load_timing_info; |
| 4899 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4900 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4901 | |
| 4902 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4903 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4904 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4905 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4906 | |
| 4907 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 4908 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4909 | EXPECT_EQ(1, trans->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4910 | trans.reset(); |
| 4911 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4912 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4913 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4914 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
| 4915 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4916 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4917 | rv = callback.WaitForResult(); |
| 4918 | EXPECT_EQ(OK, rv); |
| 4919 | |
| 4920 | LoadTimingInfo load_timing_info2; |
| 4921 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4922 | TestLoadTimingReused(load_timing_info2); |
| 4923 | |
| 4924 | // The requests should have the same ID. |
| 4925 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 4926 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4927 | EXPECT_EQ(2, trans2->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4928 | } |
| 4929 | |
| 4930 | // Test load timing in the case of of two HTTP requests through a SPDY HTTPS |
| 4931 | // Proxy to different servers. |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4932 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyLoadTimingTwoHttpRequests) { |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4933 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4934 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4935 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4936 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4937 | scoped_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4938 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4939 | |
| 4940 | HttpRequestInfo request1; |
| 4941 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4942 | request1.url = GURL("http://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4943 | request1.load_flags = 0; |
| 4944 | |
| 4945 | HttpRequestInfo request2; |
| 4946 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4947 | request2.url = GURL("http://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4948 | request2.load_flags = 0; |
| 4949 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4950 | // http://www.example.org/ |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4951 | scoped_ptr<SpdyHeaderBlock> headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4952 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 4953 | scoped_ptr<SpdyFrame> get1( |
| 4954 | spdy_util_.ConstructSpdySyn(1, *headers, LOWEST, false, true)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4955 | scoped_ptr<SpdyFrame> get_resp1( |
| 4956 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 4957 | scoped_ptr<SpdyFrame> body1( |
| 4958 | spdy_util_.ConstructSpdyBodyFrame(1, "1", 1, true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4959 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4960 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4961 | // http://mail.example.org/ |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4962 | scoped_ptr<SpdyHeaderBlock> headers2( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4963 | spdy_util_.ConstructGetHeaderBlockForProxy("http://mail.example.org/")); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 4964 | scoped_ptr<SpdyFrame> get2( |
| 4965 | spdy_util_.ConstructSpdySyn(3, *headers2, LOWEST, false, true)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4966 | scoped_ptr<SpdyFrame> get_resp2( |
| 4967 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 4968 | scoped_ptr<SpdyFrame> body2( |
| 4969 | spdy_util_.ConstructSpdyBodyFrame(3, "22", 2, true)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4970 | |
| 4971 | MockWrite spdy_writes[] = { |
| 4972 | CreateMockWrite(*get1, 0), |
| 4973 | CreateMockWrite(*get2, 3), |
| 4974 | }; |
| 4975 | |
| 4976 | MockRead spdy_reads[] = { |
| 4977 | CreateMockRead(*get_resp1, 1, ASYNC), |
| 4978 | CreateMockRead(*body1, 2, ASYNC), |
| 4979 | CreateMockRead(*get_resp2, 4, ASYNC), |
| 4980 | CreateMockRead(*body2, 5, ASYNC), |
| 4981 | MockRead(ASYNC, 0, 6), |
| 4982 | }; |
| 4983 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4984 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4985 | arraysize(spdy_writes)); |
| 4986 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4987 | |
| 4988 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4989 | ssl.SetNextProto(GetProtocol()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4990 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4991 | |
| 4992 | TestCompletionCallback callback; |
| 4993 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4994 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4995 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4996 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4997 | EXPECT_EQ(OK, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4998 | |
| 4999 | LoadTimingInfo load_timing_info; |
| 5000 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 5001 | TestLoadTimingNotReused(load_timing_info, |
| 5002 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5003 | |
| 5004 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5005 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5006 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5007 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5008 | |
| 5009 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5010 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5011 | rv = trans->Read(buf.get(), 256, callback.callback()); |
| 5012 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5013 | // Delete the first request, so the second one can reuse the socket. |
| 5014 | trans.reset(); |
| 5015 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5016 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5017 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5018 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5019 | EXPECT_EQ(OK, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5020 | |
| 5021 | LoadTimingInfo load_timing_info2; |
| 5022 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 5023 | TestLoadTimingReused(load_timing_info2); |
| 5024 | |
| 5025 | // The requests should have the same ID. |
| 5026 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 5027 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5028 | rv = trans2->Read(buf.get(), 256, callback.callback()); |
| 5029 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5030 | } |
| 5031 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5032 | // Test the challenge-response-retry sequence through an HTTPS Proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5033 | TEST_P(HttpNetworkTransactionTest, HttpsProxyAuthRetry) { |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5034 | HttpRequestInfo request; |
| 5035 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5036 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5037 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5038 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5039 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5040 | // Configure against https proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5041 | session_deps_.proxy_service = ProxyService::CreateFixed("https://myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5042 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5043 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 5044 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5045 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5046 | // Since we have proxy, should use full url |
| 5047 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5048 | MockWrite( |
| 5049 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5050 | "Host: www.example.org\r\n" |
| 5051 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5052 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5053 | // After calling trans->RestartWithAuth(), this is the request we should |
| 5054 | // be issuing -- the final header line contains the credentials. |
| 5055 | MockWrite( |
| 5056 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5057 | "Host: www.example.org\r\n" |
| 5058 | "Proxy-Connection: keep-alive\r\n" |
| 5059 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5060 | }; |
| 5061 | |
| 5062 | // The proxy responds to the GET with a 407, using a persistent |
| 5063 | // connection. |
| 5064 | MockRead data_reads1[] = { |
| 5065 | // No credentials. |
| 5066 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 5067 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5068 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 5069 | MockRead("Content-Length: 0\r\n\r\n"), |
| 5070 | |
| 5071 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5072 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5073 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5074 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5075 | }; |
| 5076 | |
| 5077 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5078 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5079 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5080 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5081 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5082 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5083 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5084 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5085 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5086 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5087 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5088 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5089 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5090 | |
| 5091 | rv = callback1.WaitForResult(); |
| 5092 | EXPECT_EQ(OK, rv); |
| 5093 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5094 | LoadTimingInfo load_timing_info; |
| 5095 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 5096 | TestLoadTimingNotReused(load_timing_info, |
| 5097 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5098 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5099 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5100 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5101 | ASSERT_FALSE(response->headers.get() == NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5102 | EXPECT_EQ(407, response->headers->response_code()); |
| 5103 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5104 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5105 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5106 | TestCompletionCallback callback2; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5107 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5108 | rv = trans->RestartWithAuth( |
| 5109 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5110 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5111 | |
| 5112 | rv = callback2.WaitForResult(); |
| 5113 | EXPECT_EQ(OK, rv); |
| 5114 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5115 | load_timing_info = LoadTimingInfo(); |
| 5116 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 5117 | // Retrying with HTTP AUTH is considered to be reusing a socket. |
| 5118 | TestLoadTimingReused(load_timing_info); |
| 5119 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5120 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5121 | ASSERT_TRUE(response != NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5122 | |
| 5123 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 5124 | EXPECT_EQ(200, response->headers->response_code()); |
| 5125 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5126 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 5127 | |
| 5128 | // The password prompt info should not be set. |
| 5129 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5130 | } |
| 5131 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5132 | void HttpNetworkTransactionTest::ConnectStatusHelperWithExpectedStatus( |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5133 | const MockRead& status, int expected_status) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5134 | HttpRequestInfo request; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5135 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5136 | request.url = GURL("https://www.example.org/"); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5137 | request.load_flags = 0; |
| 5138 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5139 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5140 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 5141 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5142 | |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5143 | // Since we have proxy, should try to establish tunnel. |
| 5144 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5145 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5146 | "Host: www.example.org:443\r\n" |
| 5147 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5148 | }; |
| 5149 | |
| 5150 | MockRead data_reads[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 5151 | status, MockRead("Content-Length: 10\r\n\r\n"), |
| 5152 | // No response body because the test stops reading here. |
| 5153 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5154 | }; |
| 5155 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5156 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 5157 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5158 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5159 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5160 | TestCompletionCallback callback; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5161 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5162 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5163 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5164 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5165 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5166 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5167 | |
| 5168 | rv = callback.WaitForResult(); |
| 5169 | EXPECT_EQ(expected_status, rv); |
| 5170 | } |
| 5171 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5172 | void HttpNetworkTransactionTest::ConnectStatusHelper( |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5173 | const MockRead& status) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5174 | ConnectStatusHelperWithExpectedStatus( |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5175 | status, ERR_TUNNEL_CONNECTION_FAILED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5176 | } |
| 5177 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5178 | TEST_P(HttpNetworkTransactionTest, ConnectStatus100) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5179 | ConnectStatusHelper(MockRead("HTTP/1.1 100 Continue\r\n")); |
| 5180 | } |
| 5181 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5182 | TEST_P(HttpNetworkTransactionTest, ConnectStatus101) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5183 | ConnectStatusHelper(MockRead("HTTP/1.1 101 Switching Protocols\r\n")); |
| 5184 | } |
| 5185 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5186 | TEST_P(HttpNetworkTransactionTest, ConnectStatus201) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5187 | ConnectStatusHelper(MockRead("HTTP/1.1 201 Created\r\n")); |
| 5188 | } |
| 5189 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5190 | TEST_P(HttpNetworkTransactionTest, ConnectStatus202) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5191 | ConnectStatusHelper(MockRead("HTTP/1.1 202 Accepted\r\n")); |
| 5192 | } |
| 5193 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5194 | TEST_P(HttpNetworkTransactionTest, ConnectStatus203) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5195 | ConnectStatusHelper( |
| 5196 | MockRead("HTTP/1.1 203 Non-Authoritative Information\r\n")); |
| 5197 | } |
| 5198 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5199 | TEST_P(HttpNetworkTransactionTest, ConnectStatus204) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5200 | ConnectStatusHelper(MockRead("HTTP/1.1 204 No Content\r\n")); |
| 5201 | } |
| 5202 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5203 | TEST_P(HttpNetworkTransactionTest, ConnectStatus205) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5204 | ConnectStatusHelper(MockRead("HTTP/1.1 205 Reset Content\r\n")); |
| 5205 | } |
| 5206 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5207 | TEST_P(HttpNetworkTransactionTest, ConnectStatus206) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5208 | ConnectStatusHelper(MockRead("HTTP/1.1 206 Partial Content\r\n")); |
| 5209 | } |
| 5210 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5211 | TEST_P(HttpNetworkTransactionTest, ConnectStatus300) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5212 | ConnectStatusHelper(MockRead("HTTP/1.1 300 Multiple Choices\r\n")); |
| 5213 | } |
| 5214 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5215 | TEST_P(HttpNetworkTransactionTest, ConnectStatus301) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5216 | ConnectStatusHelper(MockRead("HTTP/1.1 301 Moved Permanently\r\n")); |
| 5217 | } |
| 5218 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5219 | TEST_P(HttpNetworkTransactionTest, ConnectStatus302) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5220 | ConnectStatusHelper(MockRead("HTTP/1.1 302 Found\r\n")); |
| 5221 | } |
| 5222 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5223 | TEST_P(HttpNetworkTransactionTest, ConnectStatus303) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5224 | ConnectStatusHelper(MockRead("HTTP/1.1 303 See Other\r\n")); |
| 5225 | } |
| 5226 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5227 | TEST_P(HttpNetworkTransactionTest, ConnectStatus304) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5228 | ConnectStatusHelper(MockRead("HTTP/1.1 304 Not Modified\r\n")); |
| 5229 | } |
| 5230 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5231 | TEST_P(HttpNetworkTransactionTest, ConnectStatus305) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5232 | ConnectStatusHelper(MockRead("HTTP/1.1 305 Use Proxy\r\n")); |
| 5233 | } |
| 5234 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5235 | TEST_P(HttpNetworkTransactionTest, ConnectStatus306) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5236 | ConnectStatusHelper(MockRead("HTTP/1.1 306\r\n")); |
| 5237 | } |
| 5238 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5239 | TEST_P(HttpNetworkTransactionTest, ConnectStatus307) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5240 | ConnectStatusHelper(MockRead("HTTP/1.1 307 Temporary Redirect\r\n")); |
| 5241 | } |
| 5242 | |
[email protected] | 0a17aab3 | 2014-04-24 03:32:37 | [diff] [blame] | 5243 | TEST_P(HttpNetworkTransactionTest, ConnectStatus308) { |
| 5244 | ConnectStatusHelper(MockRead("HTTP/1.1 308 Permanent Redirect\r\n")); |
| 5245 | } |
| 5246 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5247 | TEST_P(HttpNetworkTransactionTest, ConnectStatus400) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5248 | ConnectStatusHelper(MockRead("HTTP/1.1 400 Bad Request\r\n")); |
| 5249 | } |
| 5250 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5251 | TEST_P(HttpNetworkTransactionTest, ConnectStatus401) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5252 | ConnectStatusHelper(MockRead("HTTP/1.1 401 Unauthorized\r\n")); |
| 5253 | } |
| 5254 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5255 | TEST_P(HttpNetworkTransactionTest, ConnectStatus402) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5256 | ConnectStatusHelper(MockRead("HTTP/1.1 402 Payment Required\r\n")); |
| 5257 | } |
| 5258 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5259 | TEST_P(HttpNetworkTransactionTest, ConnectStatus403) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5260 | ConnectStatusHelper(MockRead("HTTP/1.1 403 Forbidden\r\n")); |
| 5261 | } |
| 5262 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5263 | TEST_P(HttpNetworkTransactionTest, ConnectStatus404) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5264 | ConnectStatusHelper(MockRead("HTTP/1.1 404 Not Found\r\n")); |
| 5265 | } |
| 5266 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5267 | TEST_P(HttpNetworkTransactionTest, ConnectStatus405) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5268 | ConnectStatusHelper(MockRead("HTTP/1.1 405 Method Not Allowed\r\n")); |
| 5269 | } |
| 5270 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5271 | TEST_P(HttpNetworkTransactionTest, ConnectStatus406) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5272 | ConnectStatusHelper(MockRead("HTTP/1.1 406 Not Acceptable\r\n")); |
| 5273 | } |
| 5274 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5275 | TEST_P(HttpNetworkTransactionTest, ConnectStatus407) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5276 | ConnectStatusHelperWithExpectedStatus( |
| 5277 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
[email protected] | a7ea883 | 2010-07-12 17:54:54 | [diff] [blame] | 5278 | ERR_PROXY_AUTH_UNSUPPORTED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5279 | } |
| 5280 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5281 | TEST_P(HttpNetworkTransactionTest, ConnectStatus408) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5282 | ConnectStatusHelper(MockRead("HTTP/1.1 408 Request Timeout\r\n")); |
| 5283 | } |
| 5284 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5285 | TEST_P(HttpNetworkTransactionTest, ConnectStatus409) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5286 | ConnectStatusHelper(MockRead("HTTP/1.1 409 Conflict\r\n")); |
| 5287 | } |
| 5288 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5289 | TEST_P(HttpNetworkTransactionTest, ConnectStatus410) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5290 | ConnectStatusHelper(MockRead("HTTP/1.1 410 Gone\r\n")); |
| 5291 | } |
| 5292 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5293 | TEST_P(HttpNetworkTransactionTest, ConnectStatus411) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5294 | ConnectStatusHelper(MockRead("HTTP/1.1 411 Length Required\r\n")); |
| 5295 | } |
| 5296 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5297 | TEST_P(HttpNetworkTransactionTest, ConnectStatus412) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5298 | ConnectStatusHelper(MockRead("HTTP/1.1 412 Precondition Failed\r\n")); |
| 5299 | } |
| 5300 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5301 | TEST_P(HttpNetworkTransactionTest, ConnectStatus413) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5302 | ConnectStatusHelper(MockRead("HTTP/1.1 413 Request Entity Too Large\r\n")); |
| 5303 | } |
| 5304 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5305 | TEST_P(HttpNetworkTransactionTest, ConnectStatus414) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5306 | ConnectStatusHelper(MockRead("HTTP/1.1 414 Request-URI Too Long\r\n")); |
| 5307 | } |
| 5308 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5309 | TEST_P(HttpNetworkTransactionTest, ConnectStatus415) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5310 | ConnectStatusHelper(MockRead("HTTP/1.1 415 Unsupported Media Type\r\n")); |
| 5311 | } |
| 5312 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5313 | TEST_P(HttpNetworkTransactionTest, ConnectStatus416) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5314 | ConnectStatusHelper( |
| 5315 | MockRead("HTTP/1.1 416 Requested Range Not Satisfiable\r\n")); |
| 5316 | } |
| 5317 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5318 | TEST_P(HttpNetworkTransactionTest, ConnectStatus417) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5319 | ConnectStatusHelper(MockRead("HTTP/1.1 417 Expectation Failed\r\n")); |
| 5320 | } |
| 5321 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5322 | TEST_P(HttpNetworkTransactionTest, ConnectStatus500) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5323 | ConnectStatusHelper(MockRead("HTTP/1.1 500 Internal Server Error\r\n")); |
| 5324 | } |
| 5325 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5326 | TEST_P(HttpNetworkTransactionTest, ConnectStatus501) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5327 | ConnectStatusHelper(MockRead("HTTP/1.1 501 Not Implemented\r\n")); |
| 5328 | } |
| 5329 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5330 | TEST_P(HttpNetworkTransactionTest, ConnectStatus502) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5331 | ConnectStatusHelper(MockRead("HTTP/1.1 502 Bad Gateway\r\n")); |
| 5332 | } |
| 5333 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5334 | TEST_P(HttpNetworkTransactionTest, ConnectStatus503) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5335 | ConnectStatusHelper(MockRead("HTTP/1.1 503 Service Unavailable\r\n")); |
| 5336 | } |
| 5337 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5338 | TEST_P(HttpNetworkTransactionTest, ConnectStatus504) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5339 | ConnectStatusHelper(MockRead("HTTP/1.1 504 Gateway Timeout\r\n")); |
| 5340 | } |
| 5341 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5342 | TEST_P(HttpNetworkTransactionTest, ConnectStatus505) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5343 | ConnectStatusHelper(MockRead("HTTP/1.1 505 HTTP Version Not Supported\r\n")); |
| 5344 | } |
| 5345 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5346 | // Test the flow when both the proxy server AND origin server require |
| 5347 | // authentication. Again, this uses basic auth for both since that is |
| 5348 | // the simplest to mock. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5349 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyThenServer) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5350 | HttpRequestInfo request; |
| 5351 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5352 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5353 | request.load_flags = 0; |
| 5354 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5355 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5356 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 5357 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 5358 | |
| 5359 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 5360 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5361 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5362 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5363 | MockWrite( |
| 5364 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5365 | "Host: www.example.org\r\n" |
| 5366 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5367 | }; |
| 5368 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5369 | MockRead data_reads1[] = { |
| 5370 | MockRead("HTTP/1.0 407 Unauthorized\r\n"), |
| 5371 | // Give a couple authenticate options (only the middle one is actually |
| 5372 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 5373 | MockRead("Proxy-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5374 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5375 | MockRead("Proxy-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 5376 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5377 | // Large content-length -- won't matter, as connection will be reset. |
| 5378 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5379 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5380 | }; |
| 5381 | |
| 5382 | // After calling trans->RestartWithAuth() the first time, this is the |
| 5383 | // request we should be issuing -- the final header line contains the |
| 5384 | // proxy's credentials. |
| 5385 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5386 | MockWrite( |
| 5387 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5388 | "Host: www.example.org\r\n" |
| 5389 | "Proxy-Connection: keep-alive\r\n" |
| 5390 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5391 | }; |
| 5392 | |
| 5393 | // Now the proxy server lets the request pass through to origin server. |
| 5394 | // The origin server responds with a 401. |
| 5395 | MockRead data_reads2[] = { |
| 5396 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5397 | // Note: We are using the same realm-name as the proxy server. This is |
| 5398 | // completely valid, as realms are unique across hosts. |
| 5399 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5400 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5401 | MockRead("Content-Length: 2000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5402 | MockRead(SYNCHRONOUS, ERR_FAILED), // Won't be reached. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5403 | }; |
| 5404 | |
| 5405 | // After calling trans->RestartWithAuth() the second time, we should send |
| 5406 | // the credentials for both the proxy and origin server. |
| 5407 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5408 | MockWrite( |
| 5409 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5410 | "Host: www.example.org\r\n" |
| 5411 | "Proxy-Connection: keep-alive\r\n" |
| 5412 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n" |
| 5413 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5414 | }; |
| 5415 | |
| 5416 | // Lastly we get the desired content. |
| 5417 | MockRead data_reads3[] = { |
| 5418 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5419 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5420 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5421 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5422 | }; |
| 5423 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5424 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5425 | data_writes1, arraysize(data_writes1)); |
| 5426 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5427 | data_writes2, arraysize(data_writes2)); |
| 5428 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 5429 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5430 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5431 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 5432 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5433 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5434 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5435 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5436 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5437 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5438 | |
| 5439 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5440 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5441 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5442 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5443 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5444 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5445 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5446 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5447 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5448 | rv = trans->RestartWithAuth( |
| 5449 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5450 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5451 | |
| 5452 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5453 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5454 | |
| 5455 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5456 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5457 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5458 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5459 | TestCompletionCallback callback3; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5460 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5461 | rv = trans->RestartWithAuth( |
| 5462 | AuthCredentials(kFoo2, kBar2), callback3.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5463 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5464 | |
| 5465 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5466 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5467 | |
| 5468 | response = trans->GetResponseInfo(); |
| 5469 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5470 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5471 | } |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5472 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 5473 | // For the NTLM implementation using SSPI, we skip the NTLM tests since we |
| 5474 | // can't hook into its internals to cause it to generate predictable NTLM |
| 5475 | // authorization headers. |
| 5476 | #if defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5477 | // The NTLM authentication unit tests were generated by capturing the HTTP |
| 5478 | // requests and responses using Fiddler 2 and inspecting the generated random |
| 5479 | // bytes in the debugger. |
| 5480 | |
| 5481 | // Enter the correct password and authenticate successfully. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5482 | TEST_P(HttpNetworkTransactionTest, NTLMAuth1) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5483 | HttpRequestInfo request; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5484 | request.method = "GET"; |
| 5485 | request.url = GURL("http://172.22.68.17/kids/login.aspx"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 5486 | |
| 5487 | // Ensure load is not disrupted by flags which suppress behaviour specific |
| 5488 | // to other auth schemes. |
| 5489 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5490 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5491 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom1, |
| 5492 | MockGetHostName); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 5493 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5494 | |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5495 | MockWrite data_writes1[] = { |
| 5496 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5497 | "Host: 172.22.68.17\r\n" |
| 5498 | "Connection: keep-alive\r\n\r\n"), |
| 5499 | }; |
| 5500 | |
| 5501 | MockRead data_reads1[] = { |
| 5502 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 5503 | // Negotiate and NTLM are often requested together. However, we only want |
| 5504 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 5505 | // the header that requests Negotiate for this test. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5506 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 5507 | MockRead("Connection: close\r\n"), |
| 5508 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 5509 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5510 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5511 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5512 | }; |
| 5513 | |
| 5514 | MockWrite data_writes2[] = { |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5515 | // After restarting with a null identity, this is the |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5516 | // request we should be issuing -- the final header line contains a Type |
| 5517 | // 1 message. |
| 5518 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5519 | "Host: 172.22.68.17\r\n" |
| 5520 | "Connection: keep-alive\r\n" |
| 5521 | "Authorization: NTLM " |
| 5522 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
| 5523 | |
| 5524 | // After calling trans->RestartWithAuth(), we should send a Type 3 message |
| 5525 | // (the credentials for the origin server). The second request continues |
| 5526 | // on the same connection. |
| 5527 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5528 | "Host: 172.22.68.17\r\n" |
| 5529 | "Connection: keep-alive\r\n" |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5530 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 5531 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 5532 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwBVKW" |
| 5533 | "Yma5xzVAAAAAAAAAAAAAAAAAAAAACH+gWcm+YsP9Tqb9zCR3WAeZZX" |
| 5534 | "ahlhx5I=\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5535 | }; |
| 5536 | |
| 5537 | MockRead data_reads2[] = { |
| 5538 | // The origin server responds with a Type 2 message. |
| 5539 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 5540 | MockRead("WWW-Authenticate: NTLM " |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5541 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCjGpMpPGlYKkAAAAAAAAAALo" |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5542 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 5543 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 5544 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 5545 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 5546 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 5547 | "BtAAAAAAA=\r\n"), |
| 5548 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 5549 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5550 | MockRead("You are not authorized to view this page\r\n"), |
| 5551 | |
| 5552 | // Lastly we get the desired content. |
| 5553 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5554 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 5555 | MockRead("Content-Length: 13\r\n\r\n"), |
| 5556 | MockRead("Please Login\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5557 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5558 | }; |
| 5559 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5560 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5561 | data_writes1, arraysize(data_writes1)); |
| 5562 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5563 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5564 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5565 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5566 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5567 | TestCompletionCallback callback1; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5568 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5569 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5570 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5571 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5572 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5573 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5574 | |
| 5575 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5576 | EXPECT_EQ(OK, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5577 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5578 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5579 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5580 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5581 | ASSERT_FALSE(response == NULL); |
| 5582 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5583 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5584 | TestCompletionCallback callback2; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5585 | |
[email protected] | f3cf980 | 2011-10-28 18:44:58 | [diff] [blame] | 5586 | rv = trans->RestartWithAuth(AuthCredentials(kTestingNTLM, kTestingNTLM), |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5587 | callback2.callback()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5588 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5589 | |
| 5590 | rv = callback2.WaitForResult(); |
| 5591 | EXPECT_EQ(OK, rv); |
| 5592 | |
| 5593 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 5594 | |
| 5595 | response = trans->GetResponseInfo(); |
| 5596 | ASSERT_TRUE(response != NULL); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5597 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5598 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5599 | TestCompletionCallback callback3; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5600 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5601 | rv = trans->RestartWithAuth(AuthCredentials(), callback3.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5602 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5603 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5604 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5605 | EXPECT_EQ(OK, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5606 | |
| 5607 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5608 | ASSERT_TRUE(response != NULL); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5609 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5610 | EXPECT_EQ(13, response->headers->GetContentLength()); |
| 5611 | } |
| 5612 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5613 | // Enter a wrong password, and then the correct one. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5614 | TEST_P(HttpNetworkTransactionTest, NTLMAuth2) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5615 | HttpRequestInfo request; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5616 | request.method = "GET"; |
| 5617 | request.url = GURL("http://172.22.68.17/kids/login.aspx"); |
| 5618 | request.load_flags = 0; |
| 5619 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5620 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom2, |
| 5621 | MockGetHostName); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 5622 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5623 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5624 | MockWrite data_writes1[] = { |
| 5625 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5626 | "Host: 172.22.68.17\r\n" |
| 5627 | "Connection: keep-alive\r\n\r\n"), |
| 5628 | }; |
| 5629 | |
| 5630 | MockRead data_reads1[] = { |
| 5631 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 5632 | // Negotiate and NTLM are often requested together. However, we only want |
| 5633 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 5634 | // the header that requests Negotiate for this test. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5635 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 5636 | MockRead("Connection: close\r\n"), |
| 5637 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 5638 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5639 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5640 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5641 | }; |
| 5642 | |
| 5643 | MockWrite data_writes2[] = { |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5644 | // After restarting with a null identity, this is the |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5645 | // request we should be issuing -- the final header line contains a Type |
| 5646 | // 1 message. |
| 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" |
| 5650 | "Authorization: NTLM " |
| 5651 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
| 5652 | |
| 5653 | // After calling trans->RestartWithAuth(), we should send a Type 3 message |
| 5654 | // (the credentials for the origin server). The second request continues |
| 5655 | // on the same connection. |
| 5656 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5657 | "Host: 172.22.68.17\r\n" |
| 5658 | "Connection: keep-alive\r\n" |
| 5659 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 5660 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 5661 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwCWeY" |
| 5662 | "XnSZNwoQAAAAAAAAAAAAAAAAAAAADLa34/phTTKzNTWdub+uyFleOj" |
| 5663 | "4Ww7b7E=\r\n\r\n"), |
| 5664 | }; |
| 5665 | |
| 5666 | MockRead data_reads2[] = { |
| 5667 | // The origin server responds with a Type 2 message. |
| 5668 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 5669 | MockRead("WWW-Authenticate: NTLM " |
| 5670 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCbVWUZezVGpAAAAAAAAAAALo" |
| 5671 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 5672 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 5673 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 5674 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 5675 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 5676 | "BtAAAAAAA=\r\n"), |
| 5677 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 5678 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5679 | MockRead("You are not authorized to view this page\r\n"), |
| 5680 | |
| 5681 | // Wrong password. |
| 5682 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5683 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 5684 | MockRead("Connection: close\r\n"), |
| 5685 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 5686 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5687 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5688 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5689 | }; |
| 5690 | |
| 5691 | MockWrite data_writes3[] = { |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5692 | // After restarting with a null identity, this is the |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5693 | // request we should be issuing -- the final header line contains a Type |
| 5694 | // 1 message. |
| 5695 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5696 | "Host: 172.22.68.17\r\n" |
| 5697 | "Connection: keep-alive\r\n" |
| 5698 | "Authorization: NTLM " |
| 5699 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
| 5700 | |
| 5701 | // After calling trans->RestartWithAuth(), we should send a Type 3 message |
| 5702 | // (the credentials for the origin server). The second request continues |
| 5703 | // on the same connection. |
| 5704 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5705 | "Host: 172.22.68.17\r\n" |
| 5706 | "Connection: keep-alive\r\n" |
| 5707 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 5708 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 5709 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwBO54" |
| 5710 | "dFMVvTHwAAAAAAAAAAAAAAAAAAAACS7sT6Uzw7L0L//WUqlIaVWpbI" |
| 5711 | "+4MUm7c=\r\n\r\n"), |
| 5712 | }; |
| 5713 | |
| 5714 | MockRead data_reads3[] = { |
| 5715 | // The origin server responds with a Type 2 message. |
| 5716 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 5717 | MockRead("WWW-Authenticate: NTLM " |
| 5718 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCL24VN8dgOR8AAAAAAAAAALo" |
| 5719 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 5720 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 5721 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 5722 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 5723 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 5724 | "BtAAAAAAA=\r\n"), |
| 5725 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 5726 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5727 | MockRead("You are not authorized to view this page\r\n"), |
| 5728 | |
| 5729 | // Lastly we get the desired content. |
| 5730 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5731 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 5732 | MockRead("Content-Length: 13\r\n\r\n"), |
| 5733 | MockRead("Please Login\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5734 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5735 | }; |
| 5736 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5737 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5738 | data_writes1, arraysize(data_writes1)); |
| 5739 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5740 | data_writes2, arraysize(data_writes2)); |
| 5741 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 5742 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5743 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5744 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 5745 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5746 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5747 | TestCompletionCallback callback1; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5748 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5749 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5750 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5751 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5752 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5753 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5754 | |
| 5755 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5756 | EXPECT_EQ(OK, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5757 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5758 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5759 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5760 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5761 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5762 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5763 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5764 | TestCompletionCallback callback2; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5765 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5766 | // Enter the wrong password. |
[email protected] | f3cf980 | 2011-10-28 18:44:58 | [diff] [blame] | 5767 | rv = trans->RestartWithAuth(AuthCredentials(kTestingNTLM, kWrongPassword), |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5768 | callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5769 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5770 | |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5771 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5772 | EXPECT_EQ(OK, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5773 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5774 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5775 | TestCompletionCallback callback3; |
| 5776 | rv = trans->RestartWithAuth(AuthCredentials(), callback3.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5777 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5778 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5779 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5780 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5781 | |
| 5782 | response = trans->GetResponseInfo(); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5783 | ASSERT_FALSE(response == NULL); |
| 5784 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5785 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5786 | TestCompletionCallback callback4; |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5787 | |
| 5788 | // Now enter the right password. |
[email protected] | f3cf980 | 2011-10-28 18:44:58 | [diff] [blame] | 5789 | rv = trans->RestartWithAuth(AuthCredentials(kTestingNTLM, kTestingNTLM), |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5790 | callback4.callback()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5791 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5792 | |
| 5793 | rv = callback4.WaitForResult(); |
| 5794 | EXPECT_EQ(OK, rv); |
| 5795 | |
| 5796 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 5797 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5798 | TestCompletionCallback callback5; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5799 | |
| 5800 | // One more roundtrip |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5801 | rv = trans->RestartWithAuth(AuthCredentials(), callback5.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5802 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5803 | |
| 5804 | rv = callback5.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5805 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5806 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5807 | response = trans->GetResponseInfo(); |
| 5808 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5809 | EXPECT_EQ(13, response->headers->GetContentLength()); |
| 5810 | } |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 5811 | #endif // NTLM_PORTABLE |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5812 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5813 | // Test reading a server response which has only headers, and no body. |
| 5814 | // After some maximum number of bytes is consumed, the transaction should |
| 5815 | // fail with ERR_RESPONSE_HEADERS_TOO_BIG. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5816 | TEST_P(HttpNetworkTransactionTest, LargeHeadersNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5817 | HttpRequestInfo request; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5818 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5819 | request.url = GURL("http://www.example.org/"); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5820 | request.load_flags = 0; |
| 5821 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 5822 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5823 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 5824 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5825 | |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 5826 | // Respond with 300 kb of headers (we should fail after 256 kb). |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 5827 | std::string large_headers_string; |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 5828 | FillLargeHeadersString(&large_headers_string, 300 * 1024); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5829 | |
| 5830 | MockRead data_reads[] = { |
| 5831 | MockRead("HTTP/1.0 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5832 | MockRead(ASYNC, large_headers_string.data(), large_headers_string.size()), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5833 | MockRead("\r\nBODY"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5834 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5835 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5836 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5837 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5838 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5839 | TestCompletionCallback callback; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5840 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5841 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5842 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5843 | |
| 5844 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5845 | EXPECT_EQ(ERR_RESPONSE_HEADERS_TOO_BIG, rv); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5846 | } |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5847 | |
| 5848 | // Make sure that we don't try to reuse a TCPClientSocket when failing to |
| 5849 | // establish tunnel. |
| 5850 | // http://code.google.com/p/chromium/issues/detail?id=3772 |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5851 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5852 | DontRecycleTransportSocketForSSLTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5853 | HttpRequestInfo request; |
| 5854 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5855 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5856 | request.load_flags = 0; |
| 5857 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5858 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5859 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | db8f44c | 2008-12-13 04:52:01 | [diff] [blame] | 5860 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 5861 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5862 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5863 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5864 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5865 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5866 | // Since we have proxy, should try to establish tunnel. |
| 5867 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5868 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5869 | "Host: www.example.org:443\r\n" |
| 5870 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5871 | }; |
| 5872 | |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 5873 | // The proxy responds to the connect with a 404, using a persistent |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5874 | // connection. Usually a proxy would return 501 (not implemented), |
| 5875 | // or 200 (tunnel established). |
| 5876 | MockRead data_reads1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 5877 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 5878 | MockRead("Content-Length: 10\r\n\r\n"), |
| 5879 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5880 | }; |
| 5881 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5882 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5883 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5884 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5885 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5886 | TestCompletionCallback callback1; |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5887 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5888 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5889 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5890 | |
| 5891 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5892 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5893 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5894 | // Empty the current queue. This is necessary because idle sockets are |
| 5895 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5896 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5897 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5898 | // We now check to make sure the TCPClientSocket was not added back to |
| 5899 | // the pool. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5900 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5901 | trans.reset(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5902 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5903 | // Make sure that the socket didn't get recycled after calling the destructor. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5904 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5905 | } |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5906 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5907 | // Make sure that we recycle a socket after reading all of the response body. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5908 | TEST_P(HttpNetworkTransactionTest, RecycleSocket) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5909 | HttpRequestInfo request; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5910 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5911 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5912 | request.load_flags = 0; |
| 5913 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 5914 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5915 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5916 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5917 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5918 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5919 | MockRead data_reads[] = { |
| 5920 | // A part of the response body is received with the response headers. |
| 5921 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 5922 | // The rest of the response body is received in two parts. |
| 5923 | MockRead("lo"), |
| 5924 | MockRead(" world"), |
| 5925 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5926 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5927 | }; |
| 5928 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5929 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5930 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5931 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5932 | TestCompletionCallback callback; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5933 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5934 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5935 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5936 | |
| 5937 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5938 | EXPECT_EQ(OK, rv); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5939 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5940 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5941 | ASSERT_TRUE(response != NULL); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5942 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5943 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5944 | std::string status_line = response->headers->GetStatusLine(); |
| 5945 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 5946 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5947 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5948 | |
| 5949 | std::string response_data; |
| 5950 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5951 | EXPECT_EQ(OK, rv); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5952 | EXPECT_EQ("hello world", response_data); |
| 5953 | |
| 5954 | // Empty the current queue. This is necessary because idle sockets are |
| 5955 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5956 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5957 | |
| 5958 | // 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] | 5959 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5960 | } |
| 5961 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5962 | // Make sure that we recycle a SSL socket after reading all of the response |
| 5963 | // body. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5964 | TEST_P(HttpNetworkTransactionTest, RecycleSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5965 | HttpRequestInfo request; |
| 5966 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5967 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5968 | request.load_flags = 0; |
| 5969 | |
| 5970 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5971 | MockWrite( |
| 5972 | "GET / HTTP/1.1\r\n" |
| 5973 | "Host: www.example.org\r\n" |
| 5974 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5975 | }; |
| 5976 | |
| 5977 | MockRead data_reads[] = { |
| 5978 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5979 | MockRead("Content-Length: 11\r\n\r\n"), |
| 5980 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5981 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5982 | }; |
| 5983 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5984 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5985 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5986 | |
| 5987 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 5988 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5989 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5990 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5991 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5992 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 5993 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5994 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5995 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5996 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5997 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5998 | |
| 5999 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6000 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 6001 | |
| 6002 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6003 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6004 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6005 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6006 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6007 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6008 | |
| 6009 | std::string response_data; |
| 6010 | rv = ReadTransaction(trans.get(), &response_data); |
| 6011 | EXPECT_EQ(OK, rv); |
| 6012 | EXPECT_EQ("hello world", response_data); |
| 6013 | |
| 6014 | // Empty the current queue. This is necessary because idle sockets are |
| 6015 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 6016 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6017 | |
| 6018 | // 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] | 6019 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6020 | } |
| 6021 | |
| 6022 | // Grab a SSL socket, use it, and put it back into the pool. Then, reuse it |
| 6023 | // from the pool and make sure that we recover okay. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6024 | TEST_P(HttpNetworkTransactionTest, RecycleDeadSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6025 | HttpRequestInfo request; |
| 6026 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6027 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6028 | request.load_flags = 0; |
| 6029 | |
| 6030 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6031 | MockWrite( |
| 6032 | "GET / HTTP/1.1\r\n" |
| 6033 | "Host: www.example.org\r\n" |
| 6034 | "Connection: keep-alive\r\n\r\n"), |
| 6035 | MockWrite( |
| 6036 | "GET / HTTP/1.1\r\n" |
| 6037 | "Host: www.example.org\r\n" |
| 6038 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6039 | }; |
| 6040 | |
| 6041 | MockRead data_reads[] = { |
mmenke | 911ee022 | 2015-12-04 03:58:42 | [diff] [blame] | 6042 | MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
| 6043 | MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6044 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6045 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 6046 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6047 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 6048 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6049 | |
| 6050 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6051 | data_writes, arraysize(data_writes)); |
| 6052 | StaticSocketDataProvider data2(data_reads, arraysize(data_reads), |
| 6053 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6054 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6055 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6056 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6057 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6058 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 6059 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6060 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6061 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6062 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6063 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6064 | |
| 6065 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6066 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 6067 | |
| 6068 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6069 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6070 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6071 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6072 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6073 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6074 | |
| 6075 | std::string response_data; |
| 6076 | rv = ReadTransaction(trans.get(), &response_data); |
| 6077 | EXPECT_EQ(OK, rv); |
| 6078 | EXPECT_EQ("hello world", response_data); |
| 6079 | |
| 6080 | // Empty the current queue. This is necessary because idle sockets are |
| 6081 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 6082 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6083 | |
| 6084 | // 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] | 6085 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6086 | |
| 6087 | // Now start the second transaction, which should reuse the previous socket. |
| 6088 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6089 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6090 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6091 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6092 | |
| 6093 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6094 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 6095 | |
| 6096 | response = trans->GetResponseInfo(); |
| 6097 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6098 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6099 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6100 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6101 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6102 | |
| 6103 | rv = ReadTransaction(trans.get(), &response_data); |
| 6104 | EXPECT_EQ(OK, rv); |
| 6105 | EXPECT_EQ("hello world", response_data); |
| 6106 | |
| 6107 | // Empty the current queue. This is necessary because idle sockets are |
| 6108 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 6109 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6110 | |
| 6111 | // 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] | 6112 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6113 | } |
| 6114 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6115 | // Make sure that we recycle a socket after a zero-length response. |
| 6116 | // http://crbug.com/9880 |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6117 | TEST_P(HttpNetworkTransactionTest, RecycleSocketAfterZeroContentLength) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6118 | HttpRequestInfo request; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6119 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6120 | request.url = GURL( |
| 6121 | "http://www.example.org/csi?v=3&s=web&action=&" |
| 6122 | "tran=undefined&ei=mAXcSeegAo-SMurloeUN&" |
| 6123 | "e=17259,18167,19592,19773,19981,20133,20173,20233&" |
| 6124 | "rt=prt.2642,ol.2649,xjs.2951"); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6125 | request.load_flags = 0; |
| 6126 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 6127 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6128 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6129 | MockRead data_reads[] = { |
| 6130 | MockRead("HTTP/1.1 204 No Content\r\n" |
| 6131 | "Content-Length: 0\r\n" |
| 6132 | "Content-Type: text/html\r\n\r\n"), |
| 6133 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6134 | MockRead(SYNCHRONOUS, OK), |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6135 | }; |
| 6136 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6137 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6138 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6139 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 6140 | // Transaction must be created after the MockReads, so it's destroyed before |
| 6141 | // them. |
| 6142 | scoped_ptr<HttpTransaction> trans( |
| 6143 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 6144 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6145 | TestCompletionCallback callback; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6146 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6147 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6148 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6149 | |
| 6150 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6151 | EXPECT_EQ(OK, rv); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6152 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6153 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6154 | ASSERT_TRUE(response != NULL); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6155 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6156 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6157 | std::string status_line = response->headers->GetStatusLine(); |
| 6158 | EXPECT_EQ("HTTP/1.1 204 No Content", status_line); |
| 6159 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6160 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6161 | |
| 6162 | std::string response_data; |
| 6163 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6164 | EXPECT_EQ(OK, rv); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6165 | EXPECT_EQ("", response_data); |
| 6166 | |
| 6167 | // Empty the current queue. This is necessary because idle sockets are |
| 6168 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 6169 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6170 | |
| 6171 | // 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] | 6172 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6173 | } |
| 6174 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6175 | TEST_P(HttpNetworkTransactionTest, ResendRequestOnWriteBodyError) { |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 6176 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 6177 | element_readers.push_back( |
| 6178 | make_scoped_ptr(new UploadBytesElementReader("foo", 3))); |
| 6179 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 6180 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6181 | HttpRequestInfo request[2]; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6182 | // Transaction 1: a GET request that succeeds. The socket is recycled |
| 6183 | // after use. |
| 6184 | request[0].method = "GET"; |
| 6185 | request[0].url = GURL("http://www.google.com/"); |
| 6186 | request[0].load_flags = 0; |
| 6187 | // Transaction 2: a POST request. Reuses the socket kept alive from |
| 6188 | // transaction 1. The first attempts fails when writing the POST data. |
| 6189 | // This causes the transaction to retry with a new socket. The second |
| 6190 | // attempt succeeds. |
| 6191 | request[1].method = "POST"; |
| 6192 | request[1].url = GURL("http://www.google.com/login.cgi"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 6193 | request[1].upload_data_stream = &upload_data_stream; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6194 | request[1].load_flags = 0; |
| 6195 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 6196 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6197 | |
| 6198 | // The first socket is used for transaction 1 and the first attempt of |
| 6199 | // transaction 2. |
| 6200 | |
| 6201 | // The response of transaction 1. |
| 6202 | MockRead data_reads1[] = { |
| 6203 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\n"), |
| 6204 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6205 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6206 | }; |
| 6207 | // The mock write results of transaction 1 and the first attempt of |
| 6208 | // transaction 2. |
| 6209 | MockWrite data_writes1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6210 | MockWrite(SYNCHRONOUS, 64), // GET |
| 6211 | MockWrite(SYNCHRONOUS, 93), // POST |
| 6212 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_ABORTED), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6213 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6214 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6215 | data_writes1, arraysize(data_writes1)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6216 | |
| 6217 | // The second socket is used for the second attempt of transaction 2. |
| 6218 | |
| 6219 | // The response of transaction 2. |
| 6220 | MockRead data_reads2[] = { |
| 6221 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 7\r\n\r\n"), |
| 6222 | MockRead("welcome"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6223 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6224 | }; |
| 6225 | // The mock write results of the second attempt of transaction 2. |
| 6226 | MockWrite data_writes2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6227 | MockWrite(SYNCHRONOUS, 93), // POST |
| 6228 | MockWrite(SYNCHRONOUS, 3), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6229 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6230 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6231 | data_writes2, arraysize(data_writes2)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6232 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6233 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6234 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6235 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 6236 | const char* const kExpectedResponseData[] = { |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6237 | "hello world", "welcome" |
| 6238 | }; |
| 6239 | |
| 6240 | for (int i = 0; i < 2; ++i) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6241 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6242 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6243 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6244 | TestCompletionCallback callback; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6245 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6246 | int rv = trans->Start(&request[i], callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6247 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6248 | |
| 6249 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6250 | EXPECT_EQ(OK, rv); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6251 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6252 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6253 | ASSERT_TRUE(response != NULL); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6254 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6255 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6256 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6257 | |
| 6258 | std::string response_data; |
| 6259 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6260 | EXPECT_EQ(OK, rv); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6261 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
| 6262 | } |
| 6263 | } |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6264 | |
| 6265 | // Test the request-challenge-retry sequence for basic auth when there is |
| 6266 | // 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] | 6267 | // it fails the identity from the URL is used to answer the challenge. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6268 | TEST_P(HttpNetworkTransactionTest, AuthIdentityInURL) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6269 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6270 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6271 | request.url = GURL("http://foo:b@[email protected]/"); |
[email protected] | 7b08ba6 | 2012-02-10 20:19:41 | [diff] [blame] | 6272 | request.load_flags = LOAD_NORMAL; |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 6273 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 6274 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6275 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6276 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6277 | |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 6278 | // The password contains an escaped character -- for this test to pass it |
| 6279 | // will need to be unescaped by HttpNetworkTransaction. |
| 6280 | EXPECT_EQ("b%40r", request.url.password()); |
| 6281 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6282 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6283 | MockWrite( |
| 6284 | "GET / HTTP/1.1\r\n" |
| 6285 | "Host: www.example.org\r\n" |
| 6286 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6287 | }; |
| 6288 | |
| 6289 | MockRead data_reads1[] = { |
| 6290 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6291 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6292 | MockRead("Content-Length: 10\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6293 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6294 | }; |
| 6295 | |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6296 | // After the challenge above, the transaction will be restarted using the |
| 6297 | // identity from the url (foo, b@r) to answer the challenge. |
| 6298 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6299 | MockWrite( |
| 6300 | "GET / HTTP/1.1\r\n" |
| 6301 | "Host: www.example.org\r\n" |
| 6302 | "Connection: keep-alive\r\n" |
| 6303 | "Authorization: Basic Zm9vOmJAcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6304 | }; |
| 6305 | |
| 6306 | MockRead data_reads2[] = { |
| 6307 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6308 | MockRead("Content-Length: 100\r\n\r\n"), |
| 6309 | MockRead(SYNCHRONOUS, OK), |
| 6310 | }; |
| 6311 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6312 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6313 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6314 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6315 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6316 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6317 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6318 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6319 | TestCompletionCallback callback1; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6320 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6321 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6322 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6323 | EXPECT_EQ(OK, rv); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6324 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 6325 | |
| 6326 | TestCompletionCallback callback2; |
| 6327 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
| 6328 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6329 | rv = callback2.WaitForResult(); |
| 6330 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6331 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 6332 | |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6333 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6334 | ASSERT_TRUE(response != NULL); |
| 6335 | |
| 6336 | // There is no challenge info, since the identity in URL worked. |
| 6337 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6338 | |
| 6339 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6340 | |
| 6341 | // Empty the current queue. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 6342 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6343 | } |
| 6344 | |
| 6345 | // Test the request-challenge-retry sequence for basic auth when there is an |
| 6346 | // incorrect identity in the URL. The identity from the URL should be used only |
| 6347 | // once. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6348 | TEST_P(HttpNetworkTransactionTest, WrongAuthIdentityInURL) { |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6349 | HttpRequestInfo request; |
| 6350 | request.method = "GET"; |
| 6351 | // Note: the URL has a username:password in it. The password "baz" is |
| 6352 | // wrong (should be "bar"). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6353 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6354 | |
| 6355 | request.load_flags = LOAD_NORMAL; |
| 6356 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 6357 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6358 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6359 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6360 | |
| 6361 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6362 | MockWrite( |
| 6363 | "GET / HTTP/1.1\r\n" |
| 6364 | "Host: www.example.org\r\n" |
| 6365 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6366 | }; |
| 6367 | |
| 6368 | MockRead data_reads1[] = { |
| 6369 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6370 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6371 | MockRead("Content-Length: 10\r\n\r\n"), |
| 6372 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 6373 | }; |
| 6374 | |
| 6375 | // After the challenge above, the transaction will be restarted using the |
| 6376 | // identity from the url (foo, baz) to answer the challenge. |
| 6377 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6378 | MockWrite( |
| 6379 | "GET / HTTP/1.1\r\n" |
| 6380 | "Host: www.example.org\r\n" |
| 6381 | "Connection: keep-alive\r\n" |
| 6382 | "Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6383 | }; |
| 6384 | |
| 6385 | MockRead data_reads2[] = { |
| 6386 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6387 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6388 | MockRead("Content-Length: 10\r\n\r\n"), |
| 6389 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 6390 | }; |
| 6391 | |
| 6392 | // After the challenge above, the transaction will be restarted using the |
| 6393 | // identity supplied by the user (foo, bar) to answer the challenge. |
| 6394 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6395 | MockWrite( |
| 6396 | "GET / HTTP/1.1\r\n" |
| 6397 | "Host: www.example.org\r\n" |
| 6398 | "Connection: keep-alive\r\n" |
| 6399 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6400 | }; |
| 6401 | |
| 6402 | MockRead data_reads3[] = { |
| 6403 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6404 | MockRead("Content-Length: 100\r\n\r\n"), |
| 6405 | MockRead(SYNCHRONOUS, OK), |
| 6406 | }; |
| 6407 | |
| 6408 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6409 | data_writes1, arraysize(data_writes1)); |
| 6410 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6411 | data_writes2, arraysize(data_writes2)); |
| 6412 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 6413 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6414 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6415 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 6416 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6417 | |
| 6418 | TestCompletionCallback callback1; |
| 6419 | |
| 6420 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
| 6421 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6422 | |
| 6423 | rv = callback1.WaitForResult(); |
| 6424 | EXPECT_EQ(OK, rv); |
| 6425 | |
| 6426 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 6427 | TestCompletionCallback callback2; |
| 6428 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
| 6429 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6430 | rv = callback2.WaitForResult(); |
| 6431 | EXPECT_EQ(OK, rv); |
| 6432 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 6433 | |
| 6434 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6435 | ASSERT_TRUE(response != NULL); |
| 6436 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 6437 | |
| 6438 | TestCompletionCallback callback3; |
| 6439 | rv = trans->RestartWithAuth( |
| 6440 | AuthCredentials(kFoo, kBar), callback3.callback()); |
| 6441 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6442 | rv = callback3.WaitForResult(); |
| 6443 | EXPECT_EQ(OK, rv); |
| 6444 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 6445 | |
| 6446 | response = trans->GetResponseInfo(); |
| 6447 | ASSERT_TRUE(response != NULL); |
| 6448 | |
| 6449 | // There is no challenge info, since the identity worked. |
| 6450 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6451 | |
| 6452 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6453 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 6454 | // Empty the current queue. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 6455 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 6456 | } |
| 6457 | |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6458 | |
| 6459 | // Test the request-challenge-retry sequence for basic auth when there is a |
| 6460 | // correct identity in the URL, but its use is being suppressed. The identity |
| 6461 | // from the URL should never be used. |
| 6462 | TEST_P(HttpNetworkTransactionTest, AuthIdentityInURLSuppressed) { |
| 6463 | HttpRequestInfo request; |
| 6464 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6465 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6466 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
| 6467 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 6468 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6469 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6470 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6471 | |
| 6472 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6473 | MockWrite( |
| 6474 | "GET / HTTP/1.1\r\n" |
| 6475 | "Host: www.example.org\r\n" |
| 6476 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6477 | }; |
| 6478 | |
| 6479 | MockRead data_reads1[] = { |
| 6480 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6481 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6482 | MockRead("Content-Length: 10\r\n\r\n"), |
| 6483 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 6484 | }; |
| 6485 | |
| 6486 | // After the challenge above, the transaction will be restarted using the |
| 6487 | // identity supplied by the user, not the one in the URL, to answer the |
| 6488 | // challenge. |
| 6489 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6490 | MockWrite( |
| 6491 | "GET / HTTP/1.1\r\n" |
| 6492 | "Host: www.example.org\r\n" |
| 6493 | "Connection: keep-alive\r\n" |
| 6494 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6495 | }; |
| 6496 | |
| 6497 | MockRead data_reads3[] = { |
| 6498 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6499 | MockRead("Content-Length: 100\r\n\r\n"), |
| 6500 | MockRead(SYNCHRONOUS, OK), |
| 6501 | }; |
| 6502 | |
| 6503 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6504 | data_writes1, arraysize(data_writes1)); |
| 6505 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 6506 | data_writes3, arraysize(data_writes3)); |
| 6507 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6508 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 6509 | |
| 6510 | TestCompletionCallback callback1; |
| 6511 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
| 6512 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6513 | rv = callback1.WaitForResult(); |
| 6514 | EXPECT_EQ(OK, rv); |
| 6515 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 6516 | |
| 6517 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6518 | ASSERT_TRUE(response != NULL); |
| 6519 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 6520 | |
| 6521 | TestCompletionCallback callback3; |
| 6522 | rv = trans->RestartWithAuth( |
| 6523 | AuthCredentials(kFoo, kBar), callback3.callback()); |
| 6524 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6525 | rv = callback3.WaitForResult(); |
| 6526 | EXPECT_EQ(OK, rv); |
| 6527 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 6528 | |
| 6529 | response = trans->GetResponseInfo(); |
| 6530 | ASSERT_TRUE(response != NULL); |
| 6531 | |
| 6532 | // There is no challenge info, since the identity worked. |
| 6533 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6534 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6535 | |
| 6536 | // Empty the current queue. |
| 6537 | base::MessageLoop::current()->RunUntilIdle(); |
| 6538 | } |
| 6539 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6540 | // Test that previously tried username/passwords for a realm get re-used. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6541 | TEST_P(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) { |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 6542 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6543 | |
| 6544 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 6545 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6546 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6547 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6548 | request.url = GURL("http://www.example.org/x/y/z"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6549 | request.load_flags = 0; |
| 6550 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6551 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6552 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6553 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6554 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6555 | MockWrite( |
| 6556 | "GET /x/y/z HTTP/1.1\r\n" |
| 6557 | "Host: www.example.org\r\n" |
| 6558 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6559 | }; |
| 6560 | |
| 6561 | MockRead data_reads1[] = { |
| 6562 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6563 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6564 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6565 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6566 | }; |
| 6567 | |
| 6568 | // Resend with authorization (username=foo, password=bar) |
| 6569 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6570 | MockWrite( |
| 6571 | "GET /x/y/z HTTP/1.1\r\n" |
| 6572 | "Host: www.example.org\r\n" |
| 6573 | "Connection: keep-alive\r\n" |
| 6574 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6575 | }; |
| 6576 | |
| 6577 | // Sever accepts the authorization. |
| 6578 | MockRead data_reads2[] = { |
| 6579 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6580 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6581 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6582 | }; |
| 6583 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6584 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6585 | data_writes1, arraysize(data_writes1)); |
| 6586 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6587 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6588 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6589 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6590 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6591 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6592 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6593 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6594 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6595 | |
| 6596 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6597 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6598 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6599 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6600 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6601 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6602 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6603 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6604 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6605 | rv = trans->RestartWithAuth( |
| 6606 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6607 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6608 | |
| 6609 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6610 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6611 | |
| 6612 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6613 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6614 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6615 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6616 | } |
| 6617 | |
| 6618 | // ------------------------------------------------------------------------ |
| 6619 | |
| 6620 | // Transaction 2: authenticate (foo2, bar2) on MyRealm2 |
| 6621 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6622 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6623 | request.method = "GET"; |
| 6624 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 6625 | // protection space as MyRealm1. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6626 | request.url = GURL("http://www.example.org/x/y/a/b"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6627 | request.load_flags = 0; |
| 6628 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6629 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6630 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6631 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6632 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6633 | MockWrite( |
| 6634 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 6635 | "Host: www.example.org\r\n" |
| 6636 | "Connection: keep-alive\r\n" |
| 6637 | // Send preemptive authorization for MyRealm1 |
| 6638 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6639 | }; |
| 6640 | |
| 6641 | // The server didn't like the preemptive authorization, and |
| 6642 | // challenges us for a different realm (MyRealm2). |
| 6643 | MockRead data_reads1[] = { |
| 6644 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6645 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm2\"\r\n"), |
| 6646 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6647 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6648 | }; |
| 6649 | |
| 6650 | // Resend with authorization for MyRealm2 (username=foo2, password=bar2) |
| 6651 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6652 | MockWrite( |
| 6653 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 6654 | "Host: www.example.org\r\n" |
| 6655 | "Connection: keep-alive\r\n" |
| 6656 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6657 | }; |
| 6658 | |
| 6659 | // Sever accepts the authorization. |
| 6660 | MockRead data_reads2[] = { |
| 6661 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6662 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6663 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6664 | }; |
| 6665 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6666 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6667 | data_writes1, arraysize(data_writes1)); |
| 6668 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6669 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6670 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6671 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6672 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6673 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6674 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6675 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6676 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6677 | |
| 6678 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6679 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6680 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6681 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6682 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6683 | ASSERT_TRUE(response->auth_challenge.get()); |
| 6684 | EXPECT_FALSE(response->auth_challenge->is_proxy); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6685 | EXPECT_EQ("www.example.org:80", |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6686 | response->auth_challenge->challenger.ToString()); |
| 6687 | EXPECT_EQ("MyRealm2", response->auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 6688 | EXPECT_EQ(kBasicAuthScheme, response->auth_challenge->scheme); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6689 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6690 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6691 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6692 | rv = trans->RestartWithAuth( |
| 6693 | AuthCredentials(kFoo2, kBar2), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6694 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6695 | |
| 6696 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6697 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6698 | |
| 6699 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6700 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6701 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6702 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6703 | } |
| 6704 | |
| 6705 | // ------------------------------------------------------------------------ |
| 6706 | |
| 6707 | // Transaction 3: Resend a request in MyRealm's protection space -- |
| 6708 | // succeed with preemptive authorization. |
| 6709 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6710 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6711 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6712 | request.url = GURL("http://www.example.org/x/y/z2"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6713 | request.load_flags = 0; |
| 6714 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6715 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6716 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6717 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6718 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6719 | MockWrite( |
| 6720 | "GET /x/y/z2 HTTP/1.1\r\n" |
| 6721 | "Host: www.example.org\r\n" |
| 6722 | "Connection: keep-alive\r\n" |
| 6723 | // The authorization for MyRealm1 gets sent preemptively |
| 6724 | // (since the url is in the same protection space) |
| 6725 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6726 | }; |
| 6727 | |
| 6728 | // Sever accepts the preemptive authorization |
| 6729 | MockRead data_reads1[] = { |
| 6730 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6731 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6732 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6733 | }; |
| 6734 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6735 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6736 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6737 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6738 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6739 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6740 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6741 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6742 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6743 | |
| 6744 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6745 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6746 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6747 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6748 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6749 | |
| 6750 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6751 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6752 | } |
| 6753 | |
| 6754 | // ------------------------------------------------------------------------ |
| 6755 | |
| 6756 | // Transaction 4: request another URL in MyRealm (however the |
| 6757 | // url is not known to belong to the protection space, so no pre-auth). |
| 6758 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6759 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6760 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6761 | request.url = GURL("http://www.example.org/x/1"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6762 | request.load_flags = 0; |
| 6763 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6764 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6765 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6766 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6767 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6768 | MockWrite( |
| 6769 | "GET /x/1 HTTP/1.1\r\n" |
| 6770 | "Host: www.example.org\r\n" |
| 6771 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6772 | }; |
| 6773 | |
| 6774 | MockRead data_reads1[] = { |
| 6775 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6776 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6777 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6778 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6779 | }; |
| 6780 | |
| 6781 | // Resend with authorization from MyRealm's cache. |
| 6782 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6783 | MockWrite( |
| 6784 | "GET /x/1 HTTP/1.1\r\n" |
| 6785 | "Host: www.example.org\r\n" |
| 6786 | "Connection: keep-alive\r\n" |
| 6787 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6788 | }; |
| 6789 | |
| 6790 | // Sever accepts the authorization. |
| 6791 | MockRead data_reads2[] = { |
| 6792 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6793 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6794 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6795 | }; |
| 6796 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6797 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6798 | data_writes1, arraysize(data_writes1)); |
| 6799 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6800 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6801 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6802 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6803 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6804 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6805 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6806 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6807 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6808 | |
| 6809 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6810 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6811 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6812 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6813 | TestCompletionCallback callback2; |
| 6814 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6815 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6816 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6817 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6818 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 6819 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6820 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6821 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6822 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6823 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6824 | } |
| 6825 | |
| 6826 | // ------------------------------------------------------------------------ |
| 6827 | |
| 6828 | // Transaction 5: request a URL in MyRealm, but the server rejects the |
| 6829 | // cached identity. Should invalidate and re-prompt. |
| 6830 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6831 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6832 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6833 | request.url = GURL("http://www.example.org/p/q/t"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6834 | request.load_flags = 0; |
| 6835 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6836 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6837 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6838 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6839 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6840 | MockWrite( |
| 6841 | "GET /p/q/t HTTP/1.1\r\n" |
| 6842 | "Host: www.example.org\r\n" |
| 6843 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6844 | }; |
| 6845 | |
| 6846 | MockRead data_reads1[] = { |
| 6847 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6848 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6849 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6850 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6851 | }; |
| 6852 | |
| 6853 | // Resend with authorization from cache for MyRealm. |
| 6854 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6855 | MockWrite( |
| 6856 | "GET /p/q/t HTTP/1.1\r\n" |
| 6857 | "Host: www.example.org\r\n" |
| 6858 | "Connection: keep-alive\r\n" |
| 6859 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6860 | }; |
| 6861 | |
| 6862 | // Sever rejects the authorization. |
| 6863 | MockRead data_reads2[] = { |
| 6864 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6865 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6866 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6867 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6868 | }; |
| 6869 | |
| 6870 | // At this point we should prompt for new credentials for MyRealm. |
| 6871 | // Restart with username=foo3, password=foo4. |
| 6872 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6873 | MockWrite( |
| 6874 | "GET /p/q/t HTTP/1.1\r\n" |
| 6875 | "Host: www.example.org\r\n" |
| 6876 | "Connection: keep-alive\r\n" |
| 6877 | "Authorization: Basic Zm9vMzpiYXIz\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6878 | }; |
| 6879 | |
| 6880 | // Sever accepts the authorization. |
| 6881 | MockRead data_reads3[] = { |
| 6882 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6883 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6884 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6885 | }; |
| 6886 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6887 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6888 | data_writes1, arraysize(data_writes1)); |
| 6889 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6890 | data_writes2, arraysize(data_writes2)); |
| 6891 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 6892 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6893 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6894 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 6895 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6896 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6897 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6898 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6899 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6900 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6901 | |
| 6902 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6903 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6904 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6905 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6906 | TestCompletionCallback callback2; |
| 6907 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6908 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6909 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6910 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6911 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 6912 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6913 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6914 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6915 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6916 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6917 | TestCompletionCallback callback3; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6918 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6919 | rv = trans->RestartWithAuth( |
| 6920 | AuthCredentials(kFoo3, kBar3), callback3.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6921 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6922 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6923 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6924 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6925 | |
| 6926 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6927 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6928 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6929 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6930 | } |
| 6931 | } |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6932 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6933 | // Tests that nonce count increments when multiple auth attempts |
| 6934 | // are started with the same nonce. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6935 | TEST_P(HttpNetworkTransactionTest, DigestPreAuthNonceCount) { |
[email protected] | 54fea256 | 2010-11-17 14:40:44 | [diff] [blame] | 6936 | HttpAuthHandlerDigest::Factory* digest_factory = |
| 6937 | new HttpAuthHandlerDigest::Factory(); |
| 6938 | HttpAuthHandlerDigest::FixedNonceGenerator* nonce_generator = |
| 6939 | new HttpAuthHandlerDigest::FixedNonceGenerator("0123456789abcdef"); |
| 6940 | digest_factory->set_nonce_generator(nonce_generator); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6941 | session_deps_.http_auth_handler_factory.reset(digest_factory); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 6942 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6943 | |
| 6944 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 6945 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6946 | HttpRequestInfo request; |
| 6947 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6948 | request.url = GURL("http://www.example.org/x/y/z"); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6949 | request.load_flags = 0; |
| 6950 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6951 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6952 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6953 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6954 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6955 | MockWrite( |
| 6956 | "GET /x/y/z HTTP/1.1\r\n" |
| 6957 | "Host: www.example.org\r\n" |
| 6958 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6959 | }; |
| 6960 | |
| 6961 | MockRead data_reads1[] = { |
| 6962 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6963 | MockRead("WWW-Authenticate: Digest realm=\"digestive\", nonce=\"OU812\", " |
| 6964 | "algorithm=MD5, qop=\"auth\"\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6965 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6966 | }; |
| 6967 | |
| 6968 | // Resend with authorization (username=foo, password=bar) |
| 6969 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6970 | MockWrite( |
| 6971 | "GET /x/y/z HTTP/1.1\r\n" |
| 6972 | "Host: www.example.org\r\n" |
| 6973 | "Connection: keep-alive\r\n" |
| 6974 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 6975 | "nonce=\"OU812\", uri=\"/x/y/z\", algorithm=MD5, " |
| 6976 | "response=\"03ffbcd30add722589c1de345d7a927f\", qop=auth, " |
| 6977 | "nc=00000001, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6978 | }; |
| 6979 | |
| 6980 | // Sever accepts the authorization. |
| 6981 | MockRead data_reads2[] = { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 6982 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6983 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6984 | }; |
| 6985 | |
| 6986 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6987 | data_writes1, arraysize(data_writes1)); |
| 6988 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6989 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6990 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6991 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6992 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6993 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6994 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6995 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6996 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6997 | |
| 6998 | rv = callback1.WaitForResult(); |
| 6999 | EXPECT_EQ(OK, rv); |
| 7000 | |
| 7001 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7002 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7003 | EXPECT_TRUE(CheckDigestServerAuth(response->auth_challenge.get())); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7004 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7005 | TestCompletionCallback callback2; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7006 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7007 | rv = trans->RestartWithAuth( |
| 7008 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7009 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7010 | |
| 7011 | rv = callback2.WaitForResult(); |
| 7012 | EXPECT_EQ(OK, rv); |
| 7013 | |
| 7014 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7015 | ASSERT_TRUE(response != NULL); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7016 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 7017 | } |
| 7018 | |
| 7019 | // ------------------------------------------------------------------------ |
| 7020 | |
| 7021 | // Transaction 2: Request another resource in digestive's protection space. |
| 7022 | // This will preemptively add an Authorization header which should have an |
| 7023 | // "nc" value of 2 (as compared to 1 in the first use. |
| 7024 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7025 | HttpRequestInfo request; |
| 7026 | request.method = "GET"; |
| 7027 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 7028 | // protection space as digest. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7029 | request.url = GURL("http://www.example.org/x/y/a/b"); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7030 | request.load_flags = 0; |
| 7031 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7032 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7033 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7034 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7035 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7036 | MockWrite( |
| 7037 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 7038 | "Host: www.example.org\r\n" |
| 7039 | "Connection: keep-alive\r\n" |
| 7040 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 7041 | "nonce=\"OU812\", uri=\"/x/y/a/b\", algorithm=MD5, " |
| 7042 | "response=\"d6f9a2c07d1c5df7b89379dca1269b35\", qop=auth, " |
| 7043 | "nc=00000002, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7044 | }; |
| 7045 | |
| 7046 | // Sever accepts the authorization. |
| 7047 | MockRead data_reads1[] = { |
| 7048 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7049 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7050 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7051 | }; |
| 7052 | |
| 7053 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7054 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7055 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7056 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7057 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7058 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7059 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7060 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7061 | |
| 7062 | rv = callback1.WaitForResult(); |
| 7063 | EXPECT_EQ(OK, rv); |
| 7064 | |
| 7065 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7066 | ASSERT_TRUE(response != NULL); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7067 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 7068 | } |
| 7069 | } |
| 7070 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7071 | // Test the ResetStateForRestart() private method. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7072 | TEST_P(HttpNetworkTransactionTest, ResetStateForRestart) { |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7073 | // Create a transaction (the dependencies aren't important). |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7074 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 7075 | scoped_ptr<HttpNetworkTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7076 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7077 | |
| 7078 | // Setup some state (which we expect ResetStateForRestart() will clear). |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7079 | trans->read_buf_ = new IOBuffer(15); |
| 7080 | trans->read_buf_len_ = 15; |
[email protected] | b94f92d | 2010-10-27 16:45:20 | [diff] [blame] | 7081 | trans->request_headers_.SetHeader("Authorization", "NTLM"); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7082 | |
| 7083 | // Setup state in response_ |
[email protected] | a7e4131 | 2009-12-16 23:18:14 | [diff] [blame] | 7084 | HttpResponseInfo* response = &trans->response_; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7085 | response->auth_challenge = new AuthChallengeInfo(); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 7086 | response->ssl_info.cert_status = static_cast<CertStatus>(-1); // Nonsensical. |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7087 | response->response_time = base::Time::Now(); |
| 7088 | response->was_cached = true; // (Wouldn't ever actually be true...) |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7089 | |
| 7090 | { // Setup state for response_.vary_data |
| 7091 | HttpRequestInfo request; |
| 7092 | std::string temp("HTTP/1.1 200 OK\nVary: foo, bar\n\n"); |
| 7093 | std::replace(temp.begin(), temp.end(), '\n', '\0'); |
[email protected] | ad8e04a | 2010-11-01 04:16:27 | [diff] [blame] | 7094 | scoped_refptr<HttpResponseHeaders> headers(new HttpResponseHeaders(temp)); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 7095 | request.extra_headers.SetHeader("Foo", "1"); |
| 7096 | request.extra_headers.SetHeader("bar", "23"); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7097 | EXPECT_TRUE(response->vary_data.Init(request, *headers.get())); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7098 | } |
| 7099 | |
| 7100 | // Cause the above state to be reset. |
| 7101 | trans->ResetStateForRestart(); |
| 7102 | |
| 7103 | // Verify that the state that needed to be reset, has been reset. |
[email protected] | 9b6fee1 | 2009-09-29 18:13:07 | [diff] [blame] | 7104 | EXPECT_TRUE(trans->read_buf_.get() == NULL); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7105 | EXPECT_EQ(0, trans->read_buf_len_); |
[email protected] | b94f92d | 2010-10-27 16:45:20 | [diff] [blame] | 7106 | EXPECT_TRUE(trans->request_headers_.IsEmpty()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7107 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 7108 | EXPECT_TRUE(response->headers.get() == NULL); |
[email protected] | 34f4094 | 2010-10-04 00:34:04 | [diff] [blame] | 7109 | EXPECT_FALSE(response->was_cached); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 7110 | EXPECT_EQ(0U, response->ssl_info.cert_status); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7111 | EXPECT_FALSE(response->vary_data.is_valid()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7112 | } |
| 7113 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7114 | // Test HTTPS connections to a site with a bad certificate |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7115 | TEST_P(HttpNetworkTransactionTest, HTTPSBadCertificate) { |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7116 | HttpRequestInfo request; |
| 7117 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7118 | request.url = GURL("https://www.example.org/"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7119 | request.load_flags = 0; |
| 7120 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7121 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7122 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7123 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7124 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7125 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7126 | MockWrite( |
| 7127 | "GET / HTTP/1.1\r\n" |
| 7128 | "Host: www.example.org\r\n" |
| 7129 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7130 | }; |
| 7131 | |
| 7132 | MockRead data_reads[] = { |
| 7133 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7134 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7135 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7136 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7137 | }; |
| 7138 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 7139 | StaticSocketDataProvider ssl_bad_certificate; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7140 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7141 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7142 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 7143 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7144 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7145 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 7146 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7147 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 7148 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7149 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7150 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7151 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7152 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7153 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7154 | |
| 7155 | rv = callback.WaitForResult(); |
| 7156 | EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, rv); |
| 7157 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7158 | rv = trans->RestartIgnoringLastError(callback.callback()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7159 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7160 | |
| 7161 | rv = callback.WaitForResult(); |
| 7162 | EXPECT_EQ(OK, rv); |
| 7163 | |
| 7164 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7165 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7166 | ASSERT_TRUE(response != NULL); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7167 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7168 | } |
| 7169 | |
| 7170 | // Test HTTPS connections to a site with a bad certificate, going through a |
| 7171 | // proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7172 | TEST_P(HttpNetworkTransactionTest, HTTPSBadCertificateViaProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7173 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7174 | |
| 7175 | HttpRequestInfo request; |
| 7176 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7177 | request.url = GURL("https://www.example.org/"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7178 | request.load_flags = 0; |
| 7179 | |
| 7180 | MockWrite proxy_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7181 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7182 | "Host: www.example.org:443\r\n" |
| 7183 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7184 | }; |
| 7185 | |
| 7186 | MockRead proxy_reads[] = { |
| 7187 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7188 | MockRead(SYNCHRONOUS, OK) |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7189 | }; |
| 7190 | |
| 7191 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7192 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7193 | "Host: www.example.org:443\r\n" |
| 7194 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 7195 | MockWrite("GET / HTTP/1.1\r\n" |
| 7196 | "Host: www.example.org\r\n" |
| 7197 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7198 | }; |
| 7199 | |
| 7200 | MockRead data_reads[] = { |
| 7201 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 7202 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7203 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7204 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7205 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7206 | }; |
| 7207 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7208 | StaticSocketDataProvider ssl_bad_certificate( |
| 7209 | proxy_reads, arraysize(proxy_reads), |
| 7210 | proxy_writes, arraysize(proxy_writes)); |
| 7211 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7212 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7213 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 7214 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7215 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7216 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 7217 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7218 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 7219 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7220 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7221 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7222 | |
| 7223 | for (int i = 0; i < 2; i++) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7224 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7225 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7226 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 7227 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7228 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7229 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7230 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7231 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7232 | |
| 7233 | rv = callback.WaitForResult(); |
| 7234 | EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, rv); |
| 7235 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7236 | rv = trans->RestartIgnoringLastError(callback.callback()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7237 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7238 | |
| 7239 | rv = callback.WaitForResult(); |
| 7240 | EXPECT_EQ(OK, rv); |
| 7241 | |
| 7242 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7243 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7244 | ASSERT_TRUE(response != NULL); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7245 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7246 | } |
| 7247 | } |
| 7248 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7249 | |
| 7250 | // Test HTTPS connections to a site, going through an HTTPS proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7251 | TEST_P(HttpNetworkTransactionTest, HTTPSViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7252 | session_deps_.proxy_service = |
| 7253 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7254 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7255 | session_deps_.net_log = &net_log; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7256 | |
| 7257 | HttpRequestInfo request; |
| 7258 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7259 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7260 | request.load_flags = 0; |
| 7261 | |
| 7262 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7263 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7264 | "Host: www.example.org:443\r\n" |
| 7265 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 7266 | MockWrite("GET / HTTP/1.1\r\n" |
| 7267 | "Host: www.example.org\r\n" |
| 7268 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7269 | }; |
| 7270 | |
| 7271 | MockRead data_reads[] = { |
| 7272 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 7273 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 7274 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7275 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7276 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7277 | }; |
| 7278 | |
| 7279 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7280 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7281 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
| 7282 | SSLSocketDataProvider tunnel_ssl(ASYNC, OK); // SSL through the tunnel |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7283 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7284 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7285 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
| 7286 | session_deps_.socket_factory->AddSSLSocketDataProvider(&tunnel_ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7287 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7288 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7289 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7290 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7291 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7292 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7293 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7294 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7295 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7296 | |
| 7297 | rv = callback.WaitForResult(); |
| 7298 | EXPECT_EQ(OK, rv); |
| 7299 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7300 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7301 | ASSERT_TRUE(response != NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7302 | |
| 7303 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 7304 | EXPECT_EQ(200, response->headers->response_code()); |
| 7305 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7306 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7307 | |
| 7308 | LoadTimingInfo load_timing_info; |
| 7309 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7310 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 7311 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7312 | } |
| 7313 | |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7314 | // Test an HTTPS Proxy's ability to redirect a CONNECT request |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7315 | TEST_P(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7316 | session_deps_.proxy_service = |
| 7317 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7318 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7319 | session_deps_.net_log = &net_log; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7320 | |
| 7321 | HttpRequestInfo request; |
| 7322 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7323 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7324 | request.load_flags = 0; |
| 7325 | |
| 7326 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7327 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7328 | "Host: www.example.org:443\r\n" |
| 7329 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7330 | }; |
| 7331 | |
| 7332 | MockRead data_reads[] = { |
| 7333 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 7334 | MockRead("Location: http://login.example.com/\r\n"), |
| 7335 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7336 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7337 | }; |
| 7338 | |
| 7339 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7340 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7341 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7342 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7343 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7344 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7345 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7346 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7347 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7348 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7349 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7350 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7351 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7352 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7353 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7354 | |
| 7355 | rv = callback.WaitForResult(); |
| 7356 | EXPECT_EQ(OK, rv); |
| 7357 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7358 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7359 | ASSERT_TRUE(response != NULL); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7360 | |
| 7361 | EXPECT_EQ(302, response->headers->response_code()); |
| 7362 | std::string url; |
| 7363 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 7364 | EXPECT_EQ("http://login.example.com/", url); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7365 | |
| 7366 | // In the case of redirects from proxies, HttpNetworkTransaction returns |
| 7367 | // timing for the proxy connection instead of the connection to the host, |
| 7368 | // and no send / receive times. |
| 7369 | // See HttpNetworkTransaction::OnHttpsProxyTunnelResponse. |
| 7370 | LoadTimingInfo load_timing_info; |
| 7371 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7372 | |
| 7373 | EXPECT_FALSE(load_timing_info.socket_reused); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 7374 | EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7375 | |
| 7376 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 7377 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 7378 | load_timing_info.proxy_resolve_end); |
| 7379 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 7380 | load_timing_info.connect_timing.connect_start); |
| 7381 | ExpectConnectTimingHasTimes( |
| 7382 | load_timing_info.connect_timing, |
| 7383 | CONNECT_TIMING_HAS_DNS_TIMES | CONNECT_TIMING_HAS_SSL_TIMES); |
| 7384 | |
| 7385 | EXPECT_TRUE(load_timing_info.send_start.is_null()); |
| 7386 | EXPECT_TRUE(load_timing_info.send_end.is_null()); |
| 7387 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7388 | } |
| 7389 | |
| 7390 | // Test an HTTPS (SPDY) Proxy's ability to redirect a CONNECT request |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7391 | TEST_P(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaSpdyProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7392 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7393 | |
| 7394 | HttpRequestInfo request; |
| 7395 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7396 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7397 | request.load_flags = 0; |
| 7398 | |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 7399 | scoped_ptr<SpdyFrame> conn(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7400 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 7401 | scoped_ptr<SpdyFrame> goaway( |
| 7402 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7403 | MockWrite data_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7404 | CreateMockWrite(*conn.get(), 0, SYNCHRONOUS), |
| 7405 | CreateMockWrite(*goaway.get(), 2, SYNCHRONOUS), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7406 | }; |
| 7407 | |
| 7408 | static const char* const kExtraHeaders[] = { |
| 7409 | "location", |
| 7410 | "http://login.example.com/", |
| 7411 | }; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 7412 | scoped_ptr<SpdyFrame> resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7413 | spdy_util_.ConstructSpdySynReplyError("302 Redirect", kExtraHeaders, |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7414 | arraysize(kExtraHeaders)/2, 1)); |
| 7415 | MockRead data_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7416 | CreateMockRead(*resp.get(), 1), MockRead(ASYNC, 0, 3), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7417 | }; |
| 7418 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7419 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 7420 | arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7421 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 7422 | proxy_ssl.SetNextProto(GetProtocol()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7423 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7424 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7425 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7426 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7427 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7428 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7429 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7430 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7431 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7432 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7433 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7434 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7435 | |
| 7436 | rv = callback.WaitForResult(); |
| 7437 | EXPECT_EQ(OK, rv); |
| 7438 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7439 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7440 | ASSERT_TRUE(response != NULL); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7441 | |
| 7442 | EXPECT_EQ(302, response->headers->response_code()); |
| 7443 | std::string url; |
| 7444 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 7445 | EXPECT_EQ("http://login.example.com/", url); |
| 7446 | } |
| 7447 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 7448 | // Test that an HTTPS proxy's response to a CONNECT request is filtered. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7449 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 7450 | ErrorResponseToHttpsConnectViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7451 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7452 | |
| 7453 | HttpRequestInfo request; |
| 7454 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7455 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7456 | request.load_flags = 0; |
| 7457 | |
| 7458 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7459 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7460 | "Host: www.example.org:443\r\n" |
| 7461 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7462 | }; |
| 7463 | |
| 7464 | MockRead data_reads[] = { |
| 7465 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 7466 | MockRead("Content-Length: 23\r\n\r\n"), |
| 7467 | MockRead("The host does not exist"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7468 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7469 | }; |
| 7470 | |
| 7471 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7472 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7473 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7474 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7475 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7476 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7477 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7478 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7479 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7480 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7481 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7482 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7483 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7484 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7485 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7486 | |
| 7487 | rv = callback.WaitForResult(); |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 7488 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7489 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 7490 | // TODO(ttuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7491 | } |
| 7492 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 7493 | // Test that a SPDY proxy's response to a CONNECT request is filtered. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7494 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 7495 | ErrorResponseToHttpsConnectViaSpdyProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7496 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7497 | |
| 7498 | HttpRequestInfo request; |
| 7499 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7500 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7501 | request.load_flags = 0; |
| 7502 | |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 7503 | scoped_ptr<SpdyFrame> conn(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7504 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 7505 | scoped_ptr<SpdyFrame> rst( |
| 7506 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7507 | MockWrite data_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7508 | CreateMockWrite(*conn.get(), 0), CreateMockWrite(*rst.get(), 3), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7509 | }; |
| 7510 | |
| 7511 | static const char* const kExtraHeaders[] = { |
| 7512 | "location", |
| 7513 | "http://login.example.com/", |
| 7514 | }; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 7515 | scoped_ptr<SpdyFrame> resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7516 | spdy_util_.ConstructSpdySynReplyError("404 Not Found", kExtraHeaders, |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7517 | arraysize(kExtraHeaders)/2, 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 7518 | scoped_ptr<SpdyFrame> body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7519 | spdy_util_.ConstructSpdyBodyFrame( |
| 7520 | 1, "The host does not exist", 23, true)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7521 | MockRead data_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7522 | CreateMockRead(*resp.get(), 1), |
| 7523 | CreateMockRead(*body.get(), 2), |
| 7524 | MockRead(ASYNC, 0, 4), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7525 | }; |
| 7526 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7527 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 7528 | arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7529 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 7530 | proxy_ssl.SetNextProto(GetProtocol()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7531 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7532 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7533 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7534 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7535 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7536 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7537 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7538 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7539 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7540 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7541 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7542 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7543 | |
| 7544 | rv = callback.WaitForResult(); |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 7545 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7546 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 7547 | // TODO(ttuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7548 | } |
| 7549 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7550 | // Test the request-challenge-retry sequence for basic auth, through |
| 7551 | // a SPDY proxy over a single SPDY session. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7552 | TEST_P(HttpNetworkTransactionTest, BasicAuthSpdyProxy) { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7553 | HttpRequestInfo request; |
| 7554 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7555 | request.url = GURL("https://www.example.org/"); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7556 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 7557 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7558 | |
| 7559 | // Configure against https proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7560 | session_deps_.proxy_service = |
| 7561 | ProxyService::CreateFixedFromPacResult("HTTPS myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7562 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7563 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7564 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7565 | |
| 7566 | // Since we have proxy, should try to establish tunnel. |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 7567 | scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7568 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 7569 | scoped_ptr<SpdyFrame> rst( |
| 7570 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 7571 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7572 | |
| 7573 | // After calling trans->RestartWithAuth(), this is the request we should |
| 7574 | // be issuing -- the final header line contains the credentials. |
| 7575 | const char* const kAuthCredentials[] = { |
| 7576 | "proxy-authorization", "Basic Zm9vOmJhcg==", |
| 7577 | }; |
[email protected] | fba2dbde | 2013-05-24 16:09:01 | [diff] [blame] | 7578 | scoped_ptr<SpdyFrame> connect2(spdy_util_.ConstructSpdyConnect( |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 7579 | kAuthCredentials, arraysize(kAuthCredentials) / 2, 3, LOWEST, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7580 | HostPortPair("www.example.org", 443))); |
| 7581 | // fetch https://www.example.org/ via HTTP |
| 7582 | const char get[] = |
| 7583 | "GET / HTTP/1.1\r\n" |
| 7584 | "Host: www.example.org\r\n" |
| 7585 | "Connection: keep-alive\r\n\r\n"; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 7586 | scoped_ptr<SpdyFrame> wrapped_get( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7587 | spdy_util_.ConstructSpdyBodyFrame(3, get, strlen(get), false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7588 | |
| 7589 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7590 | CreateMockWrite(*req, 0, ASYNC), |
| 7591 | CreateMockWrite(*rst, 2, ASYNC), |
| 7592 | CreateMockWrite(*connect2, 3), |
| 7593 | CreateMockWrite(*wrapped_get, 5), |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7594 | }; |
| 7595 | |
| 7596 | // The proxy responds to the connect with a 407, using a persistent |
| 7597 | // connection. |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 7598 | const char kAuthStatus[] = "407"; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7599 | const char* const kAuthChallenge[] = { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7600 | "proxy-authenticate", "Basic realm=\"MyRealm1\"", |
| 7601 | }; |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 7602 | scoped_ptr<SpdyFrame> conn_auth_resp(spdy_util_.ConstructSpdySynReplyError( |
| 7603 | kAuthStatus, kAuthChallenge, arraysize(kAuthChallenge) / 2, 1)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7604 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7605 | scoped_ptr<SpdyFrame> conn_resp( |
| 7606 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7607 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 7608 | "Content-Length: 5\r\n\r\n"; |
| 7609 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 7610 | scoped_ptr<SpdyFrame> wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7611 | spdy_util_.ConstructSpdyBodyFrame(3, resp, strlen(resp), false)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 7612 | scoped_ptr<SpdyFrame> wrapped_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7613 | spdy_util_.ConstructSpdyBodyFrame(3, "hello", 5, false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7614 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7615 | CreateMockRead(*conn_auth_resp, 1, ASYNC), |
| 7616 | CreateMockRead(*conn_resp, 4, ASYNC), |
| 7617 | CreateMockRead(*wrapped_get_resp, 6, ASYNC), |
| 7618 | CreateMockRead(*wrapped_body, 7, ASYNC), |
| 7619 | MockRead(ASYNC, OK, 8), // EOF. May or may not be read. |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7620 | }; |
| 7621 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7622 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 7623 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7624 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7625 | // Negotiate SPDY to the proxy |
| 7626 | SSLSocketDataProvider proxy(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 7627 | proxy.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7628 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7629 | // Vanilla SSL to the server |
| 7630 | SSLSocketDataProvider server(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7631 | session_deps_.socket_factory->AddSSLSocketDataProvider(&server); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7632 | |
| 7633 | TestCompletionCallback callback1; |
| 7634 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7635 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7636 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7637 | |
| 7638 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 7639 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7640 | |
| 7641 | rv = callback1.WaitForResult(); |
| 7642 | EXPECT_EQ(OK, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 7643 | TestNetLogEntry::List entries; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7644 | log.GetEntries(&entries); |
| 7645 | size_t pos = ExpectLogContainsSomewhere( |
| 7646 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 7647 | NetLog::PHASE_NONE); |
| 7648 | ExpectLogContainsSomewhere( |
| 7649 | entries, pos, |
| 7650 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 7651 | NetLog::PHASE_NONE); |
| 7652 | |
| 7653 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7654 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7655 | ASSERT_FALSE(response->headers.get() == NULL); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7656 | EXPECT_EQ(407, response->headers->response_code()); |
| 7657 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 7658 | EXPECT_TRUE(response->auth_challenge.get() != NULL); |
| 7659 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 7660 | |
| 7661 | TestCompletionCallback callback2; |
| 7662 | |
| 7663 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 7664 | callback2.callback()); |
| 7665 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7666 | |
| 7667 | rv = callback2.WaitForResult(); |
| 7668 | EXPECT_EQ(OK, rv); |
| 7669 | |
| 7670 | response = trans->GetResponseInfo(); |
| 7671 | ASSERT_TRUE(response != NULL); |
| 7672 | |
| 7673 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 7674 | EXPECT_EQ(200, response->headers->response_code()); |
| 7675 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 7676 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 7677 | |
| 7678 | // The password prompt info should not be set. |
| 7679 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 7680 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7681 | LoadTimingInfo load_timing_info; |
| 7682 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7683 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 7684 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 7685 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7686 | trans.reset(); |
| 7687 | session->CloseAllConnections(); |
| 7688 | } |
| 7689 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7690 | // Test that an explicitly trusted SPDY proxy can push a resource from an |
| 7691 | // origin that is different from that of its associated resource. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7692 | TEST_P(HttpNetworkTransactionTest, CrossOriginProxyPush) { |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7693 | HttpRequestInfo request; |
| 7694 | HttpRequestInfo push_request; |
| 7695 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7696 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7697 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7698 | push_request.method = "GET"; |
| 7699 | push_request.url = GURL("http://www.another-origin.com/foo.dat"); |
| 7700 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7701 | // Configure against https proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7702 | session_deps_.proxy_service = |
| 7703 | ProxyService::CreateFixedFromPacResult("HTTPS myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7704 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7705 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 7706 | |
| 7707 | // Enable cross-origin push. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7708 | session_deps_.trusted_spdy_proxy = "myproxy:70"; |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 7709 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7710 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7711 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 7712 | scoped_ptr<SpdyFrame> stream1_syn( |
| 7713 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7714 | |
| 7715 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7716 | CreateMockWrite(*stream1_syn, 0, ASYNC), |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7717 | }; |
| 7718 | |
| 7719 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7720 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7721 | |
| 7722 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7723 | stream1_body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7724 | |
| 7725 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7726 | stream2_syn(spdy_util_.ConstructSpdyPush(NULL, |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7727 | 0, |
| 7728 | 2, |
| 7729 | 1, |
| 7730 | "http://www.another-origin.com/foo.dat")); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 7731 | const char kPushedData[] = "pushed"; |
| 7732 | scoped_ptr<SpdyFrame> stream2_body( |
| 7733 | spdy_util_.ConstructSpdyBodyFrame( |
| 7734 | 2, kPushedData, strlen(kPushedData), true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7735 | |
| 7736 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7737 | CreateMockRead(*stream1_reply, 1, ASYNC), |
| 7738 | CreateMockRead(*stream2_syn, 2, ASYNC), |
| 7739 | CreateMockRead(*stream1_body, 3, ASYNC), |
| 7740 | CreateMockRead(*stream2_body, 4, ASYNC), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 7741 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), // Force a hang |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7742 | }; |
| 7743 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7744 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 7745 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7746 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7747 | // Negotiate SPDY to the proxy |
| 7748 | SSLSocketDataProvider proxy(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 7749 | proxy.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7750 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7751 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7752 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7753 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7754 | TestCompletionCallback callback; |
| 7755 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
| 7756 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7757 | |
| 7758 | rv = callback.WaitForResult(); |
| 7759 | EXPECT_EQ(OK, rv); |
| 7760 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7761 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7762 | scoped_ptr<HttpTransaction> push_trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7763 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 7764 | rv = push_trans->Start(&push_request, callback.callback(), log.bound()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7765 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7766 | |
| 7767 | rv = callback.WaitForResult(); |
| 7768 | EXPECT_EQ(OK, rv); |
| 7769 | const HttpResponseInfo* push_response = push_trans->GetResponseInfo(); |
| 7770 | |
| 7771 | ASSERT_TRUE(response != NULL); |
| 7772 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 7773 | |
| 7774 | EXPECT_EQ(200, response->headers->response_code()); |
| 7775 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 7776 | |
| 7777 | std::string response_data; |
| 7778 | rv = ReadTransaction(trans.get(), &response_data); |
| 7779 | EXPECT_EQ(OK, rv); |
| 7780 | EXPECT_EQ("hello!", response_data); |
| 7781 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7782 | LoadTimingInfo load_timing_info; |
| 7783 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7784 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 7785 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 7786 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7787 | // Verify the pushed stream. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7788 | EXPECT_TRUE(push_response->headers.get() != NULL); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7789 | EXPECT_EQ(200, push_response->headers->response_code()); |
| 7790 | |
| 7791 | rv = ReadTransaction(push_trans.get(), &response_data); |
| 7792 | EXPECT_EQ(OK, rv); |
| 7793 | EXPECT_EQ("pushed", response_data); |
| 7794 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7795 | LoadTimingInfo push_load_timing_info; |
| 7796 | EXPECT_TRUE(push_trans->GetLoadTimingInfo(&push_load_timing_info)); |
| 7797 | TestLoadTimingReusedWithPac(push_load_timing_info); |
| 7798 | // The transactions should share a socket ID, despite being for different |
| 7799 | // origins. |
| 7800 | EXPECT_EQ(load_timing_info.socket_log_id, |
| 7801 | push_load_timing_info.socket_log_id); |
| 7802 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7803 | trans.reset(); |
| 7804 | push_trans.reset(); |
| 7805 | session->CloseAllConnections(); |
| 7806 | } |
| 7807 | |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7808 | // Test that an explicitly trusted SPDY proxy cannot push HTTPS content. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7809 | TEST_P(HttpNetworkTransactionTest, CrossOriginProxyPushCorrectness) { |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7810 | HttpRequestInfo request; |
| 7811 | |
| 7812 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7813 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7814 | |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7815 | // Configure against https proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7816 | session_deps_.proxy_service = ProxyService::CreateFixed("https://myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7817 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7818 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 7819 | |
| 7820 | // Enable cross-origin push. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7821 | session_deps_.trusted_spdy_proxy = "myproxy:70"; |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 7822 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7823 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7824 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 7825 | scoped_ptr<SpdyFrame> stream1_syn( |
| 7826 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7827 | |
| 7828 | scoped_ptr<SpdyFrame> push_rst( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 7829 | spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_REFUSED_STREAM)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7830 | |
| 7831 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7832 | CreateMockWrite(*stream1_syn, 0, ASYNC), CreateMockWrite(*push_rst, 3), |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7833 | }; |
| 7834 | |
| 7835 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7836 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7837 | |
| 7838 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7839 | stream1_body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7840 | |
| 7841 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7842 | stream2_syn(spdy_util_.ConstructSpdyPush(NULL, |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7843 | 0, |
| 7844 | 2, |
| 7845 | 1, |
| 7846 | "https://www.another-origin.com/foo.dat")); |
| 7847 | |
| 7848 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7849 | CreateMockRead(*stream1_reply, 1, ASYNC), |
| 7850 | CreateMockRead(*stream2_syn, 2, ASYNC), |
| 7851 | CreateMockRead(*stream1_body, 4, ASYNC), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 7852 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), // Force a hang |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7853 | }; |
| 7854 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7855 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 7856 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7857 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7858 | // Negotiate SPDY to the proxy |
| 7859 | SSLSocketDataProvider proxy(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 7860 | proxy.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7861 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7862 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7863 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7864 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7865 | TestCompletionCallback callback; |
| 7866 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
| 7867 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7868 | |
| 7869 | rv = callback.WaitForResult(); |
| 7870 | EXPECT_EQ(OK, rv); |
| 7871 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7872 | |
| 7873 | ASSERT_TRUE(response != NULL); |
| 7874 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 7875 | |
| 7876 | EXPECT_EQ(200, response->headers->response_code()); |
| 7877 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 7878 | |
| 7879 | std::string response_data; |
| 7880 | rv = ReadTransaction(trans.get(), &response_data); |
| 7881 | EXPECT_EQ(OK, rv); |
| 7882 | EXPECT_EQ("hello!", response_data); |
| 7883 | |
| 7884 | trans.reset(); |
| 7885 | session->CloseAllConnections(); |
| 7886 | } |
| 7887 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7888 | // Test HTTPS connections to a site with a bad certificate, going through an |
| 7889 | // HTTPS proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7890 | TEST_P(HttpNetworkTransactionTest, HTTPSBadCertificateViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7891 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7892 | |
| 7893 | HttpRequestInfo request; |
| 7894 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7895 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7896 | request.load_flags = 0; |
| 7897 | |
| 7898 | // Attempt to fetch the URL from a server with a bad cert |
| 7899 | MockWrite bad_cert_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7900 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7901 | "Host: www.example.org:443\r\n" |
| 7902 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7903 | }; |
| 7904 | |
| 7905 | MockRead bad_cert_reads[] = { |
| 7906 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7907 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7908 | }; |
| 7909 | |
| 7910 | // Attempt to fetch the URL with a good cert |
| 7911 | MockWrite good_data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7912 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7913 | "Host: www.example.org:443\r\n" |
| 7914 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 7915 | MockWrite("GET / HTTP/1.1\r\n" |
| 7916 | "Host: www.example.org\r\n" |
| 7917 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7918 | }; |
| 7919 | |
| 7920 | MockRead good_cert_reads[] = { |
| 7921 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 7922 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7923 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7924 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7925 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7926 | }; |
| 7927 | |
| 7928 | StaticSocketDataProvider ssl_bad_certificate( |
| 7929 | bad_cert_reads, arraysize(bad_cert_reads), |
| 7930 | bad_cert_writes, arraysize(bad_cert_writes)); |
| 7931 | StaticSocketDataProvider data(good_cert_reads, arraysize(good_cert_reads), |
| 7932 | good_data_writes, arraysize(good_data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7933 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 7934 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7935 | |
| 7936 | // SSL to the proxy, then CONNECT request, then SSL with bad certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7937 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 7938 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 7939 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7940 | |
| 7941 | // SSL to the proxy, then CONNECT request, then valid SSL certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7942 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 7943 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7944 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7945 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7946 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7947 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7948 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7949 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7950 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7951 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7952 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7953 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7954 | |
| 7955 | rv = callback.WaitForResult(); |
| 7956 | EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, rv); |
| 7957 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7958 | rv = trans->RestartIgnoringLastError(callback.callback()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7959 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7960 | |
| 7961 | rv = callback.WaitForResult(); |
| 7962 | EXPECT_EQ(OK, rv); |
| 7963 | |
| 7964 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7965 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7966 | ASSERT_TRUE(response != NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7967 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7968 | } |
| 7969 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7970 | TEST_P(HttpNetworkTransactionTest, BuildRequest_UserAgent) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7971 | HttpRequestInfo request; |
| 7972 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7973 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 7974 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 7975 | "Chromium Ultra Awesome X Edition"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7976 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7977 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7978 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7979 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7980 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7981 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7982 | MockWrite( |
| 7983 | "GET / HTTP/1.1\r\n" |
| 7984 | "Host: www.example.org\r\n" |
| 7985 | "Connection: keep-alive\r\n" |
| 7986 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7987 | }; |
| 7988 | |
| 7989 | // Lastly, the server responds with the actual content. |
| 7990 | MockRead data_reads[] = { |
| 7991 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7992 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7993 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7994 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7995 | }; |
| 7996 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7997 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7998 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7999 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8000 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8001 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8002 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8003 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8004 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8005 | |
| 8006 | rv = callback.WaitForResult(); |
| 8007 | EXPECT_EQ(OK, rv); |
| 8008 | } |
| 8009 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8010 | TEST_P(HttpNetworkTransactionTest, BuildRequest_UserAgentOverTunnel) { |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8011 | HttpRequestInfo request; |
| 8012 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8013 | request.url = GURL("https://www.example.org/"); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8014 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 8015 | "Chromium Ultra Awesome X Edition"); |
| 8016 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8017 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8018 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8019 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8020 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8021 | |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8022 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8023 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8024 | "Host: www.example.org:443\r\n" |
| 8025 | "Proxy-Connection: keep-alive\r\n" |
| 8026 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8027 | }; |
| 8028 | MockRead data_reads[] = { |
| 8029 | // Return an error, so the transaction stops here (this test isn't |
| 8030 | // interested in the rest). |
| 8031 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 8032 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8033 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 8034 | }; |
| 8035 | |
| 8036 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8037 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8038 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8039 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8040 | TestCompletionCallback callback; |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8041 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8042 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8043 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8044 | |
| 8045 | rv = callback.WaitForResult(); |
| 8046 | EXPECT_EQ(OK, rv); |
| 8047 | } |
| 8048 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8049 | TEST_P(HttpNetworkTransactionTest, BuildRequest_Referer) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8050 | HttpRequestInfo request; |
| 8051 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8052 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8053 | request.load_flags = 0; |
[email protected] | c1045010 | 2011-06-27 09:06:16 | [diff] [blame] | 8054 | request.extra_headers.SetHeader(HttpRequestHeaders::kReferer, |
| 8055 | "http://the.previous.site.com/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8056 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8057 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8058 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8059 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8060 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8061 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8062 | MockWrite( |
| 8063 | "GET / HTTP/1.1\r\n" |
| 8064 | "Host: www.example.org\r\n" |
| 8065 | "Connection: keep-alive\r\n" |
| 8066 | "Referer: http://the.previous.site.com/\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8067 | }; |
| 8068 | |
| 8069 | // Lastly, the server responds with the actual content. |
| 8070 | MockRead data_reads[] = { |
| 8071 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8072 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8073 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8074 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8075 | }; |
| 8076 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8077 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8078 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8079 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8080 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8081 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8082 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8083 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8084 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8085 | |
| 8086 | rv = callback.WaitForResult(); |
| 8087 | EXPECT_EQ(OK, rv); |
| 8088 | } |
| 8089 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8090 | TEST_P(HttpNetworkTransactionTest, BuildRequest_PostContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8091 | HttpRequestInfo request; |
| 8092 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8093 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8094 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8095 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8096 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8097 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8098 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8099 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8100 | MockWrite( |
| 8101 | "POST / HTTP/1.1\r\n" |
| 8102 | "Host: www.example.org\r\n" |
| 8103 | "Connection: keep-alive\r\n" |
| 8104 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8105 | }; |
| 8106 | |
| 8107 | // Lastly, the server responds with the actual content. |
| 8108 | MockRead data_reads[] = { |
| 8109 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8110 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8111 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8112 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8113 | }; |
| 8114 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8115 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8116 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8117 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8118 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8119 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8120 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8121 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8122 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8123 | |
| 8124 | rv = callback.WaitForResult(); |
| 8125 | EXPECT_EQ(OK, rv); |
| 8126 | } |
| 8127 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8128 | TEST_P(HttpNetworkTransactionTest, BuildRequest_PutContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8129 | HttpRequestInfo request; |
| 8130 | request.method = "PUT"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8131 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8132 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8133 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8134 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8135 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8136 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8137 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8138 | MockWrite( |
| 8139 | "PUT / HTTP/1.1\r\n" |
| 8140 | "Host: www.example.org\r\n" |
| 8141 | "Connection: keep-alive\r\n" |
| 8142 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8143 | }; |
| 8144 | |
| 8145 | // Lastly, the server responds with the actual content. |
| 8146 | MockRead data_reads[] = { |
| 8147 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8148 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8149 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8150 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8151 | }; |
| 8152 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8153 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8154 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8155 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8156 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8157 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8158 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8159 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8160 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8161 | |
| 8162 | rv = callback.WaitForResult(); |
| 8163 | EXPECT_EQ(OK, rv); |
| 8164 | } |
| 8165 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8166 | TEST_P(HttpNetworkTransactionTest, BuildRequest_HeadContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8167 | HttpRequestInfo request; |
| 8168 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8169 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8170 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8171 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8172 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8173 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8174 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8175 | MockWrite data_writes[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 8176 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 8177 | "Host: www.example.org\r\n" |
| 8178 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8179 | }; |
| 8180 | |
| 8181 | // Lastly, the server responds with the actual content. |
| 8182 | MockRead data_reads[] = { |
| 8183 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8184 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8185 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8186 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8187 | }; |
| 8188 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8189 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8190 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8191 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8192 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8193 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8194 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8195 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8196 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8197 | |
| 8198 | rv = callback.WaitForResult(); |
| 8199 | EXPECT_EQ(OK, rv); |
| 8200 | } |
| 8201 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8202 | TEST_P(HttpNetworkTransactionTest, BuildRequest_CacheControlNoCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8203 | HttpRequestInfo request; |
| 8204 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8205 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8206 | request.load_flags = LOAD_BYPASS_CACHE; |
| 8207 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8208 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8209 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8210 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8211 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8212 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8213 | MockWrite( |
| 8214 | "GET / HTTP/1.1\r\n" |
| 8215 | "Host: www.example.org\r\n" |
| 8216 | "Connection: keep-alive\r\n" |
| 8217 | "Pragma: no-cache\r\n" |
| 8218 | "Cache-Control: no-cache\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8219 | }; |
| 8220 | |
| 8221 | // Lastly, the server responds with the actual content. |
| 8222 | MockRead data_reads[] = { |
| 8223 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8224 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8225 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8226 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8227 | }; |
| 8228 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8229 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8230 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8231 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8232 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8233 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8234 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8235 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8236 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8237 | |
| 8238 | rv = callback.WaitForResult(); |
| 8239 | EXPECT_EQ(OK, rv); |
| 8240 | } |
| 8241 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8242 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8243 | BuildRequest_CacheControlValidateCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8244 | HttpRequestInfo request; |
| 8245 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8246 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8247 | request.load_flags = LOAD_VALIDATE_CACHE; |
| 8248 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8249 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8250 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8251 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8252 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8253 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8254 | MockWrite( |
| 8255 | "GET / HTTP/1.1\r\n" |
| 8256 | "Host: www.example.org\r\n" |
| 8257 | "Connection: keep-alive\r\n" |
| 8258 | "Cache-Control: max-age=0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8259 | }; |
| 8260 | |
| 8261 | // Lastly, the server responds with the actual content. |
| 8262 | MockRead data_reads[] = { |
| 8263 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8264 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8265 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8266 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8267 | }; |
| 8268 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8269 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8270 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8271 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8272 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8273 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8274 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8275 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8276 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8277 | |
| 8278 | rv = callback.WaitForResult(); |
| 8279 | EXPECT_EQ(OK, rv); |
| 8280 | } |
| 8281 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8282 | TEST_P(HttpNetworkTransactionTest, BuildRequest_ExtraHeaders) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8283 | HttpRequestInfo request; |
| 8284 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8285 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 8286 | request.extra_headers.SetHeader("FooHeader", "Bar"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8287 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8288 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8289 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8290 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8291 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8292 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8293 | MockWrite( |
| 8294 | "GET / HTTP/1.1\r\n" |
| 8295 | "Host: www.example.org\r\n" |
| 8296 | "Connection: keep-alive\r\n" |
| 8297 | "FooHeader: Bar\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8298 | }; |
| 8299 | |
| 8300 | // Lastly, the server responds with the actual content. |
| 8301 | MockRead data_reads[] = { |
| 8302 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8303 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8304 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8305 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8306 | }; |
| 8307 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8308 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8309 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8310 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8311 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8312 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8313 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8314 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8315 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8316 | |
| 8317 | rv = callback.WaitForResult(); |
| 8318 | EXPECT_EQ(OK, rv); |
| 8319 | } |
| 8320 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8321 | TEST_P(HttpNetworkTransactionTest, BuildRequest_ExtraHeadersStripped) { |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8322 | HttpRequestInfo request; |
| 8323 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8324 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 8325 | request.extra_headers.SetHeader("referer", "www.foo.com"); |
| 8326 | request.extra_headers.SetHeader("hEllo", "Kitty"); |
| 8327 | request.extra_headers.SetHeader("FoO", "bar"); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8328 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8329 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8330 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8331 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8332 | |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8333 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8334 | MockWrite( |
| 8335 | "GET / HTTP/1.1\r\n" |
| 8336 | "Host: www.example.org\r\n" |
| 8337 | "Connection: keep-alive\r\n" |
| 8338 | "referer: www.foo.com\r\n" |
| 8339 | "hEllo: Kitty\r\n" |
| 8340 | "FoO: bar\r\n\r\n"), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8341 | }; |
| 8342 | |
| 8343 | // Lastly, the server responds with the actual content. |
| 8344 | MockRead data_reads[] = { |
| 8345 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8346 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8347 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8348 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8349 | }; |
| 8350 | |
| 8351 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8352 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8353 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8354 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8355 | TestCompletionCallback callback; |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8356 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8357 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8358 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8359 | |
| 8360 | rv = callback.WaitForResult(); |
| 8361 | EXPECT_EQ(OK, rv); |
| 8362 | } |
| 8363 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8364 | TEST_P(HttpNetworkTransactionTest, SOCKS4_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8365 | HttpRequestInfo request; |
| 8366 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8367 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8368 | request.load_flags = 0; |
| 8369 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8370 | session_deps_.proxy_service = |
| 8371 | ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8372 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8373 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8374 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8375 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8376 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8377 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8378 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8379 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 8380 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 8381 | |
| 8382 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8383 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
| 8384 | MockWrite( |
| 8385 | "GET / HTTP/1.1\r\n" |
| 8386 | "Host: www.example.org\r\n" |
| 8387 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8388 | |
| 8389 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8390 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8391 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8392 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 8393 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8394 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8395 | }; |
| 8396 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8397 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8398 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8399 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8400 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8401 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8402 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8403 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8404 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8405 | |
| 8406 | rv = callback.WaitForResult(); |
| 8407 | EXPECT_EQ(OK, rv); |
| 8408 | |
| 8409 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8410 | ASSERT_TRUE(response != NULL); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8411 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8412 | LoadTimingInfo load_timing_info; |
| 8413 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 8414 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8415 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 8416 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8417 | std::string response_text; |
| 8418 | rv = ReadTransaction(trans.get(), &response_text); |
| 8419 | EXPECT_EQ(OK, rv); |
| 8420 | EXPECT_EQ("Payload", response_text); |
| 8421 | } |
| 8422 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8423 | TEST_P(HttpNetworkTransactionTest, SOCKS4_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8424 | HttpRequestInfo request; |
| 8425 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8426 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8427 | request.load_flags = 0; |
| 8428 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8429 | session_deps_.proxy_service = |
| 8430 | ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8431 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8432 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8433 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8434 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8435 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8436 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8437 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8438 | unsigned char write_buffer[] = { 0x04, 0x01, 0x01, 0xBB, 127, 0, 0, 1, 0 }; |
| 8439 | unsigned char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 8440 | |
| 8441 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8442 | MockWrite(ASYNC, reinterpret_cast<char*>(write_buffer), |
| 8443 | arraysize(write_buffer)), |
| 8444 | MockWrite( |
| 8445 | "GET / HTTP/1.1\r\n" |
| 8446 | "Host: www.example.org\r\n" |
| 8447 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8448 | |
| 8449 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 8450 | MockRead(ASYNC, reinterpret_cast<char*>(read_buffer), |
| 8451 | arraysize(read_buffer)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8452 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8453 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 8454 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8455 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8456 | }; |
| 8457 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8458 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8459 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8460 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8461 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8462 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8463 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8464 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8465 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8466 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8467 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8468 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8469 | |
| 8470 | rv = callback.WaitForResult(); |
| 8471 | EXPECT_EQ(OK, rv); |
| 8472 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8473 | LoadTimingInfo load_timing_info; |
| 8474 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 8475 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8476 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 8477 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8478 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8479 | ASSERT_TRUE(response != NULL); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8480 | |
| 8481 | std::string response_text; |
| 8482 | rv = ReadTransaction(trans.get(), &response_text); |
| 8483 | EXPECT_EQ(OK, rv); |
| 8484 | EXPECT_EQ("Payload", response_text); |
| 8485 | } |
| 8486 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8487 | TEST_P(HttpNetworkTransactionTest, SOCKS4_HTTP_GET_no_PAC) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8488 | HttpRequestInfo request; |
| 8489 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8490 | request.url = GURL("http://www.example.org/"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8491 | request.load_flags = 0; |
| 8492 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8493 | session_deps_.proxy_service = |
| 8494 | ProxyService::CreateFixed("socks4://myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8495 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8496 | session_deps_.net_log = &net_log; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8497 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8498 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8499 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8500 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8501 | |
| 8502 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 8503 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 8504 | |
| 8505 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8506 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
| 8507 | MockWrite( |
| 8508 | "GET / HTTP/1.1\r\n" |
| 8509 | "Host: www.example.org\r\n" |
| 8510 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8511 | |
| 8512 | MockRead data_reads[] = { |
| 8513 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
| 8514 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8515 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 8516 | MockRead("Payload"), |
| 8517 | MockRead(SYNCHRONOUS, OK) |
| 8518 | }; |
| 8519 | |
| 8520 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8521 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8522 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8523 | |
| 8524 | TestCompletionCallback callback; |
| 8525 | |
| 8526 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 8527 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8528 | |
| 8529 | rv = callback.WaitForResult(); |
| 8530 | EXPECT_EQ(OK, rv); |
| 8531 | |
| 8532 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8533 | ASSERT_TRUE(response != NULL); |
| 8534 | |
| 8535 | LoadTimingInfo load_timing_info; |
| 8536 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 8537 | TestLoadTimingNotReused(load_timing_info, |
| 8538 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 8539 | |
| 8540 | std::string response_text; |
| 8541 | rv = ReadTransaction(trans.get(), &response_text); |
| 8542 | EXPECT_EQ(OK, rv); |
| 8543 | EXPECT_EQ("Payload", response_text); |
| 8544 | } |
| 8545 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8546 | TEST_P(HttpNetworkTransactionTest, SOCKS5_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8547 | HttpRequestInfo request; |
| 8548 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8549 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8550 | request.load_flags = 0; |
| 8551 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8552 | session_deps_.proxy_service = |
| 8553 | ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8554 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8555 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8556 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8557 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8558 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8559 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8560 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8561 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 8562 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 8563 | const char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8564 | 0x05, // Version |
| 8565 | 0x01, // Command (CONNECT) |
| 8566 | 0x00, // Reserved. |
| 8567 | 0x03, // Address type (DOMAINNAME). |
| 8568 | 0x0F, // Length of domain (15) |
| 8569 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 8570 | '.', 'o', 'r', 'g', 0x00, 0x50, // 16-bit port (80) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 8571 | }; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8572 | const char kSOCKS5OkResponse[] = |
| 8573 | { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; |
| 8574 | |
| 8575 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8576 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 8577 | MockWrite(ASYNC, kSOCKS5OkRequest, arraysize(kSOCKS5OkRequest)), |
| 8578 | MockWrite( |
| 8579 | "GET / HTTP/1.1\r\n" |
| 8580 | "Host: www.example.org\r\n" |
| 8581 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8582 | |
| 8583 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 8584 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 8585 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8586 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8587 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 8588 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8589 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8590 | }; |
| 8591 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8592 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8593 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8594 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8595 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8596 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8597 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8598 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8599 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8600 | |
| 8601 | rv = callback.WaitForResult(); |
| 8602 | EXPECT_EQ(OK, rv); |
| 8603 | |
| 8604 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8605 | ASSERT_TRUE(response != NULL); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8606 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8607 | LoadTimingInfo load_timing_info; |
| 8608 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 8609 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8610 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 8611 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8612 | std::string response_text; |
| 8613 | rv = ReadTransaction(trans.get(), &response_text); |
| 8614 | EXPECT_EQ(OK, rv); |
| 8615 | EXPECT_EQ("Payload", response_text); |
| 8616 | } |
| 8617 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8618 | TEST_P(HttpNetworkTransactionTest, SOCKS5_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8619 | HttpRequestInfo request; |
| 8620 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8621 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8622 | request.load_flags = 0; |
| 8623 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8624 | session_deps_.proxy_service = |
| 8625 | ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8626 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8627 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8628 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8629 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8630 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8631 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8632 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8633 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 8634 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 8635 | const unsigned char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8636 | 0x05, // Version |
| 8637 | 0x01, // Command (CONNECT) |
| 8638 | 0x00, // Reserved. |
| 8639 | 0x03, // Address type (DOMAINNAME). |
| 8640 | 0x0F, // Length of domain (15) |
| 8641 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 8642 | '.', 'o', 'r', 'g', 0x01, 0xBB, // 16-bit port (443) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 8643 | }; |
| 8644 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8645 | const char kSOCKS5OkResponse[] = |
| 8646 | { 0x05, 0x00, 0x00, 0x01, 0, 0, 0, 0, 0x00, 0x00 }; |
| 8647 | |
| 8648 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8649 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 8650 | MockWrite(ASYNC, reinterpret_cast<const char*>(kSOCKS5OkRequest), |
| 8651 | arraysize(kSOCKS5OkRequest)), |
| 8652 | MockWrite( |
| 8653 | "GET / HTTP/1.1\r\n" |
| 8654 | "Host: www.example.org\r\n" |
| 8655 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8656 | |
| 8657 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 8658 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 8659 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8660 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8661 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 8662 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8663 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8664 | }; |
| 8665 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8666 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8667 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8668 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8669 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8670 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8671 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8672 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8673 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8674 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8675 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8676 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8677 | |
| 8678 | rv = callback.WaitForResult(); |
| 8679 | EXPECT_EQ(OK, rv); |
| 8680 | |
| 8681 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8682 | ASSERT_TRUE(response != NULL); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8683 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8684 | LoadTimingInfo load_timing_info; |
| 8685 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 8686 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8687 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 8688 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8689 | std::string response_text; |
| 8690 | rv = ReadTransaction(trans.get(), &response_text); |
| 8691 | EXPECT_EQ(OK, rv); |
| 8692 | EXPECT_EQ("Payload", response_text); |
| 8693 | } |
| 8694 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 8695 | namespace { |
| 8696 | |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 8697 | // Tests that for connection endpoints the group names are correctly set. |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8698 | |
| 8699 | struct GroupNameTest { |
| 8700 | std::string proxy_server; |
| 8701 | std::string url; |
| 8702 | std::string expected_group_name; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 8703 | bool ssl; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8704 | }; |
| 8705 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8706 | scoped_ptr<HttpNetworkSession> SetupSessionForGroupNameTests( |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8707 | NextProto next_proto, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8708 | SpdySessionDependencies* session_deps_) { |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8709 | scoped_ptr<HttpNetworkSession> session(CreateSession(session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8710 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 8711 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8712 | session->http_server_properties(); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 8713 | AlternativeService alternative_service( |
bnc | 4988e43 | 2015-03-31 03:06:25 | [diff] [blame] | 8714 | AlternateProtocolFromNextProto(next_proto), "", 443); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 8715 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 8716 | http_server_properties->SetAlternativeService( |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 8717 | HostPortPair("host.with.alternate", 80), alternative_service, 1.0, |
| 8718 | expiration); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8719 | |
| 8720 | return session; |
| 8721 | } |
| 8722 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8723 | int GroupNameTransactionHelper(const std::string& url, |
| 8724 | HttpNetworkSession* session) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8725 | HttpRequestInfo request; |
| 8726 | request.method = "GET"; |
| 8727 | request.url = GURL(url); |
| 8728 | request.load_flags = 0; |
| 8729 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8730 | scoped_ptr<HttpTransaction> trans( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8731 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8732 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8733 | TestCompletionCallback callback; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8734 | |
| 8735 | // We do not complete this request, the dtor will clean the transaction up. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8736 | return trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8737 | } |
| 8738 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 8739 | } // namespace |
| 8740 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8741 | TEST_P(HttpNetworkTransactionTest, GroupNameForDirectConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8742 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8743 | { |
| 8744 | "", // unused |
| 8745 | "http://www.example.org/direct", |
| 8746 | "www.example.org:80", |
| 8747 | false, |
| 8748 | }, |
| 8749 | { |
| 8750 | "", // unused |
| 8751 | "http://[2001:1418:13:1::25]/direct", |
| 8752 | "[2001:1418:13:1::25]:80", |
| 8753 | false, |
| 8754 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 8755 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8756 | // SSL Tests |
| 8757 | { |
| 8758 | "", // unused |
| 8759 | "https://www.example.org/direct_ssl", |
| 8760 | "ssl/www.example.org:443", |
| 8761 | true, |
| 8762 | }, |
| 8763 | { |
| 8764 | "", // unused |
| 8765 | "https://[2001:1418:13:1::25]/direct", |
| 8766 | "ssl/[2001:1418:13:1::25]:443", |
| 8767 | true, |
| 8768 | }, |
| 8769 | { |
| 8770 | "", // unused |
| 8771 | "http://host.with.alternate/direct", |
| 8772 | "ssl/host.with.alternate:443", |
| 8773 | true, |
| 8774 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8775 | }; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8776 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 8777 | session_deps_.use_alternative_services = true; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8778 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 8779 | for (size_t i = 0; i < arraysize(tests); ++i) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8780 | session_deps_.proxy_service = |
| 8781 | ProxyService::CreateFixed(tests[i].proxy_server); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8782 | scoped_ptr<HttpNetworkSession> session( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 8783 | SetupSessionForGroupNameTests(GetProtocol(), &session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8784 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8785 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 8786 | CaptureGroupNameTransportSocketPool* transport_conn_pool = |
| 8787 | new CaptureGroupNameTransportSocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 8788 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 8789 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 8790 | scoped_ptr<MockClientSocketPoolManager> mock_pool_manager( |
| 8791 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 8792 | mock_pool_manager->SetTransportSocketPool(transport_conn_pool); |
| 8793 | mock_pool_manager->SetSSLSocketPool(ssl_conn_pool); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 8794 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8795 | |
| 8796 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8797 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 8798 | if (tests[i].ssl) |
| 8799 | EXPECT_EQ(tests[i].expected_group_name, |
| 8800 | ssl_conn_pool->last_group_name_received()); |
| 8801 | else |
| 8802 | EXPECT_EQ(tests[i].expected_group_name, |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 8803 | transport_conn_pool->last_group_name_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8804 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8805 | } |
| 8806 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8807 | TEST_P(HttpNetworkTransactionTest, GroupNameForHTTPProxyConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8808 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8809 | { |
| 8810 | "http_proxy", |
| 8811 | "http://www.example.org/http_proxy_normal", |
| 8812 | "www.example.org:80", |
| 8813 | false, |
| 8814 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8815 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8816 | // SSL Tests |
| 8817 | { |
| 8818 | "http_proxy", |
| 8819 | "https://www.example.org/http_connect_ssl", |
| 8820 | "ssl/www.example.org:443", |
| 8821 | true, |
| 8822 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 8823 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8824 | { |
| 8825 | "http_proxy", |
| 8826 | "http://host.with.alternate/direct", |
| 8827 | "ssl/host.with.alternate:443", |
| 8828 | true, |
| 8829 | }, |
[email protected] | 4549925 | 2013-01-23 17:12:56 | [diff] [blame] | 8830 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8831 | { |
| 8832 | "http_proxy", |
| 8833 | "ftp://ftp.google.com/http_proxy_normal", |
| 8834 | "ftp/ftp.google.com:21", |
| 8835 | false, |
| 8836 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8837 | }; |
| 8838 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 8839 | session_deps_.use_alternative_services = true; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8840 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 8841 | for (size_t i = 0; i < arraysize(tests); ++i) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8842 | session_deps_.proxy_service = |
| 8843 | ProxyService::CreateFixed(tests[i].proxy_server); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8844 | scoped_ptr<HttpNetworkSession> session( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 8845 | SetupSessionForGroupNameTests(GetProtocol(), &session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8846 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8847 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8848 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 8849 | HostPortPair proxy_host("http_proxy", 80); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 8850 | CaptureGroupNameHttpProxySocketPool* http_proxy_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 8851 | new CaptureGroupNameHttpProxySocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 8852 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 8853 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 8854 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 8855 | scoped_ptr<MockClientSocketPoolManager> mock_pool_manager( |
| 8856 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 8857 | mock_pool_manager->SetSocketPoolForHTTPProxy(proxy_host, http_proxy_pool); |
| 8858 | mock_pool_manager->SetSocketPoolForSSLWithProxy(proxy_host, ssl_conn_pool); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 8859 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8860 | |
| 8861 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8862 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 8863 | if (tests[i].ssl) |
| 8864 | EXPECT_EQ(tests[i].expected_group_name, |
| 8865 | ssl_conn_pool->last_group_name_received()); |
| 8866 | else |
| 8867 | EXPECT_EQ(tests[i].expected_group_name, |
| 8868 | http_proxy_pool->last_group_name_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8869 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8870 | } |
| 8871 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8872 | TEST_P(HttpNetworkTransactionTest, GroupNameForSOCKSConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8873 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8874 | { |
| 8875 | "socks4://socks_proxy:1080", |
| 8876 | "http://www.example.org/socks4_direct", |
| 8877 | "socks4/www.example.org:80", |
| 8878 | false, |
| 8879 | }, |
| 8880 | { |
| 8881 | "socks5://socks_proxy:1080", |
| 8882 | "http://www.example.org/socks5_direct", |
| 8883 | "socks5/www.example.org:80", |
| 8884 | false, |
| 8885 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8886 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8887 | // SSL Tests |
| 8888 | { |
| 8889 | "socks4://socks_proxy:1080", |
| 8890 | "https://www.example.org/socks4_ssl", |
| 8891 | "socks4/ssl/www.example.org:443", |
| 8892 | true, |
| 8893 | }, |
| 8894 | { |
| 8895 | "socks5://socks_proxy:1080", |
| 8896 | "https://www.example.org/socks5_ssl", |
| 8897 | "socks5/ssl/www.example.org:443", |
| 8898 | true, |
| 8899 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 8900 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8901 | { |
| 8902 | "socks4://socks_proxy:1080", |
| 8903 | "http://host.with.alternate/direct", |
| 8904 | "socks4/ssl/host.with.alternate:443", |
| 8905 | true, |
| 8906 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 8907 | }; |
| 8908 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 8909 | session_deps_.use_alternative_services = true; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8910 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 8911 | for (size_t i = 0; i < arraysize(tests); ++i) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8912 | session_deps_.proxy_service = |
| 8913 | ProxyService::CreateFixed(tests[i].proxy_server); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8914 | scoped_ptr<HttpNetworkSession> session( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 8915 | SetupSessionForGroupNameTests(GetProtocol(), &session_deps_)); |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 8916 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8917 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 8918 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 8919 | HostPortPair proxy_host("socks_proxy", 1080); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 8920 | CaptureGroupNameSOCKSSocketPool* socks_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 8921 | new CaptureGroupNameSOCKSSocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 8922 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 8923 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 8924 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 8925 | scoped_ptr<MockClientSocketPoolManager> mock_pool_manager( |
| 8926 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 8927 | mock_pool_manager->SetSocketPoolForSOCKSProxy(proxy_host, socks_conn_pool); |
| 8928 | mock_pool_manager->SetSocketPoolForSSLWithProxy(proxy_host, ssl_conn_pool); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 8929 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 8930 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8931 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8932 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 8933 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8934 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8935 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 8936 | if (tests[i].ssl) |
| 8937 | EXPECT_EQ(tests[i].expected_group_name, |
| 8938 | ssl_conn_pool->last_group_name_received()); |
| 8939 | else |
| 8940 | EXPECT_EQ(tests[i].expected_group_name, |
| 8941 | socks_conn_pool->last_group_name_received()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 8942 | } |
| 8943 | } |
| 8944 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8945 | TEST_P(HttpNetworkTransactionTest, ReconsiderProxyAfterFailedConnection) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8946 | HttpRequestInfo request; |
| 8947 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8948 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8949 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8950 | session_deps_.proxy_service = |
| 8951 | ProxyService::CreateFixed("myproxy:70;foobar:80"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 8952 | |
[email protected] | 6971906 | 2010-01-05 20:09:21 | [diff] [blame] | 8953 | // This simulates failure resolving all hostnames; that means we will fail |
| 8954 | // connecting to both proxies (myproxy:70 and foobar:80). |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8955 | session_deps_.host_resolver->rules()->AddSimulatedFailure("*"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 8956 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8957 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 8958 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8959 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 8960 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8961 | TestCompletionCallback callback; |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 8962 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8963 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 8964 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8965 | |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 8966 | rv = callback.WaitForResult(); |
[email protected] | f7fccee | 2010-09-16 20:53:01 | [diff] [blame] | 8967 | EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, rv); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 8968 | } |
| 8969 | |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 8970 | // Base test to make sure that when the load flags for a request specify to |
| 8971 | // bypass the cache, the DNS cache is not used. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8972 | void HttpNetworkTransactionTest::BypassHostCacheOnRefreshHelper( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8973 | int load_flags) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8974 | // Issue a request, asking to bypass the cache(s). |
| 8975 | HttpRequestInfo request; |
| 8976 | request.method = "GET"; |
| 8977 | request.load_flags = load_flags; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8978 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8979 | |
[email protected] | a2c2fb9 | 2009-07-18 07:31:04 | [diff] [blame] | 8980 | // Select a host resolver that does caching. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8981 | session_deps_.host_resolver.reset(new MockCachingHostResolver); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 8982 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8983 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8984 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8985 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8986 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8987 | // 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] | 8988 | AddressList addrlist; |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 8989 | TestCompletionCallback callback; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8990 | int rv = session_deps_.host_resolver->Resolve( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8991 | HostResolver::RequestInfo(HostPortPair("www.example.org", 80)), |
| 8992 | DEFAULT_PRIORITY, &addrlist, callback.callback(), NULL, BoundNetLog()); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 8993 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8994 | rv = callback.WaitForResult(); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8995 | EXPECT_EQ(OK, rv); |
| 8996 | |
| 8997 | // Verify that it was added to host cache, by doing a subsequent async lookup |
| 8998 | // and confirming it completes synchronously. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8999 | rv = session_deps_.host_resolver->Resolve( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9000 | HostResolver::RequestInfo(HostPortPair("www.example.org", 80)), |
| 9001 | DEFAULT_PRIORITY, &addrlist, callback.callback(), NULL, BoundNetLog()); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 9002 | ASSERT_EQ(OK, rv); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9003 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9004 | // 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] | 9005 | // we can tell if the next lookup hit the cache, or the "network". |
| 9006 | // (cache --> success, "network" --> failure). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9007 | session_deps_.host_resolver->rules()->AddSimulatedFailure("www.example.org"); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9008 | |
| 9009 | // Connect up a mock socket which will fail with ERR_UNEXPECTED during the |
| 9010 | // 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] | 9011 | MockRead data_reads[] = { MockRead(SYNCHRONOUS, ERR_UNEXPECTED) }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9012 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9013 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9014 | |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9015 | // Run the request. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9016 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9017 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9018 | rv = callback.WaitForResult(); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9019 | |
| 9020 | // If we bypassed the cache, we would have gotten a failure while resolving |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9021 | // "www.example.org". |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9022 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, rv); |
| 9023 | } |
| 9024 | |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9025 | // There are multiple load flags that should trigger the host cache bypass. |
| 9026 | // Test each in isolation: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9027 | TEST_P(HttpNetworkTransactionTest, BypassHostCacheOnRefresh1) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9028 | BypassHostCacheOnRefreshHelper(LOAD_BYPASS_CACHE); |
| 9029 | } |
| 9030 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9031 | TEST_P(HttpNetworkTransactionTest, BypassHostCacheOnRefresh2) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9032 | BypassHostCacheOnRefreshHelper(LOAD_VALIDATE_CACHE); |
| 9033 | } |
| 9034 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9035 | TEST_P(HttpNetworkTransactionTest, BypassHostCacheOnRefresh3) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9036 | BypassHostCacheOnRefreshHelper(LOAD_DISABLE_CACHE); |
| 9037 | } |
| 9038 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9039 | // Make sure we can handle an error when writing the request. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9040 | TEST_P(HttpNetworkTransactionTest, RequestWriteError) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9041 | HttpRequestInfo request; |
| 9042 | request.method = "GET"; |
| 9043 | request.url = GURL("http://www.foo.com/"); |
| 9044 | request.load_flags = 0; |
| 9045 | |
| 9046 | MockWrite write_failure[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9047 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9048 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9049 | StaticSocketDataProvider data(NULL, 0, |
| 9050 | write_failure, arraysize(write_failure)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9051 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9052 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9053 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9054 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9055 | |
| 9056 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 9057 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9058 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9059 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9060 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9061 | |
| 9062 | rv = callback.WaitForResult(); |
| 9063 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 9064 | |
| 9065 | IPEndPoint endpoint; |
| 9066 | EXPECT_TRUE(trans->GetRemoteEndpoint(&endpoint)); |
| 9067 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9068 | } |
| 9069 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9070 | // Check that a connection closed after the start of the headers finishes ok. |
| 9071 | TEST_P(HttpNetworkTransactionTest, ConnectionClosedAfterStartOfHeaders) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9072 | HttpRequestInfo request; |
| 9073 | request.method = "GET"; |
| 9074 | request.url = GURL("http://www.foo.com/"); |
| 9075 | request.load_flags = 0; |
| 9076 | |
| 9077 | MockRead data_reads[] = { |
| 9078 | MockRead("HTTP/1."), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9079 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9080 | }; |
| 9081 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9082 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9083 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9084 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9085 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9086 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9087 | |
| 9088 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 9089 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9090 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9091 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9092 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9093 | |
| 9094 | rv = callback.WaitForResult(); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9095 | EXPECT_EQ(OK, rv); |
| 9096 | |
| 9097 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9098 | ASSERT_TRUE(response != NULL); |
| 9099 | |
| 9100 | EXPECT_TRUE(response->headers.get() != NULL); |
| 9101 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 9102 | |
| 9103 | std::string response_data; |
| 9104 | rv = ReadTransaction(trans.get(), &response_data); |
| 9105 | EXPECT_EQ(OK, rv); |
| 9106 | EXPECT_EQ("", response_data); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 9107 | |
| 9108 | IPEndPoint endpoint; |
| 9109 | EXPECT_TRUE(trans->GetRemoteEndpoint(&endpoint)); |
| 9110 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9111 | } |
| 9112 | |
| 9113 | // Make sure that a dropped connection while draining the body for auth |
| 9114 | // restart does the right thing. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9115 | TEST_P(HttpNetworkTransactionTest, DrainResetOK) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9116 | HttpRequestInfo request; |
| 9117 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9118 | request.url = GURL("http://www.example.org/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9119 | request.load_flags = 0; |
| 9120 | |
| 9121 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9122 | MockWrite( |
| 9123 | "GET / HTTP/1.1\r\n" |
| 9124 | "Host: www.example.org\r\n" |
| 9125 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9126 | }; |
| 9127 | |
| 9128 | MockRead data_reads1[] = { |
| 9129 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 9130 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 9131 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9132 | MockRead("Content-Length: 14\r\n\r\n"), |
| 9133 | MockRead("Unauth"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9134 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9135 | }; |
| 9136 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9137 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 9138 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9139 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9140 | |
| 9141 | // After calling trans->RestartWithAuth(), this is the request we should |
| 9142 | // be issuing -- the final header line contains the credentials. |
| 9143 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9144 | MockWrite( |
| 9145 | "GET / HTTP/1.1\r\n" |
| 9146 | "Host: www.example.org\r\n" |
| 9147 | "Connection: keep-alive\r\n" |
| 9148 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9149 | }; |
| 9150 | |
| 9151 | // Lastly, the server responds with the actual content. |
| 9152 | MockRead data_reads2[] = { |
| 9153 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9154 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9155 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9156 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9157 | }; |
| 9158 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9159 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 9160 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9161 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9162 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9163 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9164 | TestCompletionCallback callback1; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9165 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9166 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9167 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 9168 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9169 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9170 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9171 | |
| 9172 | rv = callback1.WaitForResult(); |
| 9173 | EXPECT_EQ(OK, rv); |
| 9174 | |
| 9175 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 9176 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9177 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9178 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9179 | TestCompletionCallback callback2; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9180 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9181 | rv = trans->RestartWithAuth( |
| 9182 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9183 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9184 | |
| 9185 | rv = callback2.WaitForResult(); |
| 9186 | EXPECT_EQ(OK, rv); |
| 9187 | |
| 9188 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 9189 | ASSERT_TRUE(response != NULL); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9190 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 9191 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9192 | } |
| 9193 | |
| 9194 | // Test HTTPS connections going through a proxy that sends extra data. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9195 | TEST_P(HttpNetworkTransactionTest, HTTPSViaProxyWithExtraData) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9196 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9197 | |
| 9198 | HttpRequestInfo request; |
| 9199 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9200 | request.url = GURL("https://www.example.org/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9201 | request.load_flags = 0; |
| 9202 | |
| 9203 | MockRead proxy_reads[] = { |
| 9204 | MockRead("HTTP/1.0 200 Connected\r\n\r\nExtra data"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9205 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9206 | }; |
| 9207 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9208 | StaticSocketDataProvider data(proxy_reads, arraysize(proxy_reads), NULL, 0); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9209 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9210 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9211 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9212 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9213 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9214 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9215 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9216 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9217 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9218 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9219 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 9220 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9221 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9222 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9223 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9224 | |
| 9225 | rv = callback.WaitForResult(); |
| 9226 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
| 9227 | } |
| 9228 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9229 | TEST_P(HttpNetworkTransactionTest, LargeContentLengthThenClose) { |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9230 | HttpRequestInfo request; |
| 9231 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9232 | request.url = GURL("http://www.example.org/"); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9233 | request.load_flags = 0; |
| 9234 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9235 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9236 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 9237 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9238 | |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 9239 | MockRead data_reads[] = { |
| 9240 | 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] | 9241 | MockRead(SYNCHRONOUS, OK), |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 9242 | }; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9243 | |
| 9244 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9245 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9246 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9247 | TestCompletionCallback callback; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9248 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9249 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9250 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9251 | |
| 9252 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9253 | |
| 9254 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 9255 | ASSERT_TRUE(response != NULL); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9256 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9257 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9258 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 9259 | |
| 9260 | std::string response_data; |
| 9261 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 5543cbb | 2012-04-20 16:35:23 | [diff] [blame] | 9262 | EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, rv); |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 9263 | } |
| 9264 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9265 | TEST_P(HttpNetworkTransactionTest, UploadFileSmallerThanLength) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 9266 | base::FilePath temp_file_path; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 9267 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file_path)); |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 9268 | const uint64_t kFakeSize = 100000; // file is actually blank |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 9269 | UploadFileElementReader::ScopedOverridingContentLengthForTests |
| 9270 | overriding_content_length(kFakeSize); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9271 | |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 9272 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 9273 | element_readers.push_back(make_scoped_ptr(new UploadFileElementReader( |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 9274 | base::ThreadTaskRunnerHandle::Get().get(), temp_file_path, 0, |
| 9275 | std::numeric_limits<uint64_t>::max(), base::Time()))); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 9276 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9277 | |
| 9278 | HttpRequestInfo request; |
| 9279 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9280 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9281 | request.upload_data_stream = &upload_data_stream; |
| 9282 | request.load_flags = 0; |
| 9283 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9284 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9285 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 9286 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9287 | |
| 9288 | MockRead data_reads[] = { |
| 9289 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 9290 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9291 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9292 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9293 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9294 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9295 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9296 | TestCompletionCallback callback; |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9297 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9298 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9299 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9300 | |
| 9301 | rv = callback.WaitForResult(); |
| 9302 | EXPECT_EQ(OK, rv); |
| 9303 | |
| 9304 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 9305 | ASSERT_TRUE(response != NULL); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9306 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9307 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9308 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 9309 | |
| 9310 | std::string response_data; |
| 9311 | rv = ReadTransaction(trans.get(), &response_data); |
| 9312 | EXPECT_EQ(OK, rv); |
| 9313 | EXPECT_EQ("hello world", response_data); |
| 9314 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 9315 | base::DeleteFile(temp_file_path, false); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9316 | } |
| 9317 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9318 | TEST_P(HttpNetworkTransactionTest, UploadUnreadableFile) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 9319 | base::FilePath temp_file; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 9320 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9321 | std::string temp_file_content("Unreadable file."); |
[email protected] | e5c2a22e | 2014-03-06 20:42:30 | [diff] [blame] | 9322 | ASSERT_TRUE(base::WriteFile(temp_file, temp_file_content.c_str(), |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9323 | temp_file_content.length())); |
[email protected] | 92be8eb | 2014-08-07 22:57:11 | [diff] [blame] | 9324 | ASSERT_TRUE(base::MakeFileUnreadable(temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9325 | |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 9326 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 9327 | element_readers.push_back(make_scoped_ptr(new UploadFileElementReader( |
| 9328 | base::ThreadTaskRunnerHandle::Get().get(), temp_file, 0, |
| 9329 | std::numeric_limits<uint64_t>::max(), base::Time()))); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 9330 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9331 | |
| 9332 | HttpRequestInfo request; |
| 9333 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9334 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9335 | request.upload_data_stream = &upload_data_stream; |
| 9336 | request.load_flags = 0; |
| 9337 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 9338 | // If we try to upload an unreadable file, the transaction should fail. |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9339 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9340 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 9341 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9342 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 9343 | StaticSocketDataProvider data(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9344 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9345 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9346 | TestCompletionCallback callback; |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9347 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9348 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9349 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9350 | |
| 9351 | rv = callback.WaitForResult(); |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 9352 | EXPECT_EQ(ERR_ACCESS_DENIED, rv); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9353 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 9354 | base::DeleteFile(temp_file, false); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9355 | } |
| 9356 | |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9357 | TEST_P(HttpNetworkTransactionTest, CancelDuringInitRequestBody) { |
| 9358 | class FakeUploadElementReader : public UploadElementReader { |
| 9359 | public: |
| 9360 | FakeUploadElementReader() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9361 | ~FakeUploadElementReader() override {} |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9362 | |
| 9363 | const CompletionCallback& callback() const { return callback_; } |
| 9364 | |
| 9365 | // UploadElementReader overrides: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9366 | int Init(const CompletionCallback& callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9367 | callback_ = callback; |
| 9368 | return ERR_IO_PENDING; |
| 9369 | } |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 9370 | uint64_t GetContentLength() const override { return 0; } |
| 9371 | uint64_t BytesRemaining() const override { return 0; } |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9372 | int Read(IOBuffer* buf, |
| 9373 | int buf_length, |
| 9374 | const CompletionCallback& callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9375 | return ERR_FAILED; |
| 9376 | } |
| 9377 | |
| 9378 | private: |
| 9379 | CompletionCallback callback_; |
| 9380 | }; |
| 9381 | |
| 9382 | FakeUploadElementReader* fake_reader = new FakeUploadElementReader; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 9383 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 9384 | element_readers.push_back(make_scoped_ptr(fake_reader)); |
| 9385 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9386 | |
| 9387 | HttpRequestInfo request; |
| 9388 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9389 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9390 | request.upload_data_stream = &upload_data_stream; |
| 9391 | request.load_flags = 0; |
| 9392 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9393 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9394 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 9395 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9396 | |
| 9397 | StaticSocketDataProvider data; |
| 9398 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9399 | |
| 9400 | TestCompletionCallback callback; |
| 9401 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 9402 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9403 | base::MessageLoop::current()->RunUntilIdle(); |
| 9404 | |
| 9405 | // Transaction is pending on request body initialization. |
| 9406 | ASSERT_FALSE(fake_reader->callback().is_null()); |
| 9407 | |
| 9408 | // Return Init()'s result after the transaction gets destroyed. |
| 9409 | trans.reset(); |
| 9410 | fake_reader->callback().Run(OK); // Should not crash. |
| 9411 | } |
| 9412 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9413 | // Tests that changes to Auth realms are treated like auth rejections. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9414 | TEST_P(HttpNetworkTransactionTest, ChangeAuthRealms) { |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9415 | HttpRequestInfo request; |
| 9416 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9417 | request.url = GURL("http://www.example.org/"); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9418 | request.load_flags = 0; |
| 9419 | |
| 9420 | // First transaction will request a resource and receive a Basic challenge |
| 9421 | // with realm="first_realm". |
| 9422 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9423 | MockWrite( |
| 9424 | "GET / HTTP/1.1\r\n" |
| 9425 | "Host: www.example.org\r\n" |
| 9426 | "Connection: keep-alive\r\n" |
| 9427 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9428 | }; |
| 9429 | MockRead data_reads1[] = { |
| 9430 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 9431 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 9432 | "\r\n"), |
| 9433 | }; |
| 9434 | |
| 9435 | // After calling trans->RestartWithAuth(), provide an Authentication header |
| 9436 | // for first_realm. The server will reject and provide a challenge with |
| 9437 | // second_realm. |
| 9438 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9439 | MockWrite( |
| 9440 | "GET / HTTP/1.1\r\n" |
| 9441 | "Host: www.example.org\r\n" |
| 9442 | "Connection: keep-alive\r\n" |
| 9443 | "Authorization: Basic Zmlyc3Q6YmF6\r\n" |
| 9444 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9445 | }; |
| 9446 | MockRead data_reads2[] = { |
| 9447 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 9448 | "WWW-Authenticate: Basic realm=\"second_realm\"\r\n" |
| 9449 | "\r\n"), |
| 9450 | }; |
| 9451 | |
| 9452 | // This again fails, and goes back to first_realm. Make sure that the |
| 9453 | // entry is removed from cache. |
| 9454 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9455 | MockWrite( |
| 9456 | "GET / HTTP/1.1\r\n" |
| 9457 | "Host: www.example.org\r\n" |
| 9458 | "Connection: keep-alive\r\n" |
| 9459 | "Authorization: Basic c2Vjb25kOmZvdQ==\r\n" |
| 9460 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9461 | }; |
| 9462 | MockRead data_reads3[] = { |
| 9463 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 9464 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 9465 | "\r\n"), |
| 9466 | }; |
| 9467 | |
| 9468 | // Try one last time (with the correct password) and get the resource. |
| 9469 | MockWrite data_writes4[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9470 | MockWrite( |
| 9471 | "GET / HTTP/1.1\r\n" |
| 9472 | "Host: www.example.org\r\n" |
| 9473 | "Connection: keep-alive\r\n" |
| 9474 | "Authorization: Basic Zmlyc3Q6YmFy\r\n" |
| 9475 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9476 | }; |
| 9477 | MockRead data_reads4[] = { |
| 9478 | MockRead("HTTP/1.1 200 OK\r\n" |
| 9479 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 9480 | "Content-Length: 5\r\n" |
| 9481 | "\r\n" |
| 9482 | "hello"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9483 | }; |
| 9484 | |
| 9485 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 9486 | data_writes1, arraysize(data_writes1)); |
| 9487 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 9488 | data_writes2, arraysize(data_writes2)); |
| 9489 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 9490 | data_writes3, arraysize(data_writes3)); |
| 9491 | StaticSocketDataProvider data4(data_reads4, arraysize(data_reads4), |
| 9492 | data_writes4, arraysize(data_writes4)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9493 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 9494 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 9495 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 9496 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9497 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9498 | TestCompletionCallback callback1; |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9499 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9500 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 9501 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 9502 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 9503 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9504 | // Issue the first request with Authorize headers. There should be a |
| 9505 | // password prompt for first_realm waiting to be filled in after the |
| 9506 | // transaction completes. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9507 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9508 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9509 | rv = callback1.WaitForResult(); |
| 9510 | EXPECT_EQ(OK, rv); |
| 9511 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 9512 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9513 | const AuthChallengeInfo* challenge = response->auth_challenge.get(); |
| 9514 | ASSERT_FALSE(challenge == NULL); |
| 9515 | EXPECT_FALSE(challenge->is_proxy); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9516 | EXPECT_EQ("www.example.org:80", challenge->challenger.ToString()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9517 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 9518 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9519 | |
| 9520 | // Issue the second request with an incorrect password. There should be a |
| 9521 | // password prompt for second_realm waiting to be filled in after the |
| 9522 | // transaction completes. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9523 | TestCompletionCallback callback2; |
| 9524 | rv = trans->RestartWithAuth( |
| 9525 | AuthCredentials(kFirst, kBaz), callback2.callback()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9526 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9527 | rv = callback2.WaitForResult(); |
| 9528 | EXPECT_EQ(OK, rv); |
| 9529 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 9530 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9531 | challenge = response->auth_challenge.get(); |
| 9532 | ASSERT_FALSE(challenge == NULL); |
| 9533 | EXPECT_FALSE(challenge->is_proxy); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9534 | EXPECT_EQ("www.example.org:80", challenge->challenger.ToString()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9535 | EXPECT_EQ("second_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 9536 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9537 | |
| 9538 | // Issue the third request with another incorrect password. There should be |
| 9539 | // a password prompt for first_realm waiting to be filled in. If the password |
| 9540 | // prompt is not present, it indicates that the HttpAuthCacheEntry for |
| 9541 | // first_realm was not correctly removed. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9542 | TestCompletionCallback callback3; |
| 9543 | rv = trans->RestartWithAuth( |
| 9544 | AuthCredentials(kSecond, kFou), callback3.callback()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9545 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9546 | rv = callback3.WaitForResult(); |
| 9547 | EXPECT_EQ(OK, rv); |
| 9548 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 9549 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9550 | challenge = response->auth_challenge.get(); |
| 9551 | ASSERT_FALSE(challenge == NULL); |
| 9552 | EXPECT_FALSE(challenge->is_proxy); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9553 | EXPECT_EQ("www.example.org:80", challenge->challenger.ToString()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9554 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 9555 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9556 | |
| 9557 | // Issue the fourth request with the correct password and username. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9558 | TestCompletionCallback callback4; |
| 9559 | rv = trans->RestartWithAuth( |
| 9560 | AuthCredentials(kFirst, kBar), callback4.callback()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9561 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9562 | rv = callback4.WaitForResult(); |
| 9563 | EXPECT_EQ(OK, rv); |
| 9564 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 9565 | ASSERT_TRUE(response != NULL); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9566 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 9567 | } |
| 9568 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9569 | TEST_P(HttpNetworkTransactionTest, HonorAlternativeServiceHeader) { |
| 9570 | session_deps_.next_protos = SpdyNextProtos(); |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9571 | session_deps_.use_alternative_services = true; |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9572 | |
| 9573 | std::string alternative_service_http_header = |
| 9574 | GetAlternativeServiceHttpHeader(); |
| 9575 | |
| 9576 | MockRead data_reads[] = { |
| 9577 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9578 | MockRead(alternative_service_http_header.c_str()), |
| 9579 | MockRead("\r\n"), |
| 9580 | MockRead("hello world"), |
| 9581 | MockRead(SYNCHRONOUS, OK), |
| 9582 | }; |
| 9583 | |
| 9584 | HttpRequestInfo request; |
| 9585 | request.method = "GET"; |
| 9586 | request.url = GURL("http://www.example.org/"); |
| 9587 | request.load_flags = 0; |
| 9588 | |
| 9589 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 9590 | |
| 9591 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9592 | |
| 9593 | TestCompletionCallback callback; |
| 9594 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9595 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9596 | scoped_ptr<HttpTransaction> trans( |
| 9597 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 9598 | |
| 9599 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 9600 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9601 | |
| 9602 | HostPortPair http_host_port_pair("www.example.org", 80); |
| 9603 | HttpServerProperties& http_server_properties = |
| 9604 | *session->http_server_properties(); |
| 9605 | AlternativeServiceVector alternative_service_vector = |
| 9606 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9607 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 9608 | |
| 9609 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9610 | |
| 9611 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9612 | ASSERT_TRUE(response != NULL); |
| 9613 | ASSERT_TRUE(response->headers.get() != NULL); |
| 9614 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9615 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9616 | EXPECT_FALSE(response->was_npn_negotiated); |
| 9617 | |
| 9618 | std::string response_data; |
| 9619 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9620 | EXPECT_EQ("hello world", response_data); |
| 9621 | |
| 9622 | alternative_service_vector = |
| 9623 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9624 | ASSERT_EQ(1u, alternative_service_vector.size()); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 9625 | EXPECT_EQ(AlternateProtocolFromNextProto(GetProtocol()), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9626 | alternative_service_vector[0].protocol); |
| 9627 | EXPECT_EQ("www.example.com", alternative_service_vector[0].host); |
| 9628 | EXPECT_EQ(443, alternative_service_vector[0].port); |
| 9629 | } |
| 9630 | |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 9631 | TEST_P(HttpNetworkTransactionTest, ClearAlternativeServices) { |
| 9632 | session_deps_.next_protos = SpdyNextProtos(); |
| 9633 | session_deps_.use_alternative_services = true; |
| 9634 | |
| 9635 | // Set an alternative service for origin. |
| 9636 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 9637 | HttpServerProperties& http_server_properties = |
| 9638 | *session->http_server_properties(); |
| 9639 | HostPortPair http_host_port_pair("www.example.org", 80); |
| 9640 | AlternativeService alternative_service(QUIC, "", 80); |
| 9641 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 9642 | http_server_properties.SetAlternativeService( |
| 9643 | http_host_port_pair, alternative_service, 1.0, expiration); |
| 9644 | AlternativeServiceVector alternative_service_vector = |
| 9645 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9646 | EXPECT_EQ(1u, alternative_service_vector.size()); |
| 9647 | |
| 9648 | // Send a clear header. |
| 9649 | MockRead data_reads[] = { |
| 9650 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9651 | MockRead("Alt-Svc: clear\r\n"), |
| 9652 | MockRead("\r\n"), |
| 9653 | MockRead("hello world"), |
| 9654 | MockRead(SYNCHRONOUS, OK), |
| 9655 | }; |
| 9656 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), nullptr, 0); |
| 9657 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9658 | |
| 9659 | HttpRequestInfo request; |
| 9660 | request.method = "GET"; |
| 9661 | request.url = GURL("http://www.example.org/"); |
| 9662 | request.load_flags = 0; |
| 9663 | |
| 9664 | TestCompletionCallback callback; |
| 9665 | |
| 9666 | scoped_ptr<HttpTransaction> trans( |
| 9667 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 9668 | |
| 9669 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 9670 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 9671 | |
| 9672 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9673 | ASSERT_TRUE(response != nullptr); |
| 9674 | ASSERT_TRUE(response->headers.get() != nullptr); |
| 9675 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9676 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9677 | EXPECT_FALSE(response->was_npn_negotiated); |
| 9678 | |
| 9679 | std::string response_data; |
| 9680 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9681 | EXPECT_EQ("hello world", response_data); |
| 9682 | |
| 9683 | alternative_service_vector = |
| 9684 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9685 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 9686 | } |
| 9687 | |
bnc | 54ec34b7 | 2015-08-26 19:34:56 | [diff] [blame] | 9688 | // Alternative Service headers must be ignored when |use_alternative_services| |
| 9689 | // is false. |
| 9690 | TEST_P(HttpNetworkTransactionTest, DoNotHonorAlternativeServiceHeader) { |
| 9691 | session_deps_.next_protos = SpdyNextProtos(); |
| 9692 | session_deps_.use_alternative_services = false; |
| 9693 | |
| 9694 | std::string alternative_service_http_header = |
| 9695 | GetAlternativeServiceHttpHeader(); |
| 9696 | |
| 9697 | MockRead data_reads[] = { |
| 9698 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9699 | MockRead(alternative_service_http_header.c_str()), |
| 9700 | MockRead("\r\n"), |
| 9701 | MockRead("hello world"), |
| 9702 | MockRead(SYNCHRONOUS, OK), |
| 9703 | }; |
| 9704 | |
| 9705 | HttpRequestInfo request; |
| 9706 | request.method = "GET"; |
| 9707 | request.url = GURL("http://www.example.org/"); |
| 9708 | request.load_flags = 0; |
| 9709 | |
| 9710 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), nullptr, 0); |
| 9711 | |
| 9712 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9713 | |
| 9714 | TestCompletionCallback callback; |
| 9715 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9716 | scoped_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
bnc | 54ec34b7 | 2015-08-26 19:34:56 | [diff] [blame] | 9717 | scoped_ptr<HttpTransaction> trans( |
| 9718 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 9719 | |
| 9720 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 9721 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9722 | |
| 9723 | HostPortPair http_host_port_pair("www.example.org", 80); |
| 9724 | HttpServerProperties& http_server_properties = |
| 9725 | *session->http_server_properties(); |
| 9726 | AlternativeServiceVector alternative_service_vector = |
| 9727 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9728 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 9729 | |
| 9730 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9731 | |
| 9732 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9733 | ASSERT_TRUE(response != nullptr); |
| 9734 | ASSERT_TRUE(response->headers.get() != nullptr); |
| 9735 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9736 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9737 | EXPECT_FALSE(response->was_npn_negotiated); |
| 9738 | |
| 9739 | std::string response_data; |
| 9740 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9741 | EXPECT_EQ("hello world", response_data); |
| 9742 | |
| 9743 | alternative_service_vector = |
| 9744 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9745 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 9746 | } |
| 9747 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9748 | TEST_P(HttpNetworkTransactionTest, HonorMultipleAlternativeServiceHeader) { |
| 9749 | session_deps_.next_protos = SpdyNextProtos(); |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9750 | session_deps_.use_alternative_services = true; |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9751 | |
| 9752 | MockRead data_reads[] = { |
| 9753 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9754 | MockRead("Alt-Svc: "), |
| 9755 | MockRead(GetAlternateProtocolFromParam()), |
bnc | 44858c8 | 2015-10-16 11:57:21 | [diff] [blame] | 9756 | MockRead("=\"www.example.com:443\";p=\"1.0\","), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9757 | MockRead("quic=\":1234\"\r\n\r\n"), |
| 9758 | MockRead("hello world"), |
| 9759 | MockRead(SYNCHRONOUS, OK), |
| 9760 | }; |
| 9761 | |
| 9762 | HttpRequestInfo request; |
| 9763 | request.method = "GET"; |
| 9764 | request.url = GURL("http://www.example.org/"); |
| 9765 | request.load_flags = 0; |
| 9766 | |
| 9767 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 9768 | |
| 9769 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9770 | |
| 9771 | TestCompletionCallback callback; |
| 9772 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9773 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9774 | scoped_ptr<HttpTransaction> trans( |
| 9775 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 9776 | |
| 9777 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 9778 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9779 | |
| 9780 | HostPortPair http_host_port_pair("www.example.org", 80); |
| 9781 | HttpServerProperties& http_server_properties = |
| 9782 | *session->http_server_properties(); |
| 9783 | AlternativeServiceVector alternative_service_vector = |
| 9784 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9785 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 9786 | |
| 9787 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9788 | |
| 9789 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9790 | ASSERT_TRUE(response != NULL); |
| 9791 | ASSERT_TRUE(response->headers.get() != NULL); |
| 9792 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9793 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9794 | EXPECT_FALSE(response->was_npn_negotiated); |
| 9795 | |
| 9796 | std::string response_data; |
| 9797 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9798 | EXPECT_EQ("hello world", response_data); |
| 9799 | |
| 9800 | alternative_service_vector = |
| 9801 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9802 | ASSERT_EQ(2u, alternative_service_vector.size()); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 9803 | EXPECT_EQ(AlternateProtocolFromNextProto(GetProtocol()), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9804 | alternative_service_vector[0].protocol); |
| 9805 | EXPECT_EQ("www.example.com", alternative_service_vector[0].host); |
| 9806 | EXPECT_EQ(443, alternative_service_vector[0].port); |
| 9807 | EXPECT_EQ(QUIC, alternative_service_vector[1].protocol); |
| 9808 | EXPECT_EQ("www.example.org", alternative_service_vector[1].host); |
| 9809 | EXPECT_EQ(1234, alternative_service_vector[1].port); |
| 9810 | } |
| 9811 | |
bnc | 54ec34b7 | 2015-08-26 19:34:56 | [diff] [blame] | 9812 | // Alternate Protocol headers must be honored even if |use_alternative_services| |
| 9813 | // is false. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9814 | TEST_P(HttpNetworkTransactionTest, HonorAlternateProtocolHeader) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 9815 | session_deps_.next_protos = SpdyNextProtos(); |
bnc | 54ec34b7 | 2015-08-26 19:34:56 | [diff] [blame] | 9816 | session_deps_.use_alternative_services = false; |
[email protected] | a2cb812 | 2010-03-10 17:22:42 | [diff] [blame] | 9817 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9818 | std::string alternate_protocol_http_header = |
| 9819 | GetAlternateProtocolHttpHeader(); |
| 9820 | |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9821 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9822 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9823 | MockRead(alternate_protocol_http_header.c_str()), |
| 9824 | MockRead("\r\n"), |
| 9825 | MockRead("hello world"), |
| 9826 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9827 | }; |
| 9828 | |
| 9829 | HttpRequestInfo request; |
| 9830 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9831 | request.url = GURL("http://www.example.org/"); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9832 | request.load_flags = 0; |
| 9833 | |
| 9834 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 9835 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9836 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9837 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9838 | TestCompletionCallback callback; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9839 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9840 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9841 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9842 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9843 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9844 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9845 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 9846 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9847 | HostPortPair http_host_port_pair("www.example.org", 80); |
[email protected] | 9801e370 | 2014-03-07 09:33:55 | [diff] [blame] | 9848 | HttpServerProperties& http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 9849 | *session->http_server_properties(); |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 9850 | AlternativeServiceVector alternative_service_vector = |
| 9851 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9852 | EXPECT_TRUE(alternative_service_vector.empty()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9853 | |
| 9854 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9855 | |
| 9856 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9857 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9858 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9859 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9860 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9861 | EXPECT_FALSE(response->was_npn_negotiated); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9862 | |
| 9863 | std::string response_data; |
| 9864 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9865 | EXPECT_EQ("hello world", response_data); |
| 9866 | |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 9867 | alternative_service_vector = |
| 9868 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9869 | ASSERT_EQ(1u, alternative_service_vector.size()); |
| 9870 | EXPECT_EQ(443, alternative_service_vector[0].port); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 9871 | EXPECT_EQ(AlternateProtocolFromNextProto(GetProtocol()), |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 9872 | alternative_service_vector[0].protocol); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9873 | } |
| 9874 | |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 9875 | TEST_P(HttpNetworkTransactionTest, EmptyAlternateProtocolHeader) { |
| 9876 | session_deps_.next_protos = SpdyNextProtos(); |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9877 | session_deps_.use_alternative_services = true; |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 9878 | |
| 9879 | MockRead data_reads[] = { |
| 9880 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9881 | MockRead("Alternate-Protocol: \r\n\r\n"), |
| 9882 | MockRead("hello world"), |
| 9883 | MockRead(SYNCHRONOUS, OK), |
| 9884 | }; |
| 9885 | |
| 9886 | HttpRequestInfo request; |
| 9887 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9888 | request.url = GURL("http://www.example.org/"); |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 9889 | request.load_flags = 0; |
| 9890 | |
| 9891 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 9892 | |
| 9893 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9894 | |
| 9895 | TestCompletionCallback callback; |
| 9896 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9897 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 9898 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9899 | HostPortPair http_host_port_pair("www.example.org", 80); |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 9900 | HttpServerProperties& http_server_properties = |
| 9901 | *session->http_server_properties(); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9902 | AlternativeService alternative_service(QUIC, "", 80); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9903 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 9904 | http_server_properties.SetAlternativeService( |
| 9905 | http_host_port_pair, alternative_service, 1.0, expiration); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9906 | |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 9907 | AlternativeServiceVector alternative_service_vector = |
| 9908 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9909 | ASSERT_EQ(1u, alternative_service_vector.size()); |
| 9910 | EXPECT_EQ(QUIC, alternative_service_vector[0].protocol); |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 9911 | |
| 9912 | scoped_ptr<HttpTransaction> trans( |
| 9913 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 9914 | |
| 9915 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 9916 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9917 | |
| 9918 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9919 | |
| 9920 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9921 | ASSERT_TRUE(response != NULL); |
| 9922 | ASSERT_TRUE(response->headers.get() != NULL); |
| 9923 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9924 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9925 | EXPECT_FALSE(response->was_npn_negotiated); |
| 9926 | |
| 9927 | std::string response_data; |
| 9928 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9929 | EXPECT_EQ("hello world", response_data); |
| 9930 | |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 9931 | alternative_service_vector = |
| 9932 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9933 | EXPECT_TRUE(alternative_service_vector.empty()); |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 9934 | } |
| 9935 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9936 | TEST_P(HttpNetworkTransactionTest, AltSvcOverwritesAlternateProtocol) { |
| 9937 | session_deps_.next_protos = SpdyNextProtos(); |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9938 | session_deps_.use_alternative_services = true; |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9939 | |
| 9940 | std::string alternative_service_http_header = |
| 9941 | GetAlternativeServiceHttpHeader(); |
| 9942 | std::string alternate_protocol_http_header = GetAlternateProtocolHttpHeader(); |
| 9943 | |
| 9944 | MockRead data_reads[] = { |
| 9945 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9946 | MockRead(alternative_service_http_header.c_str()), |
| 9947 | MockRead(alternate_protocol_http_header.c_str()), |
| 9948 | MockRead("\r\n"), |
| 9949 | MockRead("hello world"), |
| 9950 | MockRead(SYNCHRONOUS, OK), |
| 9951 | }; |
| 9952 | |
| 9953 | HttpRequestInfo request; |
| 9954 | request.method = "GET"; |
| 9955 | request.url = GURL("http://www.example.org/"); |
| 9956 | request.load_flags = 0; |
| 9957 | |
| 9958 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 9959 | |
| 9960 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9961 | |
| 9962 | TestCompletionCallback callback; |
| 9963 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9964 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9965 | scoped_ptr<HttpTransaction> trans( |
| 9966 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 9967 | |
| 9968 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 9969 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9970 | |
| 9971 | HostPortPair http_host_port_pair("www.example.org", 80); |
| 9972 | HttpServerProperties& http_server_properties = |
| 9973 | *session->http_server_properties(); |
| 9974 | AlternativeServiceVector alternative_service_vector = |
| 9975 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9976 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 9977 | |
| 9978 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9979 | |
| 9980 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9981 | ASSERT_TRUE(response != NULL); |
| 9982 | ASSERT_TRUE(response->headers.get() != NULL); |
| 9983 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9984 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9985 | EXPECT_FALSE(response->was_npn_negotiated); |
| 9986 | |
| 9987 | std::string response_data; |
| 9988 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9989 | EXPECT_EQ("hello world", response_data); |
| 9990 | |
| 9991 | alternative_service_vector = |
| 9992 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9993 | ASSERT_EQ(1u, alternative_service_vector.size()); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 9994 | EXPECT_EQ(AlternateProtocolFromNextProto(GetProtocol()), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9995 | alternative_service_vector[0].protocol); |
| 9996 | EXPECT_EQ("www.example.com", alternative_service_vector[0].host); |
| 9997 | EXPECT_EQ(443, alternative_service_vector[0].port); |
| 9998 | } |
| 9999 | |
bnc | 54ec34b7 | 2015-08-26 19:34:56 | [diff] [blame] | 10000 | // When |use_alternative_services| is false, do not observe alternative service |
| 10001 | // entries that point to a different host. |
| 10002 | TEST_P(HttpNetworkTransactionTest, DisableAlternativeServiceToDifferentHost) { |
| 10003 | session_deps_.use_alternative_services = false; |
| 10004 | |
| 10005 | HttpRequestInfo request; |
| 10006 | request.method = "GET"; |
| 10007 | request.url = GURL("http://www.example.org/"); |
| 10008 | request.load_flags = 0; |
| 10009 | |
| 10010 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 10011 | StaticSocketDataProvider first_data; |
| 10012 | first_data.set_connect_data(mock_connect); |
| 10013 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
| 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), |
| 10020 | nullptr, 0); |
| 10021 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 10022 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10023 | scoped_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
bnc | 54ec34b7 | 2015-08-26 19:34:56 | [diff] [blame] | 10024 | |
| 10025 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 10026 | session->http_server_properties(); |
| 10027 | AlternativeService alternative_service( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 10028 | AlternateProtocolFromNextProto(GetProtocol()), "different.example.org", |
| 10029 | 80); |
bnc | 54ec34b7 | 2015-08-26 19:34:56 | [diff] [blame] | 10030 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 10031 | http_server_properties->SetAlternativeService( |
| 10032 | HostPortPair::FromURL(request.url), alternative_service, 1.0, expiration); |
| 10033 | |
| 10034 | scoped_ptr<HttpTransaction> trans( |
| 10035 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 10036 | TestCompletionCallback callback; |
| 10037 | |
| 10038 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 10039 | // The connetion to origin was refused, and the alternative service should not |
| 10040 | // be used (even though mock data are there), therefore the request should |
| 10041 | // fail. |
| 10042 | EXPECT_EQ(ERR_CONNECTION_REFUSED, callback.GetResult(rv)); |
| 10043 | } |
| 10044 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10045 | TEST_P(HttpNetworkTransactionTest, IdentifyQuicBroken) { |
| 10046 | HostPortPair origin("origin.example.org", 443); |
| 10047 | HostPortPair alternative("alternative.example.org", 443); |
| 10048 | std::string origin_url = "https://origin.example.org:443"; |
| 10049 | std::string alternative_url = "https://alternative.example.org:443"; |
| 10050 | |
| 10051 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 10052 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 10053 | ssl.SetNextProto(kProtoHTTP11); |
| 10054 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10055 | |
| 10056 | // HTTP/1.1 data for request. |
| 10057 | MockWrite http_writes[] = { |
| 10058 | MockWrite("GET / HTTP/1.1\r\n" |
| 10059 | "Host: alternative.example.org\r\n" |
| 10060 | "Connection: keep-alive\r\n\r\n"), |
| 10061 | }; |
| 10062 | |
| 10063 | MockRead http_reads[] = { |
| 10064 | MockRead("HTTP/1.1 200 OK\r\n" |
| 10065 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 10066 | "Content-Length: 40\r\n\r\n" |
| 10067 | "first HTTP/1.1 response from alternative"), |
| 10068 | }; |
| 10069 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 10070 | http_writes, arraysize(http_writes)); |
| 10071 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 10072 | |
| 10073 | StaticSocketDataProvider data_refused; |
| 10074 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 10075 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 10076 | |
| 10077 | // Set up a QUIC alternative service for origin. |
| 10078 | session_deps_.use_alternative_services = true; |
| 10079 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 10080 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 10081 | session->http_server_properties(); |
| 10082 | AlternativeService alternative_service(QUIC, alternative); |
| 10083 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 10084 | http_server_properties->SetAlternativeService(origin, alternative_service, |
| 10085 | 1.0, expiration); |
| 10086 | // Mark the QUIC alternative service as broken. |
| 10087 | http_server_properties->MarkAlternativeServiceBroken(alternative_service); |
| 10088 | |
| 10089 | scoped_ptr<HttpTransaction> trans( |
| 10090 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 10091 | HttpRequestInfo request; |
| 10092 | request.method = "GET"; |
| 10093 | request.url = GURL(origin_url); |
| 10094 | request.load_flags = 0; |
| 10095 | TestCompletionCallback callback; |
| 10096 | NetErrorDetails details; |
| 10097 | EXPECT_FALSE(details.quic_broken); |
| 10098 | |
| 10099 | trans->Start(&request, callback.callback(), BoundNetLog()); |
| 10100 | trans->PopulateNetErrorDetails(&details); |
| 10101 | EXPECT_TRUE(details.quic_broken); |
| 10102 | } |
| 10103 | |
| 10104 | TEST_P(HttpNetworkTransactionTest, IdentifyQuicNotBroken) { |
| 10105 | HostPortPair origin("origin.example.org", 443); |
| 10106 | HostPortPair alternative1("alternative1.example.org", 443); |
| 10107 | HostPortPair alternative2("alternative2.example.org", 443); |
| 10108 | std::string origin_url = "https://origin.example.org:443"; |
| 10109 | std::string alternative_url1 = "https://alternative1.example.org:443"; |
| 10110 | std::string alternative_url2 = "https://alternative2.example.org:443"; |
| 10111 | |
| 10112 | // Negotiate HTTP/1.1 with alternative1.example.org. |
| 10113 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 10114 | ssl.SetNextProto(kProtoHTTP11); |
| 10115 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10116 | |
| 10117 | // HTTP/1.1 data for request. |
| 10118 | MockWrite http_writes[] = { |
| 10119 | MockWrite("GET / HTTP/1.1\r\n" |
| 10120 | "Host: alternative1.example.org\r\n" |
| 10121 | "Connection: keep-alive\r\n\r\n"), |
| 10122 | }; |
| 10123 | |
| 10124 | MockRead http_reads[] = { |
| 10125 | MockRead("HTTP/1.1 200 OK\r\n" |
| 10126 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 10127 | "Content-Length: 40\r\n\r\n" |
| 10128 | "first HTTP/1.1 response from alternative1"), |
| 10129 | }; |
| 10130 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 10131 | http_writes, arraysize(http_writes)); |
| 10132 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 10133 | |
| 10134 | StaticSocketDataProvider data_refused; |
| 10135 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 10136 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 10137 | |
| 10138 | session_deps_.use_alternative_services = true; |
| 10139 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 10140 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 10141 | session->http_server_properties(); |
| 10142 | |
| 10143 | // Set up two QUIC alternative services for origin. |
| 10144 | AlternativeServiceInfoVector alternative_service_info_vector; |
| 10145 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 10146 | |
| 10147 | AlternativeService alternative_service1(QUIC, alternative1); |
| 10148 | AlternativeServiceInfo alternative_service_info1(alternative_service1, 1.0, |
| 10149 | expiration); |
| 10150 | alternative_service_info_vector.push_back(alternative_service_info1); |
| 10151 | AlternativeService alternative_service2(QUIC, alternative2); |
| 10152 | AlternativeServiceInfo alternative_service_info2(alternative_service2, 1.0, |
| 10153 | expiration); |
| 10154 | alternative_service_info_vector.push_back(alternative_service_info2); |
| 10155 | |
| 10156 | http_server_properties->SetAlternativeServices( |
| 10157 | origin, alternative_service_info_vector); |
| 10158 | |
| 10159 | // Mark one of the QUIC alternative service as broken. |
| 10160 | http_server_properties->MarkAlternativeServiceBroken(alternative_service1); |
| 10161 | |
| 10162 | const AlternativeServiceVector alternative_service_vector = |
| 10163 | http_server_properties->GetAlternativeServices(origin); |
| 10164 | |
| 10165 | scoped_ptr<HttpTransaction> trans( |
| 10166 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 10167 | HttpRequestInfo request; |
| 10168 | request.method = "GET"; |
| 10169 | request.url = GURL(origin_url); |
| 10170 | request.load_flags = 0; |
| 10171 | TestCompletionCallback callback; |
| 10172 | NetErrorDetails details; |
| 10173 | EXPECT_FALSE(details.quic_broken); |
| 10174 | |
| 10175 | trans->Start(&request, callback.callback(), BoundNetLog()); |
| 10176 | trans->PopulateNetErrorDetails(&details); |
| 10177 | EXPECT_FALSE(details.quic_broken); |
| 10178 | } |
| 10179 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10180 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 10181 | MarkBrokenAlternateProtocolAndFallback) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10182 | session_deps_.use_alternative_services = true; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10183 | |
| 10184 | HttpRequestInfo request; |
| 10185 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10186 | request.url = GURL("http://www.example.org/"); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10187 | request.load_flags = 0; |
| 10188 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10189 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10190 | StaticSocketDataProvider first_data; |
| 10191 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10192 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10193 | |
| 10194 | MockRead data_reads[] = { |
| 10195 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10196 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10197 | MockRead(ASYNC, OK), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10198 | }; |
| 10199 | StaticSocketDataProvider second_data( |
| 10200 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10201 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10202 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10203 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10204 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 10205 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10206 | session->http_server_properties(); |
bnc | 8445b300 | 2015-03-13 01:57:09 | [diff] [blame] | 10207 | const HostPortPair host_port_pair = HostPortPair::FromURL(request.url); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10208 | // Port must be < 1024, or the header will be ignored (since initial port was |
| 10209 | // port 80 (another restricted port). |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 10210 | const AlternativeService alternative_service( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 10211 | AlternateProtocolFromNextProto(GetProtocol()), "www.example.org", |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 10212 | 666); // Port is ignored by MockConnect anyway. |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10213 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 10214 | http_server_properties->SetAlternativeService( |
| 10215 | host_port_pair, alternative_service, 1.0, expiration); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10216 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10217 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10218 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10219 | TestCompletionCallback callback; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10220 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10221 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10222 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10223 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 10224 | |
| 10225 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10226 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10227 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10228 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10229 | |
| 10230 | std::string response_data; |
| 10231 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10232 | EXPECT_EQ("hello world", response_data); |
| 10233 | |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 10234 | const AlternativeServiceVector alternative_service_vector = |
| 10235 | http_server_properties->GetAlternativeServices(host_port_pair); |
| 10236 | ASSERT_EQ(1u, alternative_service_vector.size()); |
| 10237 | EXPECT_EQ(alternative_service, alternative_service_vector[0]); |
| 10238 | EXPECT_TRUE(http_server_properties->IsAlternativeServiceBroken( |
| 10239 | alternative_service_vector[0])); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10240 | } |
| 10241 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10242 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10243 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 10244 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 10245 | // cases. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10246 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 10247 | AlternateProtocolPortRestrictedBlocked) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10248 | session_deps_.use_alternative_services = true; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10249 | |
| 10250 | HttpRequestInfo restricted_port_request; |
| 10251 | restricted_port_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10252 | restricted_port_request.url = GURL("http://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10253 | restricted_port_request.load_flags = 0; |
| 10254 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10255 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10256 | StaticSocketDataProvider first_data; |
| 10257 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10258 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10259 | |
| 10260 | MockRead data_reads[] = { |
| 10261 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10262 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10263 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10264 | }; |
| 10265 | StaticSocketDataProvider second_data( |
| 10266 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10267 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10268 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10269 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10270 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 10271 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10272 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10273 | const int kUnrestrictedAlternatePort = 1024; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10274 | AlternativeService alternative_service( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 10275 | AlternateProtocolFromNextProto(GetProtocol()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10276 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10277 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10278 | http_server_properties->SetAlternativeService( |
| 10279 | HostPortPair::FromURL(restricted_port_request.url), alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10280 | 1.0, expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10281 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10282 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10283 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10284 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10285 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10286 | int rv = trans->Start( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10287 | &restricted_port_request, |
| 10288 | callback.callback(), BoundNetLog()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10289 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10290 | // Invalid change to unrestricted port should fail. |
| 10291 | EXPECT_EQ(ERR_CONNECTION_REFUSED, callback.WaitForResult()); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10292 | } |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10293 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10294 | // Ensure that we are allowed to redirect traffic via an alternate protocol to |
| 10295 | // an unrestricted (port >= 1024) when the original traffic was on a restricted |
| 10296 | // port (port < 1024) if we set |enable_user_alternate_protocol_ports|. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10297 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10298 | AlternateProtocolPortRestrictedPermitted) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10299 | session_deps_.use_alternative_services = true; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10300 | session_deps_.enable_user_alternate_protocol_ports = true; |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10301 | |
| 10302 | HttpRequestInfo restricted_port_request; |
| 10303 | restricted_port_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10304 | restricted_port_request.url = GURL("http://www.example.org:1023/"); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10305 | restricted_port_request.load_flags = 0; |
| 10306 | |
| 10307 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 10308 | StaticSocketDataProvider first_data; |
| 10309 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10310 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10311 | |
| 10312 | MockRead data_reads[] = { |
| 10313 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10314 | MockRead("hello world"), |
| 10315 | MockRead(ASYNC, OK), |
| 10316 | }; |
| 10317 | StaticSocketDataProvider second_data( |
| 10318 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10319 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10320 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10321 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10322 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 10323 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10324 | session->http_server_properties(); |
| 10325 | const int kUnrestrictedAlternatePort = 1024; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10326 | AlternativeService alternative_service( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 10327 | AlternateProtocolFromNextProto(GetProtocol()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10328 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10329 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10330 | http_server_properties->SetAlternativeService( |
| 10331 | HostPortPair::FromURL(restricted_port_request.url), alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10332 | 1.0, expiration); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10333 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10334 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10335 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10336 | TestCompletionCallback callback; |
| 10337 | |
| 10338 | EXPECT_EQ(ERR_IO_PENDING, trans->Start( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10339 | &restricted_port_request, |
| 10340 | callback.callback(), BoundNetLog())); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10341 | // Change to unrestricted port should succeed. |
| 10342 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10343 | } |
| 10344 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10345 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10346 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 10347 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 10348 | // cases. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10349 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 10350 | AlternateProtocolPortRestrictedAllowed) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10351 | session_deps_.use_alternative_services = true; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10352 | |
| 10353 | HttpRequestInfo restricted_port_request; |
| 10354 | restricted_port_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10355 | restricted_port_request.url = GURL("http://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10356 | restricted_port_request.load_flags = 0; |
| 10357 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10358 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10359 | StaticSocketDataProvider first_data; |
| 10360 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10361 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10362 | |
| 10363 | MockRead data_reads[] = { |
| 10364 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10365 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10366 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10367 | }; |
| 10368 | StaticSocketDataProvider second_data( |
| 10369 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10370 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10371 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10372 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10373 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 10374 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10375 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10376 | const int kRestrictedAlternatePort = 80; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10377 | AlternativeService alternative_service( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 10378 | AlternateProtocolFromNextProto(GetProtocol()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10379 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10380 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10381 | http_server_properties->SetAlternativeService( |
| 10382 | HostPortPair::FromURL(restricted_port_request.url), alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10383 | 1.0, expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10384 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10385 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10386 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10387 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10388 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10389 | int rv = trans->Start( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10390 | &restricted_port_request, |
| 10391 | callback.callback(), BoundNetLog()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10392 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10393 | // Valid change to restricted port should pass. |
| 10394 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10395 | } |
| 10396 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10397 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10398 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 10399 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 10400 | // cases. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10401 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 10402 | AlternateProtocolPortUnrestrictedAllowed1) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10403 | session_deps_.use_alternative_services = true; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10404 | |
| 10405 | HttpRequestInfo unrestricted_port_request; |
| 10406 | unrestricted_port_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10407 | unrestricted_port_request.url = GURL("http://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10408 | unrestricted_port_request.load_flags = 0; |
| 10409 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10410 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10411 | StaticSocketDataProvider first_data; |
| 10412 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10413 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10414 | |
| 10415 | MockRead data_reads[] = { |
| 10416 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10417 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10418 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10419 | }; |
| 10420 | StaticSocketDataProvider second_data( |
| 10421 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10422 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10423 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10424 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10425 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 10426 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10427 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10428 | const int kRestrictedAlternatePort = 80; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10429 | AlternativeService alternative_service( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 10430 | AlternateProtocolFromNextProto(GetProtocol()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10431 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10432 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10433 | http_server_properties->SetAlternativeService( |
| 10434 | HostPortPair::FromURL(unrestricted_port_request.url), alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10435 | 1.0, expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10436 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10437 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10438 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10439 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10440 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10441 | int rv = trans->Start( |
| 10442 | &unrestricted_port_request, callback.callback(), BoundNetLog()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10443 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10444 | // Valid change to restricted port should pass. |
| 10445 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10446 | } |
| 10447 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10448 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10449 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 10450 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 10451 | // cases. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10452 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 10453 | AlternateProtocolPortUnrestrictedAllowed2) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10454 | session_deps_.use_alternative_services = true; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10455 | |
| 10456 | HttpRequestInfo unrestricted_port_request; |
| 10457 | unrestricted_port_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10458 | unrestricted_port_request.url = GURL("http://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10459 | unrestricted_port_request.load_flags = 0; |
| 10460 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10461 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 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] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10465 | |
| 10466 | MockRead data_reads[] = { |
| 10467 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10468 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10469 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 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); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10474 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10475 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10476 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 10477 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10478 | session->http_server_properties(); |
bnc | 0bbb0262 | 2015-07-23 10:06:22 | [diff] [blame] | 10479 | const int kUnrestrictedAlternatePort = 1025; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10480 | AlternativeService alternative_service( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 10481 | AlternateProtocolFromNextProto(GetProtocol()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10482 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10483 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10484 | http_server_properties->SetAlternativeService( |
| 10485 | HostPortPair::FromURL(unrestricted_port_request.url), alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10486 | 1.0, expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10487 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10488 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10489 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10490 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10491 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10492 | int rv = trans->Start( |
| 10493 | &unrestricted_port_request, callback.callback(), BoundNetLog()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10494 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10495 | // Valid change to an unrestricted port should pass. |
| 10496 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10497 | } |
| 10498 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10499 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10500 | // to an unsafe port, and that we resume the second HttpStreamFactoryImpl::Job |
| 10501 | // once the alternate protocol request fails. |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 10502 | TEST_P(HttpNetworkTransactionTest, AlternateProtocolUnsafeBlocked) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10503 | session_deps_.use_alternative_services = true; |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10504 | |
| 10505 | HttpRequestInfo request; |
| 10506 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10507 | request.url = GURL("http://www.example.org/"); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10508 | request.load_flags = 0; |
| 10509 | |
| 10510 | // The alternate protocol request will error out before we attempt to connect, |
| 10511 | // so only the standard HTTP request will try to connect. |
| 10512 | MockRead data_reads[] = { |
| 10513 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10514 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10515 | MockRead(ASYNC, OK), |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10516 | }; |
| 10517 | StaticSocketDataProvider data( |
| 10518 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10519 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10520 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10521 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10522 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 10523 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10524 | session->http_server_properties(); |
| 10525 | const int kUnsafePort = 7; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10526 | AlternativeService alternative_service( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 10527 | AlternateProtocolFromNextProto(GetProtocol()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10528 | kUnsafePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10529 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10530 | http_server_properties->SetAlternativeService( |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10531 | HostPortPair::FromURL(request.url), alternative_service, 1.0, expiration); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10532 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10533 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10534 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10535 | TestCompletionCallback callback; |
| 10536 | |
| 10537 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 10538 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10539 | // The HTTP request should succeed. |
| 10540 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 10541 | |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10542 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10543 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10544 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10545 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10546 | |
| 10547 | std::string response_data; |
| 10548 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10549 | EXPECT_EQ("hello world", response_data); |
| 10550 | } |
| 10551 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10552 | TEST_P(HttpNetworkTransactionTest, UseAlternateProtocolForNpnSpdy) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10553 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 10554 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10555 | |
| 10556 | HttpRequestInfo request; |
| 10557 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10558 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10559 | request.load_flags = 0; |
| 10560 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 10561 | std::string alternate_protocol_http_header = |
| 10562 | GetAlternateProtocolHttpHeader(); |
| 10563 | |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10564 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10565 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10566 | MockRead(alternate_protocol_http_header.c_str()), |
| 10567 | MockRead("\r\n"), |
| 10568 | MockRead("hello world"), |
| 10569 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 10570 | MockRead(ASYNC, OK)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10571 | |
| 10572 | StaticSocketDataProvider first_transaction( |
| 10573 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10574 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10575 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10576 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 10577 | ssl.SetNextProto(GetProtocol()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10578 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 10579 | ASSERT_TRUE(ssl.cert.get()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10580 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10581 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 10582 | scoped_ptr<SpdyFrame> req( |
| 10583 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10584 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10585 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10586 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 10587 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10588 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10589 | CreateMockRead(*resp, 1), CreateMockRead(*data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10590 | }; |
| 10591 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10592 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 10593 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10594 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10595 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10596 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10597 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 10598 | NULL, 0, NULL, 0); |
| 10599 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 10600 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10601 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10602 | &hanging_non_alternate_protocol_socket); |
| 10603 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10604 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10605 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10606 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10607 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10608 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10609 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10610 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10611 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10612 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 10613 | |
| 10614 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10615 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10616 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10617 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10618 | |
| 10619 | std::string response_data; |
| 10620 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10621 | EXPECT_EQ("hello world", response_data); |
| 10622 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10623 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10624 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10625 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10626 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10627 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 10628 | |
| 10629 | response = trans->GetResponseInfo(); |
| 10630 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10631 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 10632 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10633 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 10634 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10635 | |
| 10636 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10637 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10638 | } |
| 10639 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10640 | TEST_P(HttpNetworkTransactionTest, AlternateProtocolWithSpdyLateBinding) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10641 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 10642 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10643 | |
| 10644 | HttpRequestInfo request; |
| 10645 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10646 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10647 | request.load_flags = 0; |
| 10648 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 10649 | std::string alternate_protocol_http_header = |
| 10650 | GetAlternateProtocolHttpHeader(); |
| 10651 | |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10652 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10653 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10654 | MockRead(alternate_protocol_http_header.c_str()), |
| 10655 | MockRead("\r\n"), |
| 10656 | MockRead("hello world"), |
| 10657 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 10658 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10659 | }; |
| 10660 | |
| 10661 | StaticSocketDataProvider first_transaction( |
| 10662 | data_reads, arraysize(data_reads), NULL, 0); |
| 10663 | // Socket 1 is the HTTP transaction with the Alternate-Protocol header. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10664 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10665 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10666 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 10667 | StaticSocketDataProvider hanging_socket1(NULL, 0, NULL, 0); |
| 10668 | hanging_socket1.set_connect_data(never_finishing_connect); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10669 | // Socket 2 and 3 are the hanging Alternate-Protocol and |
| 10670 | // non-Alternate-Protocol jobs from the 2nd transaction. |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 10671 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket1); |
| 10672 | |
| 10673 | StaticSocketDataProvider hanging_socket2(NULL, 0, NULL, 0); |
| 10674 | hanging_socket2.set_connect_data(never_finishing_connect); |
| 10675 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket2); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10676 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10677 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 10678 | ssl.SetNextProto(GetProtocol()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10679 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 10680 | ASSERT_TRUE(ssl.cert.get()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10681 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10682 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 10683 | scoped_ptr<SpdyFrame> req1( |
| 10684 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 10685 | scoped_ptr<SpdyFrame> req2( |
| 10686 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, LOWEST, true)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10687 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10688 | CreateMockWrite(*req1, 0), CreateMockWrite(*req2, 1), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10689 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10690 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 10691 | scoped_ptr<SpdyFrame> data1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 10692 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 10693 | scoped_ptr<SpdyFrame> data2(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10694 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10695 | CreateMockRead(*resp1, 2), |
| 10696 | CreateMockRead(*data1, 3), |
| 10697 | CreateMockRead(*resp2, 4), |
| 10698 | CreateMockRead(*data2, 5), |
| 10699 | MockRead(ASYNC, 0, 6), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10700 | }; |
| 10701 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10702 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 10703 | arraysize(spdy_writes)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10704 | // Socket 4 is the successful Alternate-Protocol for transaction 3. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10705 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10706 | |
| 10707 | // Socket 5 is the unsuccessful non-Alternate-Protocol for transaction 3. |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 10708 | StaticSocketDataProvider hanging_socket3(NULL, 0, NULL, 0); |
| 10709 | hanging_socket3.set_connect_data(never_finishing_connect); |
| 10710 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket3); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10711 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10712 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10713 | TestCompletionCallback callback1; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10714 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10715 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10716 | int rv = trans1.Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10717 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10718 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 10719 | |
| 10720 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 10721 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10722 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10723 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10724 | |
| 10725 | std::string response_data; |
| 10726 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); |
| 10727 | EXPECT_EQ("hello world", response_data); |
| 10728 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10729 | TestCompletionCallback callback2; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10730 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10731 | rv = trans2.Start(&request, callback2.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10732 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10733 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10734 | TestCompletionCallback callback3; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10735 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10736 | rv = trans3.Start(&request, callback3.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10737 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10738 | |
| 10739 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 10740 | EXPECT_EQ(OK, callback3.WaitForResult()); |
| 10741 | |
| 10742 | response = trans2.GetResponseInfo(); |
| 10743 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10744 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 10745 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10746 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 10747 | EXPECT_TRUE(response->was_npn_negotiated); |
| 10748 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 10749 | EXPECT_EQ("hello!", response_data); |
| 10750 | |
| 10751 | response = trans3.GetResponseInfo(); |
| 10752 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10753 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 10754 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10755 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 10756 | EXPECT_TRUE(response->was_npn_negotiated); |
| 10757 | ASSERT_EQ(OK, ReadTransaction(&trans3, &response_data)); |
| 10758 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10759 | } |
| 10760 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10761 | TEST_P(HttpNetworkTransactionTest, StallAlternateProtocolForNpnSpdy) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10762 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 10763 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10764 | |
| 10765 | HttpRequestInfo request; |
| 10766 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10767 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10768 | request.load_flags = 0; |
| 10769 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 10770 | std::string alternate_protocol_http_header = |
| 10771 | GetAlternateProtocolHttpHeader(); |
| 10772 | |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10773 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10774 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10775 | MockRead(alternate_protocol_http_header.c_str()), |
| 10776 | MockRead("\r\n"), |
| 10777 | MockRead("hello world"), |
| 10778 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 10779 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10780 | }; |
| 10781 | |
| 10782 | StaticSocketDataProvider first_transaction( |
| 10783 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10784 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10785 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10786 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 10787 | ssl.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10788 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10789 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10790 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10791 | StaticSocketDataProvider hanging_alternate_protocol_socket( |
| 10792 | NULL, 0, NULL, 0); |
| 10793 | hanging_alternate_protocol_socket.set_connect_data( |
| 10794 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10795 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10796 | &hanging_alternate_protocol_socket); |
| 10797 | |
| 10798 | // 2nd request is just a copy of the first one, over HTTP again. |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 10799 | StaticSocketDataProvider second_transaction(data_reads, arraysize(data_reads), |
| 10800 | NULL, 0); |
| 10801 | session_deps_.socket_factory->AddSocketDataProvider(&second_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10802 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10803 | TestCompletionCallback callback; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10804 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10805 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10806 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10807 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10808 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10809 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10810 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10811 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 10812 | |
| 10813 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10814 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10815 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10816 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10817 | |
| 10818 | std::string response_data; |
| 10819 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10820 | EXPECT_EQ("hello world", response_data); |
| 10821 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10822 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10823 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10824 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10825 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10826 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 10827 | |
| 10828 | response = trans->GetResponseInfo(); |
| 10829 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10830 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10831 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10832 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 10833 | EXPECT_FALSE(response->was_npn_negotiated); |
| 10834 | |
| 10835 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10836 | EXPECT_EQ("hello world", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10837 | } |
| 10838 | |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10839 | class CapturingProxyResolver : public ProxyResolver { |
| 10840 | public: |
sammc | e90c921 | 2015-05-27 23:43:35 | [diff] [blame] | 10841 | CapturingProxyResolver() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 10842 | ~CapturingProxyResolver() override {} |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10843 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 10844 | int GetProxyForURL(const GURL& url, |
| 10845 | ProxyInfo* results, |
| 10846 | const CompletionCallback& callback, |
| 10847 | RequestHandle* request, |
| 10848 | const BoundNetLog& net_log) override { |
[email protected] | fae7669f | 2010-08-02 21:49:40 | [diff] [blame] | 10849 | ProxyServer proxy_server(ProxyServer::SCHEME_HTTP, |
| 10850 | HostPortPair("myproxy", 80)); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 10851 | results->UseProxyServer(proxy_server); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10852 | resolved_.push_back(url); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 10853 | return OK; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10854 | } |
| 10855 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 10856 | void CancelRequest(RequestHandle request) override { NOTREACHED(); } |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10857 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 10858 | LoadState GetLoadState(RequestHandle request) const override { |
[email protected] | f2c971f | 2011-11-08 00:33:17 | [diff] [blame] | 10859 | NOTREACHED(); |
| 10860 | return LOAD_STATE_IDLE; |
| 10861 | } |
| 10862 | |
[email protected] | 2447640 | 2010-07-20 20:55:17 | [diff] [blame] | 10863 | const std::vector<GURL>& resolved() const { return resolved_; } |
| 10864 | |
| 10865 | private: |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10866 | std::vector<GURL> resolved_; |
| 10867 | |
| 10868 | DISALLOW_COPY_AND_ASSIGN(CapturingProxyResolver); |
| 10869 | }; |
| 10870 | |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 10871 | class CapturingProxyResolverFactory : public ProxyResolverFactory { |
| 10872 | public: |
| 10873 | explicit CapturingProxyResolverFactory(CapturingProxyResolver* resolver) |
| 10874 | : ProxyResolverFactory(false), resolver_(resolver) {} |
| 10875 | |
| 10876 | int CreateProxyResolver( |
| 10877 | const scoped_refptr<ProxyResolverScriptData>& pac_script, |
| 10878 | scoped_ptr<ProxyResolver>* resolver, |
| 10879 | const net::CompletionCallback& callback, |
| 10880 | scoped_ptr<Request>* request) override { |
| 10881 | resolver->reset(new ForwardingProxyResolver(resolver_)); |
| 10882 | return OK; |
| 10883 | } |
| 10884 | |
| 10885 | private: |
| 10886 | ProxyResolver* resolver_; |
| 10887 | }; |
| 10888 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10889 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 10890 | UseAlternateProtocolForTunneledNpnSpdy) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10891 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 10892 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10893 | |
| 10894 | ProxyConfig proxy_config; |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 10895 | proxy_config.set_auto_detect(true); |
| 10896 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 10897 | |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 10898 | CapturingProxyResolver capturing_proxy_resolver; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10899 | session_deps_.proxy_service.reset(new ProxyService( |
csharrison | b7e3a08 | 2015-09-22 19:13:04 | [diff] [blame] | 10900 | make_scoped_ptr(new ProxyConfigServiceFixed(proxy_config)), |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 10901 | make_scoped_ptr( |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 10902 | new CapturingProxyResolverFactory(&capturing_proxy_resolver)), |
[email protected] | 66761b95 | 2010-06-25 21:30:38 | [diff] [blame] | 10903 | NULL)); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10904 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10905 | session_deps_.net_log = &net_log; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10906 | |
| 10907 | HttpRequestInfo request; |
| 10908 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10909 | request.url = GURL("http://www.example.org/"); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10910 | request.load_flags = 0; |
| 10911 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 10912 | std::string alternate_protocol_http_header = |
| 10913 | GetAlternateProtocolHttpHeader(); |
| 10914 | |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10915 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10916 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10917 | MockRead(alternate_protocol_http_header.c_str()), |
| 10918 | MockRead("\r\n"), |
| 10919 | MockRead("hello world"), |
| 10920 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 10921 | MockRead(ASYNC, OK), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10922 | }; |
| 10923 | |
| 10924 | StaticSocketDataProvider first_transaction( |
| 10925 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10926 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10927 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10928 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 10929 | ssl.SetNextProto(GetProtocol()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10930 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 10931 | ASSERT_TRUE(ssl.cert.get()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10932 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10933 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 10934 | scoped_ptr<SpdyFrame> req( |
| 10935 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10936 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10937 | MockWrite(ASYNC, 0, |
| 10938 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 10939 | "Host: www.example.org:443\r\n" |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10940 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 10941 | CreateMockWrite(*req, 2), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10942 | }; |
| 10943 | |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 10944 | const char kCONNECTResponse[] = "HTTP/1.1 200 Connected\r\n\r\n"; |
| 10945 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10946 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 10947 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10948 | MockRead spdy_reads[] = { |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 10949 | MockRead(ASYNC, 1, kCONNECTResponse), CreateMockRead(*resp.get(), 3), |
| 10950 | CreateMockRead(*data.get(), 4), MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10951 | }; |
| 10952 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10953 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 10954 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10955 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10956 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10957 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10958 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 10959 | NULL, 0, NULL, 0); |
| 10960 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 10961 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10962 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10963 | &hanging_non_alternate_protocol_socket); |
| 10964 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10965 | TestCompletionCallback callback; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10966 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10967 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10968 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10969 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10970 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10971 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10972 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10973 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 10974 | |
| 10975 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10976 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10977 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10978 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10979 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 10980 | EXPECT_FALSE(response->was_npn_negotiated); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10981 | |
| 10982 | std::string response_data; |
| 10983 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10984 | EXPECT_EQ("hello world", response_data); |
| 10985 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10986 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10987 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10988 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10989 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10990 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 10991 | |
| 10992 | response = trans->GetResponseInfo(); |
| 10993 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10994 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 10995 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10996 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 10997 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10998 | |
| 10999 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 11000 | EXPECT_EQ("hello!", response_data); |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 11001 | ASSERT_EQ(3u, capturing_proxy_resolver.resolved().size()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11002 | EXPECT_EQ("http://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 11003 | capturing_proxy_resolver.resolved()[0].spec()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11004 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 11005 | capturing_proxy_resolver.resolved()[1].spec()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11006 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11007 | LoadTimingInfo load_timing_info; |
| 11008 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 11009 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 11010 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11011 | } |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11012 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11013 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11014 | UseAlternateProtocolForNpnSpdyWithExistingSpdySession) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11015 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 11016 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11017 | |
| 11018 | HttpRequestInfo request; |
| 11019 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11020 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11021 | request.load_flags = 0; |
| 11022 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 11023 | std::string alternate_protocol_http_header = |
| 11024 | GetAlternateProtocolHttpHeader(); |
| 11025 | |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11026 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11027 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 11028 | MockRead(alternate_protocol_http_header.c_str()), |
| 11029 | MockRead("\r\n"), |
| 11030 | MockRead("hello world"), |
| 11031 | MockRead(ASYNC, OK), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11032 | }; |
| 11033 | |
| 11034 | StaticSocketDataProvider first_transaction( |
| 11035 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11036 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11037 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11038 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 11039 | ssl.SetNextProto(GetProtocol()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11040 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 11041 | ASSERT_TRUE(ssl.cert.get()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11042 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11043 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11044 | scoped_ptr<SpdyFrame> req( |
| 11045 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11046 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11047 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11048 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11049 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11050 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11051 | CreateMockRead(*resp, 1), CreateMockRead(*data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11052 | }; |
| 11053 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11054 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 11055 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11056 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11057 | |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 11058 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11059 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11060 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11061 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11062 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11063 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11064 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11065 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11066 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11067 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11068 | |
| 11069 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 11070 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11071 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11072 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11073 | |
| 11074 | std::string response_data; |
| 11075 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 11076 | EXPECT_EQ("hello world", response_data); |
| 11077 | |
| 11078 | // Set up an initial SpdySession in the pool to reuse. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11079 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 11080 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 11081 | PRIVACY_MODE_DISABLED); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 11082 | base::WeakPtr<SpdySession> spdy_session = |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11083 | CreateSecureSpdySession(session.get(), key, BoundNetLog()); |
[email protected] | 02b0c34 | 2010-09-25 21:09:38 | [diff] [blame] | 11084 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11085 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11086 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11087 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11088 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11089 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11090 | |
| 11091 | response = trans->GetResponseInfo(); |
| 11092 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11093 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 11094 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11095 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 11096 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11097 | |
| 11098 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 11099 | EXPECT_EQ("hello!", response_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11100 | } |
| 11101 | |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11102 | // GenerateAuthToken is a mighty big test. |
| 11103 | // It tests all permutation of GenerateAuthToken behavior: |
| 11104 | // - Synchronous and Asynchronous completion. |
| 11105 | // - OK or error on completion. |
| 11106 | // - Direct connection, non-authenticating proxy, and authenticating proxy. |
| 11107 | // - HTTP or HTTPS backend (to include proxy tunneling). |
| 11108 | // - Non-authenticating and authenticating backend. |
| 11109 | // |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 11110 | // In all, there are 44 reasonable permuations (for example, if there are |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11111 | // problems generating an auth token for an authenticating proxy, we don't |
| 11112 | // need to test all permutations of the backend server). |
| 11113 | // |
| 11114 | // The test proceeds by going over each of the configuration cases, and |
| 11115 | // potentially running up to three rounds in each of the tests. The TestConfig |
| 11116 | // specifies both the configuration for the test as well as the expectations |
| 11117 | // for the results. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11118 | TEST_P(HttpNetworkTransactionTest, GenerateAuthToken) { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11119 | static const char kServer[] = "http://www.example.com"; |
| 11120 | static const char kSecureServer[] = "https://www.example.com"; |
| 11121 | static const char kProxy[] = "myproxy:70"; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11122 | const int kAuthErr = ERR_INVALID_AUTH_CREDENTIALS; |
| 11123 | |
| 11124 | enum AuthTiming { |
| 11125 | AUTH_NONE, |
| 11126 | AUTH_SYNC, |
| 11127 | AUTH_ASYNC, |
| 11128 | }; |
| 11129 | |
| 11130 | const MockWrite kGet( |
| 11131 | "GET / HTTP/1.1\r\n" |
| 11132 | "Host: www.example.com\r\n" |
| 11133 | "Connection: keep-alive\r\n\r\n"); |
| 11134 | const MockWrite kGetProxy( |
| 11135 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 11136 | "Host: www.example.com\r\n" |
| 11137 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 11138 | const MockWrite kGetAuth( |
| 11139 | "GET / HTTP/1.1\r\n" |
| 11140 | "Host: www.example.com\r\n" |
| 11141 | "Connection: keep-alive\r\n" |
| 11142 | "Authorization: auth_token\r\n\r\n"); |
| 11143 | const MockWrite kGetProxyAuth( |
| 11144 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 11145 | "Host: www.example.com\r\n" |
| 11146 | "Proxy-Connection: keep-alive\r\n" |
| 11147 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 11148 | const MockWrite kGetAuthThroughProxy( |
| 11149 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 11150 | "Host: www.example.com\r\n" |
| 11151 | "Proxy-Connection: keep-alive\r\n" |
| 11152 | "Authorization: auth_token\r\n\r\n"); |
| 11153 | const MockWrite kGetAuthWithProxyAuth( |
| 11154 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 11155 | "Host: www.example.com\r\n" |
| 11156 | "Proxy-Connection: keep-alive\r\n" |
| 11157 | "Proxy-Authorization: auth_token\r\n" |
| 11158 | "Authorization: auth_token\r\n\r\n"); |
| 11159 | const MockWrite kConnect( |
| 11160 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 11161 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11162 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 11163 | const MockWrite kConnectProxyAuth( |
| 11164 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 11165 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11166 | "Proxy-Connection: keep-alive\r\n" |
| 11167 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 11168 | |
| 11169 | const MockRead kSuccess( |
| 11170 | "HTTP/1.1 200 OK\r\n" |
| 11171 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11172 | "Content-Length: 3\r\n\r\n" |
| 11173 | "Yes"); |
| 11174 | const MockRead kFailure( |
| 11175 | "Should not be called."); |
| 11176 | const MockRead kServerChallenge( |
| 11177 | "HTTP/1.1 401 Unauthorized\r\n" |
| 11178 | "WWW-Authenticate: Mock realm=server\r\n" |
| 11179 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11180 | "Content-Length: 14\r\n\r\n" |
| 11181 | "Unauthorized\r\n"); |
| 11182 | const MockRead kProxyChallenge( |
| 11183 | "HTTP/1.1 407 Unauthorized\r\n" |
| 11184 | "Proxy-Authenticate: Mock realm=proxy\r\n" |
| 11185 | "Proxy-Connection: close\r\n" |
| 11186 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11187 | "Content-Length: 14\r\n\r\n" |
| 11188 | "Unauthorized\r\n"); |
| 11189 | const MockRead kProxyConnected( |
| 11190 | "HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 11191 | |
| 11192 | // NOTE(cbentzel): I wanted TestReadWriteRound to be a simple struct with |
| 11193 | // no constructors, but the C++ compiler on Windows warns about |
| 11194 | // unspecified data in compound literals. So, moved to using constructors, |
| 11195 | // and TestRound's created with the default constructor should not be used. |
| 11196 | struct TestRound { |
| 11197 | TestRound() |
| 11198 | : expected_rv(ERR_UNEXPECTED), |
| 11199 | extra_write(NULL), |
| 11200 | extra_read(NULL) { |
| 11201 | } |
| 11202 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 11203 | int expected_rv_arg) |
| 11204 | : write(write_arg), |
| 11205 | read(read_arg), |
| 11206 | expected_rv(expected_rv_arg), |
| 11207 | extra_write(NULL), |
| 11208 | extra_read(NULL) { |
| 11209 | } |
| 11210 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 11211 | int expected_rv_arg, const MockWrite* extra_write_arg, |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 11212 | const MockRead* extra_read_arg) |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11213 | : write(write_arg), |
| 11214 | read(read_arg), |
| 11215 | expected_rv(expected_rv_arg), |
| 11216 | extra_write(extra_write_arg), |
| 11217 | extra_read(extra_read_arg) { |
| 11218 | } |
| 11219 | MockWrite write; |
| 11220 | MockRead read; |
| 11221 | int expected_rv; |
| 11222 | const MockWrite* extra_write; |
| 11223 | const MockRead* extra_read; |
| 11224 | }; |
| 11225 | |
| 11226 | static const int kNoSSL = 500; |
| 11227 | |
| 11228 | struct TestConfig { |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 11229 | const char* const proxy_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11230 | AuthTiming proxy_auth_timing; |
| 11231 | int proxy_auth_rv; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 11232 | const char* const server_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11233 | AuthTiming server_auth_timing; |
| 11234 | int server_auth_rv; |
| 11235 | int num_auth_rounds; |
| 11236 | int first_ssl_round; |
| 11237 | TestRound rounds[3]; |
| 11238 | } test_configs[] = { |
| 11239 | // Non-authenticating HTTP server with a direct connection. |
| 11240 | { NULL, AUTH_NONE, OK, kServer, AUTH_NONE, OK, 1, kNoSSL, |
| 11241 | { TestRound(kGet, kSuccess, OK)}}, |
| 11242 | // Authenticating HTTP server with a direct connection. |
| 11243 | { NULL, AUTH_NONE, OK, kServer, AUTH_SYNC, OK, 2, kNoSSL, |
| 11244 | { TestRound(kGet, kServerChallenge, OK), |
| 11245 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11246 | { NULL, AUTH_NONE, OK, kServer, AUTH_SYNC, kAuthErr, 2, kNoSSL, |
| 11247 | { TestRound(kGet, kServerChallenge, OK), |
| 11248 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11249 | { NULL, AUTH_NONE, OK, kServer, AUTH_ASYNC, OK, 2, kNoSSL, |
| 11250 | { TestRound(kGet, kServerChallenge, OK), |
| 11251 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11252 | { NULL, AUTH_NONE, OK, kServer, AUTH_ASYNC, kAuthErr, 2, kNoSSL, |
| 11253 | { TestRound(kGet, kServerChallenge, OK), |
| 11254 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11255 | // Non-authenticating HTTP server through a non-authenticating proxy. |
| 11256 | { kProxy, AUTH_NONE, OK, kServer, AUTH_NONE, OK, 1, kNoSSL, |
| 11257 | { TestRound(kGetProxy, kSuccess, OK)}}, |
| 11258 | // Authenticating HTTP server through a non-authenticating proxy. |
| 11259 | { kProxy, AUTH_NONE, OK, kServer, AUTH_SYNC, OK, 2, kNoSSL, |
| 11260 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 11261 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
| 11262 | { kProxy, AUTH_NONE, OK, kServer, AUTH_SYNC, kAuthErr, 2, kNoSSL, |
| 11263 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 11264 | TestRound(kGetAuthThroughProxy, kFailure, kAuthErr)}}, |
| 11265 | { kProxy, AUTH_NONE, OK, kServer, AUTH_ASYNC, OK, 2, kNoSSL, |
| 11266 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 11267 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
| 11268 | { kProxy, AUTH_NONE, OK, kServer, AUTH_ASYNC, kAuthErr, 2, kNoSSL, |
| 11269 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 11270 | TestRound(kGetAuthThroughProxy, kFailure, kAuthErr)}}, |
| 11271 | // Non-authenticating HTTP server through an authenticating proxy. |
| 11272 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 11273 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11274 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
| 11275 | { kProxy, AUTH_SYNC, kAuthErr, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 11276 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11277 | TestRound(kGetProxyAuth, kFailure, kAuthErr)}}, |
| 11278 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 11279 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11280 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
| 11281 | { kProxy, AUTH_ASYNC, kAuthErr, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 11282 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11283 | TestRound(kGetProxyAuth, kFailure, kAuthErr)}}, |
| 11284 | // Authenticating HTTP server through an authenticating proxy. |
| 11285 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_SYNC, OK, 3, kNoSSL, |
| 11286 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11287 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11288 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 11289 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_SYNC, kAuthErr, 3, kNoSSL, |
| 11290 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11291 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11292 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 11293 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_SYNC, OK, 3, kNoSSL, |
| 11294 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11295 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11296 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 11297 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_SYNC, kAuthErr, 3, kNoSSL, |
| 11298 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11299 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11300 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 11301 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_ASYNC, OK, 3, kNoSSL, |
| 11302 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11303 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11304 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 11305 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_ASYNC, kAuthErr, 3, kNoSSL, |
| 11306 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11307 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11308 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 11309 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_ASYNC, OK, 3, kNoSSL, |
| 11310 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11311 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11312 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 11313 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_ASYNC, kAuthErr, 3, kNoSSL, |
| 11314 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11315 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11316 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 11317 | // Non-authenticating HTTPS server with a direct connection. |
| 11318 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_NONE, OK, 1, 0, |
| 11319 | { TestRound(kGet, kSuccess, OK)}}, |
| 11320 | // Authenticating HTTPS server with a direct connection. |
| 11321 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, OK, 2, 0, |
| 11322 | { TestRound(kGet, kServerChallenge, OK), |
| 11323 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11324 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, kAuthErr, 2, 0, |
| 11325 | { TestRound(kGet, kServerChallenge, OK), |
| 11326 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11327 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, OK, 2, 0, |
| 11328 | { TestRound(kGet, kServerChallenge, OK), |
| 11329 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11330 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 2, 0, |
| 11331 | { TestRound(kGet, kServerChallenge, OK), |
| 11332 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11333 | // Non-authenticating HTTPS server with a non-authenticating proxy. |
| 11334 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_NONE, OK, 1, 0, |
| 11335 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 11336 | // Authenticating HTTPS server through a non-authenticating proxy. |
| 11337 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, OK, 2, 0, |
| 11338 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 11339 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11340 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, kAuthErr, 2, 0, |
| 11341 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 11342 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11343 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, OK, 2, 0, |
| 11344 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 11345 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11346 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 2, 0, |
| 11347 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 11348 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11349 | // Non-Authenticating HTTPS server through an authenticating proxy. |
| 11350 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_NONE, OK, 2, 1, |
| 11351 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11352 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 11353 | { kProxy, AUTH_SYNC, kAuthErr, kSecureServer, AUTH_NONE, OK, 2, kNoSSL, |
| 11354 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11355 | TestRound(kConnectProxyAuth, kFailure, kAuthErr)}}, |
| 11356 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_NONE, OK, 2, 1, |
| 11357 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11358 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 11359 | { kProxy, AUTH_ASYNC, kAuthErr, kSecureServer, AUTH_NONE, OK, 2, kNoSSL, |
| 11360 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11361 | TestRound(kConnectProxyAuth, kFailure, kAuthErr)}}, |
| 11362 | // Authenticating HTTPS server through an authenticating proxy. |
| 11363 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_SYNC, OK, 3, 1, |
| 11364 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11365 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 11366 | &kGet, &kServerChallenge), |
| 11367 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11368 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_SYNC, kAuthErr, 3, 1, |
| 11369 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11370 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 11371 | &kGet, &kServerChallenge), |
| 11372 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11373 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_SYNC, OK, 3, 1, |
| 11374 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11375 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 11376 | &kGet, &kServerChallenge), |
| 11377 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11378 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_SYNC, kAuthErr, 3, 1, |
| 11379 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11380 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 11381 | &kGet, &kServerChallenge), |
| 11382 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11383 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_ASYNC, OK, 3, 1, |
| 11384 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11385 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 11386 | &kGet, &kServerChallenge), |
| 11387 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11388 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 3, 1, |
| 11389 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11390 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 11391 | &kGet, &kServerChallenge), |
| 11392 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11393 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_ASYNC, OK, 3, 1, |
| 11394 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11395 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 11396 | &kGet, &kServerChallenge), |
| 11397 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11398 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 3, 1, |
| 11399 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11400 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 11401 | &kGet, &kServerChallenge), |
| 11402 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11403 | }; |
| 11404 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 11405 | for (size_t i = 0; i < arraysize(test_configs); ++i) { |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 11406 | HttpAuthHandlerMock::Factory* auth_factory( |
| 11407 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11408 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11409 | const TestConfig& test_config = test_configs[i]; |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 11410 | |
| 11411 | // Set up authentication handlers as necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11412 | if (test_config.proxy_auth_timing != AUTH_NONE) { |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 11413 | for (int n = 0; n < 2; n++) { |
| 11414 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 11415 | std::string auth_challenge = "Mock realm=proxy"; |
| 11416 | GURL origin(test_config.proxy_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 11417 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 11418 | auth_challenge.end()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 11419 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_PROXY, |
| 11420 | origin, BoundNetLog()); |
| 11421 | auth_handler->SetGenerateExpectation( |
| 11422 | test_config.proxy_auth_timing == AUTH_ASYNC, |
| 11423 | test_config.proxy_auth_rv); |
| 11424 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
| 11425 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11426 | } |
| 11427 | if (test_config.server_auth_timing != AUTH_NONE) { |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 11428 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11429 | std::string auth_challenge = "Mock realm=server"; |
| 11430 | GURL origin(test_config.server_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 11431 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 11432 | auth_challenge.end()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11433 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
| 11434 | origin, BoundNetLog()); |
| 11435 | auth_handler->SetGenerateExpectation( |
| 11436 | test_config.server_auth_timing == AUTH_ASYNC, |
| 11437 | test_config.server_auth_rv); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 11438 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11439 | } |
| 11440 | if (test_config.proxy_url) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 11441 | session_deps_.proxy_service = |
| 11442 | ProxyService::CreateFixed(test_config.proxy_url); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11443 | } else { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 11444 | session_deps_.proxy_service = ProxyService::CreateDirect(); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11445 | } |
| 11446 | |
| 11447 | HttpRequestInfo request; |
| 11448 | request.method = "GET"; |
| 11449 | request.url = GURL(test_config.server_url); |
| 11450 | request.load_flags = 0; |
| 11451 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11452 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11453 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11454 | SSLSocketDataProvider ssl_socket_data_provider(SYNCHRONOUS, OK); |
| 11455 | |
| 11456 | std::vector<std::vector<MockRead>> mock_reads(1); |
| 11457 | std::vector<std::vector<MockWrite>> mock_writes(1); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11458 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
| 11459 | const TestRound& read_write_round = test_config.rounds[round]; |
| 11460 | |
| 11461 | // Set up expected reads and writes. |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11462 | mock_reads.back().push_back(read_write_round.read); |
| 11463 | mock_writes.back().push_back(read_write_round.write); |
| 11464 | |
| 11465 | // kProxyChallenge uses Proxy-Connection: close which means that the |
| 11466 | // socket is closed and a new one will be created for the next request. |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 11467 | if (read_write_round.read.data == kProxyChallenge.data) { |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11468 | mock_reads.push_back(std::vector<MockRead>()); |
| 11469 | mock_writes.push_back(std::vector<MockWrite>()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11470 | } |
| 11471 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11472 | if (read_write_round.extra_read) { |
| 11473 | mock_reads.back().push_back(*read_write_round.extra_read); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11474 | } |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11475 | if (read_write_round.extra_write) { |
| 11476 | mock_writes.back().push_back(*read_write_round.extra_write); |
| 11477 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11478 | |
| 11479 | // Add an SSL sequence if necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11480 | if (round >= test_config.first_ssl_round) |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11481 | session_deps_.socket_factory->AddSSLSocketDataProvider( |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11482 | &ssl_socket_data_provider); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11483 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11484 | |
olli.raula | 525048c | 2015-12-10 07:38:32 | [diff] [blame] | 11485 | std::vector<scoped_ptr<StaticSocketDataProvider>> data_providers; |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11486 | for (size_t i = 0; i < mock_reads.size(); ++i) { |
olli.raula | 525048c | 2015-12-10 07:38:32 | [diff] [blame] | 11487 | data_providers.push_back(make_scoped_ptr(new StaticSocketDataProvider( |
davidben | 5f8b6bc | 2015-11-25 03:19:54 | [diff] [blame] | 11488 | mock_reads[i].data(), mock_reads[i].size(), mock_writes[i].data(), |
olli.raula | 525048c | 2015-12-10 07:38:32 | [diff] [blame] | 11489 | mock_writes[i].size()))); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11490 | session_deps_.socket_factory->AddSocketDataProvider( |
olli.raula | 525048c | 2015-12-10 07:38:32 | [diff] [blame] | 11491 | data_providers.back().get()); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11492 | } |
| 11493 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 11494 | // Transaction must be created after DataProviders, so it's destroyed before |
| 11495 | // they are as well. |
| 11496 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 11497 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11498 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
| 11499 | const TestRound& read_write_round = test_config.rounds[round]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11500 | // Start or restart the transaction. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11501 | TestCompletionCallback callback; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11502 | int rv; |
| 11503 | if (round == 0) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11504 | rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11505 | } else { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11506 | rv = trans.RestartWithAuth( |
| 11507 | AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11508 | } |
| 11509 | if (rv == ERR_IO_PENDING) |
| 11510 | rv = callback.WaitForResult(); |
| 11511 | |
| 11512 | // Compare results with expected data. |
| 11513 | EXPECT_EQ(read_write_round.expected_rv, rv); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11514 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | c0c82849 | 2015-05-15 01:25:55 | [diff] [blame] | 11515 | if (read_write_round.expected_rv != OK) { |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11516 | EXPECT_EQ(round + 1, test_config.num_auth_rounds); |
| 11517 | continue; |
| 11518 | } |
| 11519 | if (round + 1 < test_config.num_auth_rounds) { |
| 11520 | EXPECT_FALSE(response->auth_challenge.get() == NULL); |
| 11521 | } else { |
| 11522 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 11523 | } |
| 11524 | } |
[email protected] | e5ae96a | 2010-04-14 20:12:45 | [diff] [blame] | 11525 | } |
| 11526 | } |
| 11527 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11528 | TEST_P(HttpNetworkTransactionTest, MultiRoundAuth) { |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11529 | // Do multi-round authentication and make sure it works correctly. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11530 | HttpAuthHandlerMock::Factory* auth_factory( |
| 11531 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11532 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 11533 | session_deps_.proxy_service = ProxyService::CreateDirect(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11534 | session_deps_.host_resolver->rules()->AddRule("www.example.com", "10.0.0.1"); |
| 11535 | session_deps_.host_resolver->set_synchronous_mode(true); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11536 | |
| 11537 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 11538 | auth_handler->set_connection_based(true); |
| 11539 | std::string auth_challenge = "Mock realm=server"; |
| 11540 | GURL origin("http://www.example.com"); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 11541 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 11542 | auth_challenge.end()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11543 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
| 11544 | origin, BoundNetLog()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 11545 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11546 | |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11547 | int rv = OK; |
| 11548 | const HttpResponseInfo* response = NULL; |
| 11549 | HttpRequestInfo request; |
| 11550 | request.method = "GET"; |
| 11551 | request.url = origin; |
| 11552 | request.load_flags = 0; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11553 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11554 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11555 | |
| 11556 | // Use a TCP Socket Pool with only one connection per group. This is used |
| 11557 | // to validate that the TCP socket is not released to the pool between |
| 11558 | // each round of multi-round authentication. |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11559 | HttpNetworkSessionPeer session_peer(session.get()); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 11560 | TransportClientSocketPool* transport_pool = new TransportClientSocketPool( |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11561 | 50, // Max sockets for pool |
| 11562 | 1, // Max sockets per group |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11563 | session_deps_.host_resolver.get(), |
| 11564 | session_deps_.socket_factory.get(), |
| 11565 | session_deps_.net_log); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 11566 | scoped_ptr<MockClientSocketPoolManager> mock_pool_manager( |
| 11567 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 11568 | mock_pool_manager->SetTransportSocketPool(transport_pool); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 11569 | session_peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11570 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11571 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11572 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11573 | TestCompletionCallback callback; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11574 | |
| 11575 | const MockWrite kGet( |
| 11576 | "GET / HTTP/1.1\r\n" |
| 11577 | "Host: www.example.com\r\n" |
| 11578 | "Connection: keep-alive\r\n\r\n"); |
| 11579 | const MockWrite kGetAuth( |
| 11580 | "GET / HTTP/1.1\r\n" |
| 11581 | "Host: www.example.com\r\n" |
| 11582 | "Connection: keep-alive\r\n" |
| 11583 | "Authorization: auth_token\r\n\r\n"); |
| 11584 | |
| 11585 | const MockRead kServerChallenge( |
| 11586 | "HTTP/1.1 401 Unauthorized\r\n" |
| 11587 | "WWW-Authenticate: Mock realm=server\r\n" |
| 11588 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11589 | "Content-Length: 14\r\n\r\n" |
| 11590 | "Unauthorized\r\n"); |
| 11591 | const MockRead kSuccess( |
| 11592 | "HTTP/1.1 200 OK\r\n" |
| 11593 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11594 | "Content-Length: 3\r\n\r\n" |
| 11595 | "Yes"); |
| 11596 | |
| 11597 | MockWrite writes[] = { |
| 11598 | // First round |
| 11599 | kGet, |
| 11600 | // Second round |
| 11601 | kGetAuth, |
| 11602 | // Third round |
| 11603 | kGetAuth, |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 11604 | // Fourth round |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11605 | kGetAuth, |
| 11606 | // Competing request |
| 11607 | kGet, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11608 | }; |
| 11609 | MockRead reads[] = { |
| 11610 | // First round |
| 11611 | kServerChallenge, |
| 11612 | // Second round |
| 11613 | kServerChallenge, |
| 11614 | // Third round |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 11615 | kServerChallenge, |
| 11616 | // Fourth round |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11617 | kSuccess, |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11618 | // Competing response |
| 11619 | kSuccess, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11620 | }; |
| 11621 | StaticSocketDataProvider data_provider(reads, arraysize(reads), |
| 11622 | writes, arraysize(writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11623 | session_deps_.socket_factory->AddSocketDataProvider(&data_provider); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11624 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 11625 | const char kSocketGroup[] = "www.example.com:80"; |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11626 | |
| 11627 | // First round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11628 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11629 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11630 | if (rv == ERR_IO_PENDING) |
| 11631 | rv = callback.WaitForResult(); |
| 11632 | EXPECT_EQ(OK, rv); |
| 11633 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 11634 | ASSERT_TRUE(response != NULL); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11635 | EXPECT_FALSE(response->auth_challenge.get() == NULL); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 11636 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11637 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11638 | // In between rounds, another request comes in for the same domain. |
| 11639 | // It should not be able to grab the TCP socket that trans has already |
| 11640 | // claimed. |
| 11641 | scoped_ptr<HttpTransaction> trans_compete( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11642 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11643 | TestCompletionCallback callback_compete; |
| 11644 | rv = trans_compete->Start( |
| 11645 | &request, callback_compete.callback(), BoundNetLog()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11646 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11647 | // callback_compete.WaitForResult at this point would stall forever, |
| 11648 | // since the HttpNetworkTransaction does not release the request back to |
| 11649 | // the pool until after authentication completes. |
| 11650 | |
| 11651 | // Second round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11652 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11653 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11654 | if (rv == ERR_IO_PENDING) |
| 11655 | rv = callback.WaitForResult(); |
| 11656 | EXPECT_EQ(OK, rv); |
| 11657 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 11658 | ASSERT_TRUE(response != NULL); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11659 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 11660 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11661 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11662 | // Third round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11663 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11664 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11665 | if (rv == ERR_IO_PENDING) |
| 11666 | rv = callback.WaitForResult(); |
| 11667 | EXPECT_EQ(OK, rv); |
| 11668 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 11669 | ASSERT_TRUE(response != NULL); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11670 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 11671 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 11672 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11673 | // Fourth round of authentication, which completes successfully. |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 11674 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11675 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 11676 | if (rv == ERR_IO_PENDING) |
| 11677 | rv = callback.WaitForResult(); |
| 11678 | EXPECT_EQ(OK, rv); |
| 11679 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 11680 | ASSERT_TRUE(response != NULL); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 11681 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 11682 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11683 | |
| 11684 | // Read the body since the fourth round was successful. This will also |
| 11685 | // release the socket back to the pool. |
| 11686 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(50)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11687 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11688 | if (rv == ERR_IO_PENDING) |
| 11689 | rv = callback.WaitForResult(); |
| 11690 | EXPECT_EQ(3, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11691 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11692 | EXPECT_EQ(0, rv); |
| 11693 | // There are still 0 idle sockets, since the trans_compete transaction |
| 11694 | // will be handed it immediately after trans releases it to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 11695 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11696 | |
| 11697 | // The competing request can now finish. Wait for the headers and then |
| 11698 | // read the body. |
| 11699 | rv = callback_compete.WaitForResult(); |
| 11700 | EXPECT_EQ(OK, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11701 | rv = trans_compete->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11702 | if (rv == ERR_IO_PENDING) |
| 11703 | rv = callback.WaitForResult(); |
| 11704 | EXPECT_EQ(3, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11705 | rv = trans_compete->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11706 | EXPECT_EQ(0, rv); |
| 11707 | |
| 11708 | // Finally, the socket is released to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 11709 | EXPECT_EQ(1, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11710 | } |
| 11711 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11712 | // This tests the case that a request is issued via http instead of spdy after |
| 11713 | // npn is negotiated. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11714 | TEST_P(HttpNetworkTransactionTest, NpnWithHttpOverSSL) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11715 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 11716 | NextProtoVector next_protos; |
[email protected] | 0ce3af8 | 2013-07-22 16:17:16 | [diff] [blame] | 11717 | next_protos.push_back(kProtoHTTP11); |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 11718 | session_deps_.next_protos = next_protos; |
| 11719 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11720 | HttpRequestInfo request; |
| 11721 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11722 | request.url = GURL("https://www.example.org/"); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11723 | request.load_flags = 0; |
| 11724 | |
| 11725 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11726 | MockWrite( |
| 11727 | "GET / HTTP/1.1\r\n" |
| 11728 | "Host: www.example.org\r\n" |
| 11729 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11730 | }; |
| 11731 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 11732 | std::string alternate_protocol_http_header = |
| 11733 | GetAlternateProtocolHttpHeader(); |
| 11734 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11735 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11736 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 11737 | MockRead(alternate_protocol_http_header.c_str()), |
| 11738 | MockRead("\r\n"), |
| 11739 | MockRead("hello world"), |
| 11740 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11741 | }; |
| 11742 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11743 | SSLSocketDataProvider ssl(ASYNC, OK); |
davidben | 6974bf7 | 2015-04-27 17:52:48 | [diff] [blame] | 11744 | ssl.SetNextProto(kProtoHTTP11); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11745 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11746 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11747 | |
| 11748 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 11749 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11750 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11751 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11752 | TestCompletionCallback callback; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11753 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11754 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11755 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11756 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11757 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11758 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11759 | |
| 11760 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11761 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 11762 | |
| 11763 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 11764 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11765 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11766 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11767 | |
| 11768 | std::string response_data; |
| 11769 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 11770 | EXPECT_EQ("hello world", response_data); |
| 11771 | |
| 11772 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 11773 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11774 | } |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11775 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11776 | // Simulate the SSL handshake completing with an NPN negotiation followed by an |
| 11777 | // immediate server closing of the socket. |
| 11778 | // Regression test for https://crbug.com/46369. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11779 | TEST_P(HttpNetworkTransactionTest, SpdyPostNPNServerHangup) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11780 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 11781 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11782 | |
| 11783 | HttpRequestInfo request; |
| 11784 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11785 | request.url = GURL("https://www.example.org/"); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11786 | request.load_flags = 0; |
| 11787 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11788 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 11789 | ssl.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11790 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11791 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11792 | scoped_ptr<SpdyFrame> req( |
| 11793 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11794 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 1)}; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11795 | |
| 11796 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11797 | MockRead(SYNCHRONOUS, 0, 0) // Not async - return 0 immediately. |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11798 | }; |
| 11799 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11800 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 11801 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11802 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11803 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11804 | TestCompletionCallback callback; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11805 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11806 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11807 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11808 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11809 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11810 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11811 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11812 | EXPECT_EQ(ERR_CONNECTION_CLOSED, callback.WaitForResult()); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11813 | } |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 11814 | |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 11815 | // A subclass of HttpAuthHandlerMock that records the request URL when |
| 11816 | // it gets it. This is needed since the auth handler may get destroyed |
| 11817 | // before we get a chance to query it. |
| 11818 | class UrlRecordingHttpAuthHandlerMock : public HttpAuthHandlerMock { |
| 11819 | public: |
| 11820 | explicit UrlRecordingHttpAuthHandlerMock(GURL* url) : url_(url) {} |
| 11821 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11822 | ~UrlRecordingHttpAuthHandlerMock() override {} |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 11823 | |
| 11824 | protected: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11825 | int GenerateAuthTokenImpl(const AuthCredentials* credentials, |
| 11826 | const HttpRequestInfo* request, |
| 11827 | const CompletionCallback& callback, |
| 11828 | std::string* auth_token) override { |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 11829 | *url_ = request->url; |
| 11830 | return HttpAuthHandlerMock::GenerateAuthTokenImpl( |
| 11831 | credentials, request, callback, auth_token); |
| 11832 | } |
| 11833 | |
| 11834 | private: |
| 11835 | GURL* url_; |
| 11836 | }; |
| 11837 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11838 | // This test ensures that the URL passed into the proxy is upgraded to https |
| 11839 | // when doing an Alternate Protocol upgrade. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11840 | TEST_P(HttpNetworkTransactionTest, SpdyAlternateProtocolThroughProxy) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11841 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 11842 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11843 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 11844 | session_deps_.proxy_service = |
| 11845 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11846 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11847 | session_deps_.net_log = &net_log; |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 11848 | GURL request_url; |
| 11849 | { |
| 11850 | HttpAuthHandlerMock::Factory* auth_factory = |
| 11851 | new HttpAuthHandlerMock::Factory(); |
| 11852 | UrlRecordingHttpAuthHandlerMock* auth_handler = |
| 11853 | new UrlRecordingHttpAuthHandlerMock(&request_url); |
| 11854 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
| 11855 | auth_factory->set_do_init_from_challenge(true); |
| 11856 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
| 11857 | } |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11858 | |
| 11859 | HttpRequestInfo request; |
| 11860 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11861 | request.url = GURL("http://www.example.org"); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11862 | request.load_flags = 0; |
| 11863 | |
| 11864 | // First round goes unauthenticated through the proxy. |
| 11865 | MockWrite data_writes_1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11866 | MockWrite( |
| 11867 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 11868 | "Host: www.example.org\r\n" |
| 11869 | "Proxy-Connection: keep-alive\r\n" |
| 11870 | "\r\n"), |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11871 | }; |
| 11872 | MockRead data_reads_1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11873 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
bnc | 33b8cef4 | 2014-11-19 17:30:38 | [diff] [blame] | 11874 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 11875 | MockRead("Alternate-Protocol: 443:"), |
| 11876 | MockRead(GetAlternateProtocolFromParam()), |
| 11877 | MockRead("\r\n"), |
| 11878 | MockRead("Proxy-Connection: close\r\n"), |
| 11879 | MockRead("\r\n"), |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11880 | }; |
| 11881 | StaticSocketDataProvider data_1(data_reads_1, arraysize(data_reads_1), |
| 11882 | data_writes_1, arraysize(data_writes_1)); |
| 11883 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11884 | // Second round tries to tunnel to www.example.org due to the |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11885 | // Alternate-Protocol announcement in the first round. It fails due |
| 11886 | // to a proxy authentication challenge. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11887 | // After the failure, a tunnel is established to www.example.org using |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 11888 | // Proxy-Authorization headers. There is then a SPDY request round. |
| 11889 | // |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 11890 | // NOTE: Despite the "Proxy-Connection: Close", these are done on the |
| 11891 | // same MockTCPClientSocket since the underlying HttpNetworkClientSocket |
| 11892 | // does a Disconnect and Connect on the same socket, rather than trying |
| 11893 | // to obtain a new one. |
| 11894 | // |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 11895 | // NOTE: Originally, the proxy response to the second CONNECT request |
| 11896 | // simply returned another 407 so the unit test could skip the SSL connection |
| 11897 | // establishment and SPDY framing issues. Alas, the |
| 11898 | // retry-http-when-alternate-protocol fails logic kicks in, which was more |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11899 | // complicated to set up expectations for than the SPDY session. |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 11900 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11901 | scoped_ptr<SpdyFrame> req( |
| 11902 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11903 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11904 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11905 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 11906 | MockWrite data_writes_2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11907 | // First connection attempt without Proxy-Authorization. |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11908 | MockWrite(ASYNC, 0, |
| 11909 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 11910 | "Host: www.example.org:443\r\n" |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11911 | "Proxy-Connection: keep-alive\r\n" |
| 11912 | "\r\n"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 11913 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11914 | // Second connection attempt with Proxy-Authorization. |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11915 | MockWrite(ASYNC, 2, |
| 11916 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 11917 | "Host: www.example.org:443\r\n" |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11918 | "Proxy-Connection: keep-alive\r\n" |
| 11919 | "Proxy-Authorization: auth_token\r\n" |
| 11920 | "\r\n"), |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11921 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11922 | // SPDY request |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11923 | CreateMockWrite(*req, 4), |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11924 | }; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 11925 | MockRead data_reads_2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11926 | // First connection attempt fails |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 11927 | MockRead(ASYNC, 1, |
| 11928 | "HTTP/1.1 407 Unauthorized\r\n" |
| 11929 | "Proxy-Authenticate: Mock\r\n" |
| 11930 | "Content-Length: 0\r\n" |
| 11931 | "Proxy-Connection: keep-alive\r\n" |
| 11932 | "\r\n"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 11933 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11934 | // Second connection attempt passes |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 11935 | MockRead(ASYNC, 3, "HTTP/1.1 200 Connected\r\n\r\n"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 11936 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11937 | // SPDY response |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 11938 | CreateMockRead(*resp.get(), 5), CreateMockRead(*data.get(), 6), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11939 | MockRead(ASYNC, 0, 0, 7), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 11940 | }; |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11941 | SequencedSocketData data_2(data_reads_2, arraysize(data_reads_2), |
| 11942 | data_writes_2, arraysize(data_writes_2)); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11943 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11944 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 11945 | ssl.SetNextProto(GetProtocol()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11946 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 11947 | ASSERT_TRUE(ssl.cert.get()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11948 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11949 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11950 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 11951 | NULL, 0, NULL, 0); |
| 11952 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 11953 | never_finishing_connect); |
| 11954 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11955 | session_deps_.socket_factory->AddSocketDataProvider(&data_1); |
| 11956 | session_deps_.socket_factory->AddSocketDataProvider(&data_2); |
| 11957 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11958 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11959 | &hanging_non_alternate_protocol_socket); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11960 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11961 | |
| 11962 | // First round should work and provide the Alternate-Protocol state. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11963 | TestCompletionCallback callback_1; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11964 | scoped_ptr<HttpTransaction> trans_1( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11965 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11966 | int rv = trans_1->Start(&request, callback_1.callback(), BoundNetLog()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11967 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11968 | EXPECT_EQ(OK, callback_1.WaitForResult()); |
| 11969 | |
| 11970 | // Second round should attempt a tunnel connect and get an auth challenge. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11971 | TestCompletionCallback callback_2; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11972 | scoped_ptr<HttpTransaction> trans_2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11973 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11974 | rv = trans_2->Start(&request, callback_2.callback(), BoundNetLog()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11975 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11976 | EXPECT_EQ(OK, callback_2.WaitForResult()); |
| 11977 | const HttpResponseInfo* response = trans_2->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 11978 | ASSERT_TRUE(response != NULL); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11979 | ASSERT_FALSE(response->auth_challenge.get() == NULL); |
| 11980 | |
| 11981 | // Restart with auth. Tunnel should work and response received. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11982 | TestCompletionCallback callback_3; |
| 11983 | rv = trans_2->RestartWithAuth( |
| 11984 | AuthCredentials(kFoo, kBar), callback_3.callback()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11985 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11986 | EXPECT_EQ(OK, callback_3.WaitForResult()); |
| 11987 | |
| 11988 | // After all that work, these two lines (or actually, just the scheme) are |
| 11989 | // what this test is all about. Make sure it happens correctly. |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11990 | EXPECT_EQ("https", request_url.scheme()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11991 | EXPECT_EQ("www.example.org", request_url.host()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11992 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11993 | LoadTimingInfo load_timing_info; |
| 11994 | EXPECT_TRUE(trans_2->GetLoadTimingInfo(&load_timing_info)); |
| 11995 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 11996 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 11997 | } |
| 11998 | |
| 11999 | // Test that if we cancel the transaction as the connection is completing, that |
| 12000 | // everything tears down correctly. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12001 | TEST_P(HttpNetworkTransactionTest, SimpleCancel) { |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12002 | // Setup everything about the connection to complete synchronously, so that |
| 12003 | // after calling HttpNetworkTransaction::Start, the only thing we're waiting |
| 12004 | // for is the callback from the HttpStreamRequest. |
| 12005 | // Then cancel the transaction. |
| 12006 | // Verify that we don't crash. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12007 | MockConnect mock_connect(SYNCHRONOUS, OK); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12008 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12009 | MockRead(SYNCHRONOUS, "HTTP/1.0 200 OK\r\n\r\n"), |
| 12010 | MockRead(SYNCHRONOUS, "hello world"), |
| 12011 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12012 | }; |
| 12013 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12014 | HttpRequestInfo request; |
| 12015 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12016 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12017 | request.load_flags = 0; |
| 12018 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12019 | session_deps_.host_resolver->set_synchronous_mode(true); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12020 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12021 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12022 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12023 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12024 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 12025 | data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12026 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12027 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12028 | TestCompletionCallback callback; |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12029 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12030 | BoundTestNetLog log; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12031 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12032 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12033 | trans.reset(); // Cancel the transaction here. |
| 12034 | |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 12035 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 12036 | } |
| 12037 | |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12038 | // Test that if a transaction is cancelled after receiving the headers, the |
| 12039 | // stream is drained properly and added back to the socket pool. The main |
| 12040 | // purpose of this test is to make sure that an HttpStreamParser can be read |
| 12041 | // from after the HttpNetworkTransaction and the objects it owns have been |
| 12042 | // deleted. |
| 12043 | // See http://crbug.com/368418 |
| 12044 | TEST_P(HttpNetworkTransactionTest, CancelAfterHeaders) { |
| 12045 | MockRead data_reads[] = { |
| 12046 | MockRead(ASYNC, "HTTP/1.1 200 OK\r\n"), |
| 12047 | MockRead(ASYNC, "Content-Length: 2\r\n"), |
| 12048 | MockRead(ASYNC, "Connection: Keep-Alive\r\n\r\n"), |
| 12049 | MockRead(ASYNC, "1"), |
| 12050 | // 2 async reads are necessary to trigger a ReadResponseBody call after the |
| 12051 | // HttpNetworkTransaction has been deleted. |
| 12052 | MockRead(ASYNC, "2"), |
| 12053 | MockRead(SYNCHRONOUS, ERR_IO_PENDING), // Should never read this. |
| 12054 | }; |
| 12055 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 12056 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12057 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12058 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12059 | |
| 12060 | { |
| 12061 | HttpRequestInfo request; |
| 12062 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12063 | request.url = GURL("http://www.example.org/"); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12064 | request.load_flags = 0; |
| 12065 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12066 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12067 | TestCompletionCallback callback; |
| 12068 | |
| 12069 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
| 12070 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12071 | callback.WaitForResult(); |
| 12072 | |
| 12073 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 12074 | ASSERT_TRUE(response != NULL); |
| 12075 | EXPECT_TRUE(response->headers.get() != NULL); |
| 12076 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12077 | |
| 12078 | // The transaction and HttpRequestInfo are deleted. |
| 12079 | } |
| 12080 | |
| 12081 | // Let the HttpResponseBodyDrainer drain the socket. |
| 12082 | base::MessageLoop::current()->RunUntilIdle(); |
| 12083 | |
| 12084 | // Socket should now be idle, waiting to be reused. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12085 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12086 | } |
| 12087 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12088 | // Test a basic GET request through a proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12089 | TEST_P(HttpNetworkTransactionTest, ProxyGet) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12090 | session_deps_.proxy_service = |
| 12091 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12092 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12093 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12094 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12095 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12096 | HttpRequestInfo request; |
| 12097 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12098 | request.url = GURL("http://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12099 | |
| 12100 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12101 | MockWrite( |
| 12102 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 12103 | "Host: www.example.org\r\n" |
| 12104 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12105 | }; |
| 12106 | |
| 12107 | MockRead data_reads1[] = { |
| 12108 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12109 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 12110 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12111 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12112 | }; |
| 12113 | |
| 12114 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 12115 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12116 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12117 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12118 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12119 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 12120 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12121 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 12122 | BeforeProxyHeadersSentHandler proxy_headers_handler; |
| 12123 | trans->SetBeforeProxyHeadersSentCallback( |
| 12124 | base::Bind(&BeforeProxyHeadersSentHandler::OnBeforeProxyHeadersSent, |
| 12125 | base::Unretained(&proxy_headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 12126 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12127 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12128 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12129 | |
| 12130 | rv = callback1.WaitForResult(); |
| 12131 | EXPECT_EQ(OK, rv); |
| 12132 | |
| 12133 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 12134 | ASSERT_TRUE(response != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12135 | |
| 12136 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 12137 | EXPECT_EQ(200, response->headers->response_code()); |
| 12138 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 12139 | EXPECT_TRUE(response->was_fetched_via_proxy); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 12140 | EXPECT_TRUE( |
| 12141 | response->proxy_server.Equals(HostPortPair::FromString("myproxy:70"))); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 12142 | EXPECT_TRUE(proxy_headers_handler.observed_before_proxy_headers_sent()); |
| 12143 | EXPECT_EQ("myproxy:70", proxy_headers_handler.observed_proxy_server_uri()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12144 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 12145 | |
| 12146 | LoadTimingInfo load_timing_info; |
| 12147 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 12148 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 12149 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12150 | } |
| 12151 | |
| 12152 | // Test a basic HTTPS GET request through a proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12153 | TEST_P(HttpNetworkTransactionTest, ProxyTunnelGet) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12154 | session_deps_.proxy_service = |
| 12155 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12156 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12157 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12158 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12159 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12160 | HttpRequestInfo request; |
| 12161 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12162 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12163 | |
| 12164 | // Since we have proxy, should try to establish tunnel. |
| 12165 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12166 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 12167 | "Host: www.example.org:443\r\n" |
| 12168 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12169 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12170 | MockWrite("GET / HTTP/1.1\r\n" |
| 12171 | "Host: www.example.org\r\n" |
| 12172 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12173 | }; |
| 12174 | |
| 12175 | MockRead data_reads1[] = { |
| 12176 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 12177 | |
| 12178 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12179 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 12180 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12181 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12182 | }; |
| 12183 | |
| 12184 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 12185 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12186 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12187 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12188 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12189 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12190 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12191 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 12192 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12193 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 12194 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12195 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12196 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12197 | |
| 12198 | rv = callback1.WaitForResult(); |
| 12199 | EXPECT_EQ(OK, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 12200 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 12201 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12202 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 12203 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12204 | NetLog::PHASE_NONE); |
| 12205 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 12206 | entries, pos, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12207 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 12208 | NetLog::PHASE_NONE); |
| 12209 | |
| 12210 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 12211 | ASSERT_TRUE(response != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12212 | |
| 12213 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 12214 | EXPECT_EQ(200, response->headers->response_code()); |
| 12215 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 12216 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 12217 | EXPECT_TRUE(response->was_fetched_via_proxy); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 12218 | EXPECT_TRUE( |
| 12219 | response->proxy_server.Equals(HostPortPair::FromString("myproxy:70"))); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 12220 | |
| 12221 | LoadTimingInfo load_timing_info; |
| 12222 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 12223 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 12224 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12225 | } |
| 12226 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12227 | // Test a basic HTTPS GET request through a proxy, connecting to an IPv6 |
| 12228 | // literal host. |
| 12229 | TEST_P(HttpNetworkTransactionTest, ProxyTunnelGetIPv6) { |
| 12230 | session_deps_.proxy_service = |
| 12231 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 12232 | BoundTestNetLog log; |
| 12233 | session_deps_.net_log = log.bound().net_log(); |
| 12234 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12235 | |
| 12236 | HttpRequestInfo request; |
| 12237 | request.method = "GET"; |
| 12238 | request.url = GURL("https://[::1]:443/"); |
| 12239 | |
| 12240 | // Since we have proxy, should try to establish tunnel. |
| 12241 | MockWrite data_writes1[] = { |
| 12242 | MockWrite("CONNECT [::1]:443 HTTP/1.1\r\n" |
| 12243 | "Host: [::1]:443\r\n" |
| 12244 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 12245 | |
| 12246 | MockWrite("GET / HTTP/1.1\r\n" |
| 12247 | "Host: [::1]\r\n" |
| 12248 | "Connection: keep-alive\r\n\r\n"), |
| 12249 | }; |
| 12250 | |
| 12251 | MockRead data_reads1[] = { |
| 12252 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 12253 | |
| 12254 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12255 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 12256 | MockRead("Content-Length: 100\r\n\r\n"), |
| 12257 | MockRead(SYNCHRONOUS, OK), |
| 12258 | }; |
| 12259 | |
| 12260 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 12261 | data_writes1, arraysize(data_writes1)); |
| 12262 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 12263 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 12264 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12265 | |
| 12266 | TestCompletionCallback callback1; |
| 12267 | |
| 12268 | scoped_ptr<HttpTransaction> trans( |
| 12269 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 12270 | |
| 12271 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 12272 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12273 | |
| 12274 | rv = callback1.WaitForResult(); |
| 12275 | EXPECT_EQ(OK, rv); |
| 12276 | TestNetLogEntry::List entries; |
| 12277 | log.GetEntries(&entries); |
| 12278 | size_t pos = ExpectLogContainsSomewhere( |
| 12279 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 12280 | NetLog::PHASE_NONE); |
| 12281 | ExpectLogContainsSomewhere( |
| 12282 | entries, pos, NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 12283 | NetLog::PHASE_NONE); |
| 12284 | |
| 12285 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 12286 | ASSERT_TRUE(response != NULL); |
| 12287 | |
| 12288 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 12289 | EXPECT_EQ(200, response->headers->response_code()); |
| 12290 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 12291 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 12292 | EXPECT_TRUE(response->was_fetched_via_proxy); |
| 12293 | EXPECT_TRUE( |
| 12294 | response->proxy_server.Equals(HostPortPair::FromString("myproxy:70"))); |
| 12295 | |
| 12296 | LoadTimingInfo load_timing_info; |
| 12297 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 12298 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 12299 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 12300 | } |
| 12301 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12302 | // Test a basic HTTPS GET request through a proxy, but the server hangs up |
| 12303 | // while establishing the tunnel. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12304 | TEST_P(HttpNetworkTransactionTest, ProxyTunnelGetHangup) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12305 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12306 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12307 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12308 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12309 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12310 | HttpRequestInfo request; |
| 12311 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12312 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12313 | |
| 12314 | // Since we have proxy, should try to establish tunnel. |
| 12315 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12316 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 12317 | "Host: www.example.org:443\r\n" |
| 12318 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12319 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12320 | MockWrite("GET / HTTP/1.1\r\n" |
| 12321 | "Host: www.example.org\r\n" |
| 12322 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12323 | }; |
| 12324 | |
| 12325 | MockRead data_reads1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12326 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12327 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12328 | MockRead(ASYNC, 0, 0), // EOF |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12329 | }; |
| 12330 | |
| 12331 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 12332 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12333 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12334 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12335 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12336 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12337 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12338 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 12339 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12340 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 12341 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12342 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12343 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12344 | |
| 12345 | rv = callback1.WaitForResult(); |
| 12346 | EXPECT_EQ(ERR_EMPTY_RESPONSE, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 12347 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 12348 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12349 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 12350 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12351 | NetLog::PHASE_NONE); |
| 12352 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 12353 | entries, pos, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12354 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 12355 | NetLog::PHASE_NONE); |
| 12356 | } |
| 12357 | |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12358 | // Test for crbug.com/55424. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12359 | TEST_P(HttpNetworkTransactionTest, PreconnectWithExistingSpdySession) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12360 | scoped_ptr<SpdyFrame> req( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12361 | spdy_util_.ConstructSpdyGet("https://www.example.org", false, 1, LOWEST)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12362 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12363 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12364 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12365 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12366 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12367 | CreateMockRead(*resp, 1), CreateMockRead(*data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12368 | }; |
| 12369 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12370 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 12371 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12372 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12373 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12374 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 12375 | ssl.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12376 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12377 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12378 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12379 | |
| 12380 | // Set up an initial SpdySession in the pool to reuse. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12381 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 12382 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 12383 | PRIVACY_MODE_DISABLED); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 12384 | base::WeakPtr<SpdySession> spdy_session = |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12385 | CreateInsecureSpdySession(session.get(), key, BoundNetLog()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12386 | |
| 12387 | HttpRequestInfo request; |
| 12388 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12389 | request.url = GURL("https://www.example.org/"); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12390 | request.load_flags = 0; |
| 12391 | |
| 12392 | // This is the important line that marks this as a preconnect. |
| 12393 | request.motivation = HttpRequestInfo::PRECONNECT_MOTIVATED; |
| 12394 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 12395 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12396 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12397 | |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 12398 | TestCompletionCallback callback; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12399 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12400 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12401 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12402 | } |
| 12403 | |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 12404 | // Given a net error, cause that error to be returned from the first Write() |
| 12405 | // call and verify that the HttpTransaction fails with that error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12406 | void HttpNetworkTransactionTest::CheckErrorIsPassedBack( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12407 | int error, IoMode mode) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12408 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12409 | request_info.url = GURL("https://www.example.com/"); |
| 12410 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12411 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12412 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12413 | SSLSocketDataProvider ssl_data(mode, OK); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12414 | MockWrite data_writes[] = { |
| 12415 | MockWrite(mode, error), |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 12416 | }; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12417 | StaticSocketDataProvider data(NULL, 0, data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12418 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12419 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 12420 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12421 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 12422 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12423 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 12424 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12425 | TestCompletionCallback callback; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12426 | int rv = trans->Start(&request_info, callback.callback(), BoundNetLog()); |
| 12427 | if (rv == ERR_IO_PENDING) |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 12428 | rv = callback.WaitForResult(); |
| 12429 | ASSERT_EQ(error, rv); |
| 12430 | } |
| 12431 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12432 | TEST_P(HttpNetworkTransactionTest, SSLWriteCertError) { |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 12433 | // Just check a grab bag of cert errors. |
| 12434 | static const int kErrors[] = { |
| 12435 | ERR_CERT_COMMON_NAME_INVALID, |
| 12436 | ERR_CERT_AUTHORITY_INVALID, |
| 12437 | ERR_CERT_DATE_INVALID, |
| 12438 | }; |
| 12439 | for (size_t i = 0; i < arraysize(kErrors); i++) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12440 | CheckErrorIsPassedBack(kErrors[i], ASYNC); |
| 12441 | CheckErrorIsPassedBack(kErrors[i], SYNCHRONOUS); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 12442 | } |
| 12443 | } |
| 12444 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12445 | // Ensure that a client certificate is removed from the SSL client auth |
| 12446 | // cache when: |
| 12447 | // 1) No proxy is involved. |
| 12448 | // 2) TLS False Start is disabled. |
| 12449 | // 3) The initial TLS handshake requests a client certificate. |
| 12450 | // 4) The client supplies an invalid/unacceptable certificate. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12451 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 12452 | ClientAuthCertCache_Direct_NoFalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12453 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12454 | request_info.url = GURL("https://www.example.com/"); |
| 12455 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12456 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12457 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12458 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12459 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12460 | |
| 12461 | // [ssl_]data1 contains the data for the first SSL handshake. When a |
| 12462 | // CertificateRequest is received for the first time, the handshake will |
| 12463 | // be aborted to allow the caller to provide a certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12464 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12465 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12466 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12467 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12468 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12469 | |
| 12470 | // [ssl_]data2 contains the data for the second SSL handshake. When TLS |
| 12471 | // False Start is not being used, the result of the SSL handshake will be |
| 12472 | // returned as part of the SSLClientSocket::Connect() call. This test |
| 12473 | // matches the result of a server sending a handshake_failure alert, |
| 12474 | // rather than a Finished message, because it requires a client |
| 12475 | // certificate and none was supplied. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12476 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12477 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12478 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12479 | StaticSocketDataProvider data2(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12480 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12481 | |
| 12482 | // [ssl_]data3 contains the data for the third SSL handshake. When a |
| 12483 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 12484 | // HttpNetworkTransaction will attempt to fallback to TLSv1.1 if the previous |
| 12485 | // connection was attempted with TLSv1.2. This is transparent to the caller |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12486 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 12487 | // requiring a client certificate, this fallback handshake should also |
| 12488 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12489 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12490 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12491 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12492 | StaticSocketDataProvider data3(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12493 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12494 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12495 | // [ssl_]data4 contains the data for the fourth SSL handshake. When a |
| 12496 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 12497 | // HttpNetworkTransaction will attempt to fallback to TLSv1 if the previous |
| 12498 | // connection was attempted with TLSv1.1. This is transparent to the caller |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12499 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 12500 | // requiring a client certificate, this fallback handshake should also |
| 12501 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12502 | SSLSocketDataProvider ssl_data4(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12503 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12504 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12505 | StaticSocketDataProvider data4(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12506 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12507 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12508 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 12509 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12510 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12511 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12512 | // Begin the SSL handshake with the peer. This consumes ssl_data1. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12513 | TestCompletionCallback callback; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12514 | int rv = trans->Start(&request_info, callback.callback(), BoundNetLog()); |
| 12515 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12516 | |
| 12517 | // Complete the SSL handshake, which should abort due to requiring a |
| 12518 | // client certificate. |
| 12519 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12520 | ASSERT_EQ(ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12521 | |
| 12522 | // Indicate that no certificate should be supplied. From the perspective |
| 12523 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 12524 | // certificate, so this is the same as supply a |
| 12525 | // legitimate-but-unacceptable certificate. |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12526 | rv = trans->RestartWithCertificate(NULL, NULL, callback.callback()); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12527 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12528 | |
| 12529 | // Ensure the certificate was added to the client auth cache before |
| 12530 | // allowing the connection to continue restarting. |
| 12531 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12532 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12533 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12534 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12535 | ASSERT_EQ(NULL, client_cert.get()); |
| 12536 | |
| 12537 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12538 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 12539 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12540 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12541 | ASSERT_EQ(ERR_SSL_PROTOCOL_ERROR, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12542 | |
| 12543 | // Ensure that the client certificate is removed from the cache on a |
| 12544 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12545 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12546 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12547 | } |
| 12548 | |
| 12549 | // Ensure that a client certificate is removed from the SSL client auth |
| 12550 | // cache when: |
| 12551 | // 1) No proxy is involved. |
| 12552 | // 2) TLS False Start is enabled. |
| 12553 | // 3) The initial TLS handshake requests a client certificate. |
| 12554 | // 4) The client supplies an invalid/unacceptable certificate. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12555 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 12556 | ClientAuthCertCache_Direct_FalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12557 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12558 | request_info.url = GURL("https://www.example.com/"); |
| 12559 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12560 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12561 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12562 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12563 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12564 | |
| 12565 | // When TLS False Start is used, SSLClientSocket::Connect() calls will |
| 12566 | // return successfully after reading up to the peer's Certificate message. |
| 12567 | // This is to allow the caller to call SSLClientSocket::Write(), which can |
| 12568 | // enqueue application data to be sent in the same packet as the |
| 12569 | // ChangeCipherSpec and Finished messages. |
| 12570 | // The actual handshake will be finished when SSLClientSocket::Read() is |
| 12571 | // called, which expects to process the peer's ChangeCipherSpec and |
| 12572 | // Finished messages. If there was an error negotiating with the peer, |
| 12573 | // such as due to the peer requiring a client certificate when none was |
| 12574 | // supplied, the alert sent by the peer won't be processed until Read() is |
| 12575 | // called. |
| 12576 | |
| 12577 | // Like the non-False Start case, when a client certificate is requested by |
| 12578 | // the peer, the handshake is aborted during the Connect() call. |
| 12579 | // [ssl_]data1 represents the initial SSL handshake with the peer. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12580 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12581 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12582 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12583 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12584 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12585 | |
| 12586 | // When a client certificate is supplied, Connect() will not be aborted |
| 12587 | // when the peer requests the certificate. Instead, the handshake will |
| 12588 | // artificially succeed, allowing the caller to write the HTTP request to |
| 12589 | // the socket. The handshake messages are not processed until Read() is |
| 12590 | // called, which then detects that the handshake was aborted, due to the |
| 12591 | // peer sending a handshake_failure because it requires a client |
| 12592 | // certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12593 | SSLSocketDataProvider ssl_data2(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12594 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12595 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12596 | MockRead data2_reads[] = { |
| 12597 | MockRead(ASYNC /* async */, ERR_SSL_PROTOCOL_ERROR), |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12598 | }; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12599 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12600 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12601 | |
| 12602 | // As described in ClientAuthCertCache_Direct_NoFalseStart, [ssl_]data3 is |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12603 | // the data for the SSL handshake once the TLSv1.1 connection falls back to |
| 12604 | // TLSv1. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12605 | SSLSocketDataProvider ssl_data3(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12606 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12607 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12608 | StaticSocketDataProvider data3(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12609 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12610 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12611 | // [ssl_]data4 is the data for the SSL handshake once the TLSv1 connection |
| 12612 | // falls back to SSLv3. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12613 | SSLSocketDataProvider ssl_data4(ASYNC, OK); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12614 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12615 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12616 | StaticSocketDataProvider data4(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12617 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12618 | |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 12619 | // Need one more if TLSv1.2 is enabled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12620 | SSLSocketDataProvider ssl_data5(ASYNC, OK); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 12621 | ssl_data5.cert_request_info = cert_request.get(); |
| 12622 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data5); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12623 | StaticSocketDataProvider data5(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 12624 | session_deps_.socket_factory->AddSocketDataProvider(&data5); |
| 12625 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12626 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 12627 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12628 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12629 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12630 | // Begin the initial SSL handshake. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12631 | TestCompletionCallback callback; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12632 | int rv = trans->Start(&request_info, callback.callback(), BoundNetLog()); |
| 12633 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12634 | |
| 12635 | // Complete the SSL handshake, which should abort due to requiring a |
| 12636 | // client certificate. |
| 12637 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12638 | ASSERT_EQ(ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12639 | |
| 12640 | // Indicate that no certificate should be supplied. From the perspective |
| 12641 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 12642 | // certificate, so this is the same as supply a |
| 12643 | // legitimate-but-unacceptable certificate. |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12644 | rv = trans->RestartWithCertificate(NULL, NULL, callback.callback()); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12645 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12646 | |
| 12647 | // Ensure the certificate was added to the client auth cache before |
| 12648 | // allowing the connection to continue restarting. |
| 12649 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12650 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12651 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12652 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12653 | ASSERT_EQ(NULL, client_cert.get()); |
| 12654 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12655 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12656 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 12657 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12658 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12659 | ASSERT_EQ(ERR_SSL_PROTOCOL_ERROR, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12660 | |
| 12661 | // Ensure that the client certificate is removed from the cache on a |
| 12662 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12663 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12664 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12665 | } |
| 12666 | |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12667 | // Ensure that a client certificate is removed from the SSL client auth |
| 12668 | // cache when: |
| 12669 | // 1) An HTTPS proxy is involved. |
| 12670 | // 3) The HTTPS proxy requests a client certificate. |
| 12671 | // 4) The client supplies an invalid/unacceptable certificate for the |
| 12672 | // proxy. |
| 12673 | // The test is repeated twice, first for connecting to an HTTPS endpoint, |
| 12674 | // then for connecting to an HTTP endpoint. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12675 | TEST_P(HttpNetworkTransactionTest, ClientAuthCertCache_Proxy_Fail) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12676 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12677 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12678 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12679 | |
| 12680 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12681 | cert_request->host_and_port = HostPortPair("proxy", 70); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12682 | |
| 12683 | // See ClientAuthCertCache_Direct_NoFalseStart for the explanation of |
| 12684 | // [ssl_]data[1-3]. Rather than represending the endpoint |
| 12685 | // (www.example.com:443), they represent failures with the HTTPS proxy |
| 12686 | // (proxy:70). |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12687 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12688 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12689 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12690 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12691 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12692 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12693 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12694 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12695 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12696 | StaticSocketDataProvider data2(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12697 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12698 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12699 | // TODO(wtc): find out why this unit test doesn't need [ssl_]data3. |
| 12700 | #if 0 |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12701 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12702 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12703 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12704 | StaticSocketDataProvider data3(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12705 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12706 | #endif |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12707 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12708 | HttpRequestInfo requests[2]; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12709 | requests[0].url = GURL("https://www.example.com/"); |
| 12710 | requests[0].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12711 | requests[0].load_flags = LOAD_NORMAL; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12712 | |
| 12713 | requests[1].url = GURL("http://www.example.com/"); |
| 12714 | requests[1].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12715 | requests[1].load_flags = LOAD_NORMAL; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12716 | |
| 12717 | for (size_t i = 0; i < arraysize(requests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12718 | session_deps_.socket_factory->ResetNextMockIndexes(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12719 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12720 | scoped_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12721 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12722 | |
| 12723 | // Begin the SSL handshake with the proxy. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12724 | TestCompletionCallback callback; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12725 | int rv = trans->Start(&requests[i], callback.callback(), BoundNetLog()); |
| 12726 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12727 | |
| 12728 | // Complete the SSL handshake, which should abort due to requiring a |
| 12729 | // client certificate. |
| 12730 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12731 | ASSERT_EQ(ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12732 | |
| 12733 | // Indicate that no certificate should be supplied. From the perspective |
| 12734 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 12735 | // certificate, so this is the same as supply a |
| 12736 | // legitimate-but-unacceptable certificate. |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12737 | rv = trans->RestartWithCertificate(NULL, NULL, callback.callback()); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12738 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12739 | |
| 12740 | // Ensure the certificate was added to the client auth cache before |
| 12741 | // allowing the connection to continue restarting. |
| 12742 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12743 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12744 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12745 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12746 | ASSERT_EQ(NULL, client_cert.get()); |
| 12747 | // Ensure the certificate was NOT cached for the endpoint. This only |
| 12748 | // applies to HTTPS requests, but is fine to check for HTTP requests. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12749 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12750 | HostPortPair("www.example.com", 443), &client_cert, |
| 12751 | &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12752 | |
| 12753 | // Restart the handshake. This will consume ssl_data2, which fails, and |
| 12754 | // then consume ssl_data3, which should also fail. The result code is |
| 12755 | // checked against what ssl_data3 should return. |
| 12756 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12757 | ASSERT_EQ(ERR_PROXY_CONNECTION_FAILED, rv); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12758 | |
| 12759 | // Now that the new handshake has failed, ensure that the client |
| 12760 | // certificate was removed from the client auth cache. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12761 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12762 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12763 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12764 | HostPortPair("www.example.com", 443), &client_cert, |
| 12765 | &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12766 | } |
| 12767 | } |
| 12768 | |
mmenke | 5c64213 | 2015-06-02 16:05:13 | [diff] [blame] | 12769 | TEST_P(HttpNetworkTransactionTest, UseIPConnectionPooling) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12770 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 12771 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12772 | |
| 12773 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12774 | session_deps_.host_resolver.reset(new MockCachingHostResolver()); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12775 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | b9ec688 | 2011-07-01 07:40:26 | [diff] [blame] | 12776 | SpdySessionPoolPeer pool_peer(session->spdy_session_pool()); |
| 12777 | pool_peer.DisableDomainAuthenticationVerification(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12778 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12779 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 12780 | ssl.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12781 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12782 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12783 | scoped_ptr<SpdyFrame> host1_req( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12784 | spdy_util_.ConstructSpdyGet("https://www.example.org", false, 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 12785 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12786 | scoped_ptr<SpdyFrame> host2_req( |
| 12787 | spdy_util_.ConstructSpdyGet("https://www.gmail.com", false, 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12788 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12789 | CreateMockWrite(*host1_req, 0), CreateMockWrite(*host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12790 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12791 | scoped_ptr<SpdyFrame> host1_resp( |
| 12792 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12793 | scoped_ptr<SpdyFrame> host1_resp_body( |
| 12794 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 12795 | scoped_ptr<SpdyFrame> host2_resp( |
| 12796 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 12797 | scoped_ptr<SpdyFrame> host2_resp_body( |
| 12798 | spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12799 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12800 | CreateMockRead(*host1_resp, 1), |
| 12801 | CreateMockRead(*host1_resp_body, 2), |
| 12802 | CreateMockRead(*host2_resp, 4), |
| 12803 | CreateMockRead(*host2_resp_body, 5), |
| 12804 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12805 | }; |
| 12806 | |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12807 | IPAddressNumber ip; |
| 12808 | ASSERT_TRUE(ParseIPLiteralToNumber("127.0.0.1", &ip)); |
| 12809 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 12810 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12811 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 12812 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12813 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12814 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 12815 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12816 | HttpRequestInfo request1; |
| 12817 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12818 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12819 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12820 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12821 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12822 | int rv = trans1.Start(&request1, callback.callback(), BoundNetLog()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12823 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12824 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12825 | |
| 12826 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 12827 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12828 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12829 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12830 | |
| 12831 | std::string response_data; |
| 12832 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); |
| 12833 | EXPECT_EQ("hello!", response_data); |
| 12834 | |
| 12835 | // Preload www.gmail.com into HostCache. |
| 12836 | HostPortPair host_port("www.gmail.com", 443); |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 12837 | HostResolver::RequestInfo resolve_info(host_port); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12838 | AddressList ignored; |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 12839 | rv = session_deps_.host_resolver->Resolve(resolve_info, |
| 12840 | DEFAULT_PRIORITY, |
| 12841 | &ignored, |
| 12842 | callback.callback(), |
| 12843 | NULL, |
| 12844 | BoundNetLog()); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 12845 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12846 | rv = callback.WaitForResult(); |
| 12847 | EXPECT_EQ(OK, rv); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12848 | |
| 12849 | HttpRequestInfo request2; |
| 12850 | request2.method = "GET"; |
| 12851 | request2.url = GURL("https://www.gmail.com/"); |
| 12852 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12853 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12854 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12855 | rv = trans2.Start(&request2, callback.callback(), BoundNetLog()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12856 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12857 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12858 | |
| 12859 | response = trans2.GetResponseInfo(); |
| 12860 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12861 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12862 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12863 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 12864 | EXPECT_TRUE(response->was_npn_negotiated); |
| 12865 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 12866 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12867 | } |
| 12868 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12869 | TEST_P(HttpNetworkTransactionTest, UseIPConnectionPoolingAfterResolution) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12870 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 12871 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12872 | |
| 12873 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12874 | session_deps_.host_resolver.reset(new MockCachingHostResolver()); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12875 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12876 | SpdySessionPoolPeer pool_peer(session->spdy_session_pool()); |
| 12877 | pool_peer.DisableDomainAuthenticationVerification(); |
| 12878 | |
| 12879 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 12880 | ssl.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12881 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12882 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12883 | scoped_ptr<SpdyFrame> host1_req( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12884 | spdy_util_.ConstructSpdyGet("https://www.example.org", false, 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 12885 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12886 | scoped_ptr<SpdyFrame> host2_req( |
| 12887 | spdy_util_.ConstructSpdyGet("https://www.gmail.com", false, 3, LOWEST)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12888 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12889 | CreateMockWrite(*host1_req, 0), CreateMockWrite(*host2_req, 3), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12890 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12891 | scoped_ptr<SpdyFrame> host1_resp( |
| 12892 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12893 | scoped_ptr<SpdyFrame> host1_resp_body( |
| 12894 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 12895 | scoped_ptr<SpdyFrame> host2_resp( |
| 12896 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 12897 | scoped_ptr<SpdyFrame> host2_resp_body( |
| 12898 | spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12899 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12900 | CreateMockRead(*host1_resp, 1), |
| 12901 | CreateMockRead(*host1_resp_body, 2), |
| 12902 | CreateMockRead(*host2_resp, 4), |
| 12903 | CreateMockRead(*host2_resp_body, 5), |
| 12904 | MockRead(ASYNC, 0, 6), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12905 | }; |
| 12906 | |
| 12907 | IPAddressNumber ip; |
| 12908 | ASSERT_TRUE(ParseIPLiteralToNumber("127.0.0.1", &ip)); |
| 12909 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 12910 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12911 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 12912 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12913 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12914 | |
| 12915 | TestCompletionCallback callback; |
| 12916 | HttpRequestInfo request1; |
| 12917 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12918 | request1.url = GURL("https://www.example.org/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12919 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12920 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12921 | |
| 12922 | int rv = trans1.Start(&request1, callback.callback(), BoundNetLog()); |
| 12923 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12924 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 12925 | |
| 12926 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 12927 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12928 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12929 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12930 | |
| 12931 | std::string response_data; |
| 12932 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); |
| 12933 | EXPECT_EQ("hello!", response_data); |
| 12934 | |
| 12935 | HttpRequestInfo request2; |
| 12936 | request2.method = "GET"; |
| 12937 | request2.url = GURL("https://www.gmail.com/"); |
| 12938 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12939 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12940 | |
| 12941 | rv = trans2.Start(&request2, callback.callback(), BoundNetLog()); |
| 12942 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12943 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 12944 | |
| 12945 | response = trans2.GetResponseInfo(); |
| 12946 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12947 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12948 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12949 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 12950 | EXPECT_TRUE(response->was_npn_negotiated); |
| 12951 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 12952 | EXPECT_EQ("hello!", response_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12953 | } |
| 12954 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12955 | class OneTimeCachingHostResolver : public HostResolver { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12956 | public: |
| 12957 | explicit OneTimeCachingHostResolver(const HostPortPair& host_port) |
| 12958 | : host_port_(host_port) {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12959 | ~OneTimeCachingHostResolver() override {} |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12960 | |
| 12961 | RuleBasedHostResolverProc* rules() { return host_resolver_.rules(); } |
| 12962 | |
| 12963 | // HostResolver methods: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12964 | int Resolve(const RequestInfo& info, |
| 12965 | RequestPriority priority, |
| 12966 | AddressList* addresses, |
| 12967 | const CompletionCallback& callback, |
| 12968 | RequestHandle* out_req, |
| 12969 | const BoundNetLog& net_log) override { |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 12970 | return host_resolver_.Resolve( |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 12971 | info, priority, addresses, callback, out_req, net_log); |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 12972 | } |
| 12973 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12974 | int ResolveFromCache(const RequestInfo& info, |
| 12975 | AddressList* addresses, |
| 12976 | const BoundNetLog& net_log) override { |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 12977 | int rv = host_resolver_.ResolveFromCache(info, addresses, net_log); |
| 12978 | if (rv == OK && info.host_port_pair().Equals(host_port_)) |
[email protected] | 98e1cd01 | 2011-11-08 15:33:09 | [diff] [blame] | 12979 | host_resolver_.GetHostCache()->clear(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12980 | return rv; |
| 12981 | } |
| 12982 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12983 | void CancelRequest(RequestHandle req) override { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12984 | host_resolver_.CancelRequest(req); |
| 12985 | } |
| 12986 | |
[email protected] | 46da33be | 2011-07-19 21:58:04 | [diff] [blame] | 12987 | MockCachingHostResolver* GetMockHostResolver() { |
| 12988 | return &host_resolver_; |
| 12989 | } |
| 12990 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12991 | private: |
| 12992 | MockCachingHostResolver host_resolver_; |
| 12993 | const HostPortPair host_port_; |
| 12994 | }; |
| 12995 | |
mmenke | 5c64213 | 2015-06-02 16:05:13 | [diff] [blame] | 12996 | TEST_P(HttpNetworkTransactionTest, |
| 12997 | UseIPConnectionPoolingWithHostCacheExpiration) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12998 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 12999 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13000 | |
| 13001 | // Set up a special HttpNetworkSession with a OneTimeCachingHostResolver. |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13002 | OneTimeCachingHostResolver host_resolver(HostPortPair("www.gmail.com", 443)); |
[email protected] | c6bf815 | 2012-12-02 07:43:34 | [diff] [blame] | 13003 | HttpNetworkSession::Params params = |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13004 | SpdySessionDependencies::CreateSessionParams(&session_deps_); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13005 | params.host_resolver = &host_resolver; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 13006 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | b9ec688 | 2011-07-01 07:40:26 | [diff] [blame] | 13007 | SpdySessionPoolPeer pool_peer(session->spdy_session_pool()); |
| 13008 | pool_peer.DisableDomainAuthenticationVerification(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13009 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13010 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13011 | ssl.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13012 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13013 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 13014 | scoped_ptr<SpdyFrame> host1_req( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13015 | spdy_util_.ConstructSpdyGet("https://www.example.org", false, 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13016 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 13017 | scoped_ptr<SpdyFrame> host2_req( |
| 13018 | spdy_util_.ConstructSpdyGet("https://www.gmail.com", false, 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13019 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13020 | CreateMockWrite(*host1_req, 0), CreateMockWrite(*host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13021 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13022 | scoped_ptr<SpdyFrame> host1_resp( |
| 13023 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 13024 | scoped_ptr<SpdyFrame> host1_resp_body( |
| 13025 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 13026 | scoped_ptr<SpdyFrame> host2_resp( |
| 13027 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 13028 | scoped_ptr<SpdyFrame> host2_resp_body( |
| 13029 | spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13030 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13031 | CreateMockRead(*host1_resp, 1), |
| 13032 | CreateMockRead(*host1_resp_body, 2), |
| 13033 | CreateMockRead(*host2_resp, 4), |
| 13034 | CreateMockRead(*host2_resp_body, 5), |
| 13035 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13036 | }; |
| 13037 | |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13038 | IPAddressNumber ip; |
| 13039 | ASSERT_TRUE(ParseIPLiteralToNumber("127.0.0.1", &ip)); |
| 13040 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 13041 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13042 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 13043 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13044 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13045 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 13046 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13047 | HttpRequestInfo request1; |
| 13048 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13049 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13050 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13051 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13052 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13053 | int rv = trans1.Start(&request1, callback.callback(), BoundNetLog()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13054 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13055 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13056 | |
| 13057 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 13058 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13059 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13060 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13061 | |
| 13062 | std::string response_data; |
| 13063 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); |
| 13064 | EXPECT_EQ("hello!", response_data); |
| 13065 | |
| 13066 | // Preload cache entries into HostCache. |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 13067 | HostResolver::RequestInfo resolve_info(HostPortPair("www.gmail.com", 443)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13068 | AddressList ignored; |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 13069 | rv = host_resolver.Resolve(resolve_info, |
| 13070 | DEFAULT_PRIORITY, |
| 13071 | &ignored, |
| 13072 | callback.callback(), |
| 13073 | NULL, |
| 13074 | BoundNetLog()); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 13075 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13076 | rv = callback.WaitForResult(); |
| 13077 | EXPECT_EQ(OK, rv); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13078 | |
| 13079 | HttpRequestInfo request2; |
| 13080 | request2.method = "GET"; |
| 13081 | request2.url = GURL("https://www.gmail.com/"); |
| 13082 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13083 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13084 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13085 | rv = trans2.Start(&request2, callback.callback(), BoundNetLog()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13086 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13087 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13088 | |
| 13089 | response = trans2.GetResponseInfo(); |
| 13090 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13091 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13092 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13093 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 13094 | EXPECT_TRUE(response->was_npn_negotiated); |
| 13095 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 13096 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13097 | } |
| 13098 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13099 | TEST_P(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttp) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13100 | const std::string https_url = "https://www.example.org:8080/"; |
| 13101 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13102 | |
| 13103 | // SPDY GET for HTTPS URL |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 13104 | scoped_ptr<SpdyFrame> req1( |
| 13105 | spdy_util_.ConstructSpdyGet(https_url.c_str(), false, 1, LOWEST)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13106 | |
| 13107 | MockWrite writes1[] = { |
| 13108 | CreateMockWrite(*req1, 0), |
| 13109 | }; |
| 13110 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13111 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 13112 | scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 13113 | MockRead reads1[] = {CreateMockRead(*resp1, 1), CreateMockRead(*body1, 2), |
| 13114 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3)}; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13115 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13116 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 13117 | arraysize(writes1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13118 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 13119 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13120 | |
| 13121 | // HTTP GET for the HTTP URL |
| 13122 | MockWrite writes2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13123 | MockWrite(ASYNC, 0, |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 13124 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13125 | "Host: www.example.org:8080\r\n" |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 13126 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13127 | }; |
| 13128 | |
| 13129 | MockRead reads2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13130 | MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 13131 | MockRead(ASYNC, 2, "hello"), |
| 13132 | MockRead(ASYNC, OK, 3), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13133 | }; |
| 13134 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13135 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 13136 | arraysize(writes2)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13137 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13138 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13139 | ssl.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13140 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13141 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 13142 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13143 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 13144 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13145 | |
| 13146 | // Start the first transaction to set up the SpdySession |
| 13147 | HttpRequestInfo request1; |
| 13148 | request1.method = "GET"; |
| 13149 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13150 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13151 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13152 | TestCompletionCallback callback1; |
| 13153 | EXPECT_EQ(ERR_IO_PENDING, |
| 13154 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 13155 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13156 | |
| 13157 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 13158 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 13159 | |
| 13160 | // Now, start the HTTP request |
| 13161 | HttpRequestInfo request2; |
| 13162 | request2.method = "GET"; |
| 13163 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13164 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13165 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13166 | TestCompletionCallback callback2; |
| 13167 | EXPECT_EQ(ERR_IO_PENDING, |
| 13168 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 13169 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13170 | |
| 13171 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 13172 | EXPECT_FALSE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 13173 | } |
| 13174 | |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 13175 | class AltSvcCertificateVerificationTest : public HttpNetworkTransactionTest { |
| 13176 | public: |
| 13177 | void Run(bool pooling, bool valid) { |
| 13178 | HostPortPair origin(valid ? "mail.example.org" : "invalid.example.org", |
| 13179 | 443); |
| 13180 | HostPortPair alternative("www.example.org", 443); |
| 13181 | |
| 13182 | base::FilePath certs_dir = GetTestCertsDirectory(); |
| 13183 | scoped_refptr<X509Certificate> cert( |
| 13184 | ImportCertFromFile(certs_dir, "spdy_pooling.pem")); |
| 13185 | ASSERT_TRUE(cert.get()); |
| 13186 | bool common_name_fallback_used; |
| 13187 | EXPECT_EQ(valid, |
| 13188 | cert->VerifyNameMatch(origin.host(), &common_name_fallback_used)); |
| 13189 | EXPECT_TRUE( |
| 13190 | cert->VerifyNameMatch(alternative.host(), &common_name_fallback_used)); |
| 13191 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13192 | ssl.SetNextProto(GetProtocol()); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 13193 | ssl.cert = cert; |
| 13194 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13195 | |
| 13196 | // If pooling, then start a request to alternative first to create a |
| 13197 | // SpdySession. |
| 13198 | std::string url0 = "https://www.example.org:443"; |
| 13199 | // Second request to origin, which has an alternative service, and could |
| 13200 | // open a connection to the alternative host or pool to the existing one. |
| 13201 | std::string url1("https://"); |
| 13202 | url1.append(origin.host()); |
| 13203 | url1.append(":443"); |
| 13204 | |
| 13205 | scoped_ptr<SpdyFrame> req0; |
| 13206 | scoped_ptr<SpdyFrame> req1; |
| 13207 | scoped_ptr<SpdyFrame> resp0; |
| 13208 | scoped_ptr<SpdyFrame> body0; |
| 13209 | scoped_ptr<SpdyFrame> resp1; |
| 13210 | scoped_ptr<SpdyFrame> body1; |
| 13211 | std::vector<MockWrite> writes; |
| 13212 | std::vector<MockRead> reads; |
| 13213 | |
| 13214 | if (pooling) { |
| 13215 | req0.reset(spdy_util_.ConstructSpdyGet(url0.c_str(), false, 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13216 | spdy_util_.UpdateWithStreamDestruction(1); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 13217 | req1.reset(spdy_util_.ConstructSpdyGet(url1.c_str(), false, 3, LOWEST)); |
| 13218 | |
| 13219 | writes.push_back(CreateMockWrite(*req0, 0)); |
| 13220 | writes.push_back(CreateMockWrite(*req1, 3)); |
| 13221 | |
| 13222 | resp0.reset(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 13223 | body0.reset(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 13224 | resp1.reset(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 13225 | body1.reset(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
| 13226 | |
| 13227 | reads.push_back(CreateMockRead(*resp0, 1)); |
| 13228 | reads.push_back(CreateMockRead(*body0, 2)); |
| 13229 | reads.push_back(MockRead(ASYNC, ERR_IO_PENDING, 4)); |
| 13230 | reads.push_back(CreateMockRead(*resp1, 5)); |
| 13231 | reads.push_back(CreateMockRead(*body1, 6)); |
| 13232 | reads.push_back(MockRead(ASYNC, OK, 7)); |
| 13233 | } else { |
| 13234 | req1.reset(spdy_util_.ConstructSpdyGet(url1.c_str(), false, 1, LOWEST)); |
| 13235 | |
| 13236 | writes.push_back(CreateMockWrite(*req1, 0)); |
| 13237 | |
| 13238 | resp1.reset(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 13239 | body1.reset(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 13240 | |
| 13241 | reads.push_back(CreateMockRead(*resp1, 1)); |
| 13242 | reads.push_back(CreateMockRead(*body1, 2)); |
| 13243 | reads.push_back(MockRead(ASYNC, OK, 3)); |
| 13244 | } |
| 13245 | |
davidben | 5f8b6bc | 2015-11-25 03:19:54 | [diff] [blame] | 13246 | SequencedSocketData data(reads.data(), reads.size(), writes.data(), |
| 13247 | writes.size()); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 13248 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13249 | |
| 13250 | // Connection to the origin fails. |
| 13251 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 13252 | StaticSocketDataProvider data_refused; |
| 13253 | data_refused.set_connect_data(mock_connect); |
| 13254 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 13255 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 13256 | session_deps_.use_alternative_services = true; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 13257 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 13258 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 13259 | session->http_server_properties(); |
| 13260 | AlternativeService alternative_service( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13261 | AlternateProtocolFromNextProto(GetProtocol()), alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 13262 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 13263 | http_server_properties->SetAlternativeService(origin, alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 13264 | 1.0, expiration); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 13265 | |
| 13266 | // First request to alternative. |
| 13267 | if (pooling) { |
| 13268 | scoped_ptr<HttpTransaction> trans0( |
| 13269 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 13270 | HttpRequestInfo request0; |
| 13271 | request0.method = "GET"; |
| 13272 | request0.url = GURL(url0); |
| 13273 | request0.load_flags = 0; |
| 13274 | TestCompletionCallback callback0; |
| 13275 | |
| 13276 | int rv = trans0->Start(&request0, callback0.callback(), BoundNetLog()); |
| 13277 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13278 | rv = callback0.WaitForResult(); |
| 13279 | EXPECT_EQ(OK, rv); |
| 13280 | } |
| 13281 | |
| 13282 | // Second request to origin. |
| 13283 | scoped_ptr<HttpTransaction> trans1( |
| 13284 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 13285 | HttpRequestInfo request1; |
| 13286 | request1.method = "GET"; |
| 13287 | request1.url = GURL(url1); |
| 13288 | request1.load_flags = 0; |
| 13289 | TestCompletionCallback callback1; |
| 13290 | |
| 13291 | int rv = trans1->Start(&request1, callback1.callback(), BoundNetLog()); |
| 13292 | EXPECT_EQ(ERR_IO_PENDING, rv); |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 13293 | base::MessageLoop::current()->RunUntilIdle(); |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 13294 | if (data.IsPaused()) |
| 13295 | data.Resume(); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 13296 | rv = callback1.WaitForResult(); |
| 13297 | if (valid) { |
| 13298 | EXPECT_EQ(OK, rv); |
| 13299 | } else { |
| 13300 | if (pooling) { |
| 13301 | EXPECT_EQ(ERR_CONNECTION_REFUSED, rv); |
| 13302 | } else { |
| 13303 | EXPECT_EQ(ERR_ALTERNATIVE_CERT_NOT_VALID_FOR_ORIGIN, rv); |
| 13304 | } |
| 13305 | } |
| 13306 | } |
| 13307 | }; |
| 13308 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13309 | INSTANTIATE_TEST_CASE_P(ProtoPlusDepend, |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 13310 | AltSvcCertificateVerificationTest, |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13311 | testing::Values(kTestCaseSPDY31, |
| 13312 | kTestCaseHTTP2NoPriorityDependencies, |
| 13313 | kTestCaseHTTP2PriorityDependencies)); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 13314 | |
| 13315 | // The alternative service host must exhibit a certificate that is valid for the |
| 13316 | // origin host. Test that this is enforced when pooling to an existing |
| 13317 | // connection. |
| 13318 | TEST_P(AltSvcCertificateVerificationTest, PoolingValid) { |
| 13319 | Run(true, true); |
| 13320 | } |
| 13321 | |
| 13322 | TEST_P(AltSvcCertificateVerificationTest, PoolingInvalid) { |
| 13323 | Run(true, false); |
| 13324 | } |
| 13325 | |
| 13326 | // The alternative service host must exhibit a certificate that is valid for the |
| 13327 | // origin host. Test that this is enforced when opening a new connection. |
| 13328 | TEST_P(AltSvcCertificateVerificationTest, NewConnectionValid) { |
| 13329 | Run(false, true); |
| 13330 | } |
| 13331 | |
| 13332 | TEST_P(AltSvcCertificateVerificationTest, NewConnectionInvalid) { |
| 13333 | Run(false, false); |
| 13334 | } |
| 13335 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13336 | // Alternative service requires HTTP/2 (or SPDY), but HTTP/1.1 is negotiated |
| 13337 | // with the alternative server. That connection should not be used. |
| 13338 | TEST_P(HttpNetworkTransactionTest, AlternativeServiceNotOnHttp11) { |
| 13339 | HostPortPair origin("origin.example.org", 443); |
| 13340 | HostPortPair alternative("alternative.example.org", 443); |
| 13341 | |
| 13342 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 13343 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 13344 | ssl.SetNextProto(kProtoHTTP11); |
| 13345 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13346 | |
| 13347 | // No data should be read from the alternative, because HTTP/1.1 is |
| 13348 | // negotiated. |
| 13349 | StaticSocketDataProvider data; |
| 13350 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13351 | |
| 13352 | // This test documents that an alternate Job should not be used if HTTP/1.1 is |
| 13353 | // negotiated. In order to test this, a failed connection to the origin is |
| 13354 | // mocked. This way the request relies on the alternate Job. |
| 13355 | StaticSocketDataProvider data_refused; |
| 13356 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 13357 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 13358 | |
| 13359 | // Set up alternative service for origin. |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 13360 | session_deps_.use_alternative_services = true; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 13361 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13362 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 13363 | session->http_server_properties(); |
| 13364 | AlternativeService alternative_service( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13365 | AlternateProtocolFromNextProto(GetProtocol()), alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 13366 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13367 | http_server_properties->SetAlternativeService(origin, alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 13368 | 1.0, expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13369 | |
| 13370 | scoped_ptr<HttpTransaction> trans( |
| 13371 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 13372 | HttpRequestInfo request; |
| 13373 | request.method = "GET"; |
| 13374 | request.url = GURL("https://origin.example.org:443"); |
| 13375 | request.load_flags = 0; |
| 13376 | TestCompletionCallback callback; |
| 13377 | |
| 13378 | // HTTP/2 (or SPDY) is required for alternative service, if HTTP/1.1 is |
| 13379 | // negotiated, the alternate Job should fail with ERR_NPN_NEGOTIATION_FAILED. |
| 13380 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13381 | EXPECT_EQ(ERR_NPN_NEGOTIATION_FAILED, callback.GetResult(rv)); |
| 13382 | } |
| 13383 | |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13384 | // A request to a server with an alternative service fires two Jobs: one to the |
| 13385 | // origin, and an alternate one to the alternative server. If the former |
| 13386 | // succeeds, the request should succeed, even if the latter fails because |
| 13387 | // HTTP/1.1 is negotiated which is insufficient for alternative service. |
| 13388 | TEST_P(HttpNetworkTransactionTest, FailedAlternativeServiceIsNotUserVisible) { |
| 13389 | HostPortPair origin("origin.example.org", 443); |
| 13390 | HostPortPair alternative("alternative.example.org", 443); |
| 13391 | |
| 13392 | // Negotiate HTTP/1.1 with alternative. |
| 13393 | SSLSocketDataProvider alternative_ssl(ASYNC, OK); |
| 13394 | alternative_ssl.SetNextProto(kProtoHTTP11); |
| 13395 | session_deps_.socket_factory->AddSSLSocketDataProvider(&alternative_ssl); |
| 13396 | |
| 13397 | // No data should be read from the alternative, because HTTP/1.1 is |
| 13398 | // negotiated. |
| 13399 | StaticSocketDataProvider data; |
| 13400 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13401 | |
| 13402 | // Negotiate HTTP/1.1 with origin. |
| 13403 | SSLSocketDataProvider origin_ssl(ASYNC, OK); |
| 13404 | origin_ssl.SetNextProto(kProtoHTTP11); |
| 13405 | session_deps_.socket_factory->AddSSLSocketDataProvider(&origin_ssl); |
| 13406 | |
| 13407 | MockWrite http_writes[] = { |
| 13408 | MockWrite( |
| 13409 | "GET / HTTP/1.1\r\n" |
| 13410 | "Host: origin.example.org\r\n" |
| 13411 | "Connection: keep-alive\r\n\r\n"), |
| 13412 | MockWrite( |
| 13413 | "GET /second HTTP/1.1\r\n" |
| 13414 | "Host: origin.example.org\r\n" |
| 13415 | "Connection: keep-alive\r\n\r\n"), |
| 13416 | }; |
| 13417 | |
| 13418 | MockRead http_reads[] = { |
| 13419 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13420 | MockRead("Content-Type: text/html\r\n"), |
| 13421 | MockRead("Content-Length: 6\r\n\r\n"), |
| 13422 | MockRead("foobar"), |
| 13423 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13424 | MockRead("Content-Type: text/html\r\n"), |
| 13425 | MockRead("Content-Length: 7\r\n\r\n"), |
| 13426 | MockRead("another"), |
| 13427 | }; |
| 13428 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 13429 | http_writes, arraysize(http_writes)); |
| 13430 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 13431 | |
| 13432 | // Set up alternative service for origin. |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 13433 | session_deps_.use_alternative_services = true; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 13434 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13435 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 13436 | session->http_server_properties(); |
| 13437 | AlternativeService alternative_service( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13438 | AlternateProtocolFromNextProto(GetProtocol()), alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 13439 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13440 | http_server_properties->SetAlternativeService(origin, alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 13441 | 1.0, expiration); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13442 | |
| 13443 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 13444 | HttpRequestInfo request1; |
| 13445 | request1.method = "GET"; |
| 13446 | request1.url = GURL("https://origin.example.org:443"); |
| 13447 | request1.load_flags = 0; |
| 13448 | TestCompletionCallback callback1; |
| 13449 | |
| 13450 | int rv = trans1.Start(&request1, callback1.callback(), BoundNetLog()); |
| 13451 | rv = callback1.GetResult(rv); |
| 13452 | EXPECT_EQ(OK, rv); |
| 13453 | |
| 13454 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
| 13455 | ASSERT_TRUE(response1 != nullptr); |
| 13456 | ASSERT_TRUE(response1->headers.get() != nullptr); |
| 13457 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
| 13458 | |
| 13459 | std::string response_data1; |
| 13460 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data1)); |
| 13461 | EXPECT_EQ("foobar", response_data1); |
| 13462 | |
| 13463 | // Alternative should be marked as broken, because HTTP/1.1 is not sufficient |
| 13464 | // for alternative service. |
| 13465 | EXPECT_TRUE( |
| 13466 | http_server_properties->IsAlternativeServiceBroken(alternative_service)); |
| 13467 | |
| 13468 | // Since |alternative_service| is broken, a second transaction to origin |
| 13469 | // should not start an alternate Job. It should pool to existing connection |
| 13470 | // to origin. |
| 13471 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 13472 | HttpRequestInfo request2; |
| 13473 | request2.method = "GET"; |
| 13474 | request2.url = GURL("https://origin.example.org:443/second"); |
| 13475 | request2.load_flags = 0; |
| 13476 | TestCompletionCallback callback2; |
| 13477 | |
| 13478 | rv = trans2.Start(&request2, callback2.callback(), BoundNetLog()); |
| 13479 | rv = callback2.GetResult(rv); |
| 13480 | EXPECT_EQ(OK, rv); |
| 13481 | |
| 13482 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
| 13483 | ASSERT_TRUE(response2 != nullptr); |
| 13484 | ASSERT_TRUE(response2->headers.get() != nullptr); |
| 13485 | EXPECT_EQ("HTTP/1.1 200 OK", response2->headers->GetStatusLine()); |
| 13486 | |
| 13487 | std::string response_data2; |
| 13488 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data2)); |
| 13489 | EXPECT_EQ("another", response_data2); |
| 13490 | } |
| 13491 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13492 | // Alternative service requires HTTP/2 (or SPDY), but there is already a |
| 13493 | // HTTP/1.1 socket open to the alternative server. That socket should not be |
| 13494 | // used. |
| 13495 | TEST_P(HttpNetworkTransactionTest, AlternativeServiceShouldNotPoolToHttp11) { |
| 13496 | HostPortPair origin("origin.example.org", 443); |
| 13497 | HostPortPair alternative("alternative.example.org", 443); |
| 13498 | std::string origin_url = "https://origin.example.org:443"; |
| 13499 | std::string alternative_url = "https://alternative.example.org:443"; |
| 13500 | |
| 13501 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 13502 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 13503 | ssl.SetNextProto(kProtoHTTP11); |
| 13504 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13505 | |
| 13506 | // HTTP/1.1 data for |request1| and |request2|. |
| 13507 | MockWrite http_writes[] = { |
| 13508 | MockWrite( |
| 13509 | "GET / HTTP/1.1\r\n" |
| 13510 | "Host: alternative.example.org\r\n" |
| 13511 | "Connection: keep-alive\r\n\r\n"), |
| 13512 | MockWrite( |
| 13513 | "GET / HTTP/1.1\r\n" |
| 13514 | "Host: alternative.example.org\r\n" |
| 13515 | "Connection: keep-alive\r\n\r\n"), |
| 13516 | }; |
| 13517 | |
| 13518 | MockRead http_reads[] = { |
| 13519 | MockRead( |
| 13520 | "HTTP/1.1 200 OK\r\n" |
| 13521 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13522 | "Content-Length: 40\r\n\r\n" |
| 13523 | "first HTTP/1.1 response from alternative"), |
| 13524 | MockRead( |
| 13525 | "HTTP/1.1 200 OK\r\n" |
| 13526 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13527 | "Content-Length: 41\r\n\r\n" |
| 13528 | "second HTTP/1.1 response from alternative"), |
| 13529 | }; |
| 13530 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 13531 | http_writes, arraysize(http_writes)); |
| 13532 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 13533 | |
| 13534 | // This test documents that an alternate Job should not pool to an already |
| 13535 | // existing HTTP/1.1 connection. In order to test this, a failed connection |
| 13536 | // to the origin is mocked. This way |request2| relies on the alternate Job. |
| 13537 | StaticSocketDataProvider data_refused; |
| 13538 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 13539 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 13540 | |
| 13541 | // Set up alternative service for origin. |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 13542 | session_deps_.use_alternative_services = true; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 13543 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13544 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 13545 | session->http_server_properties(); |
| 13546 | AlternativeService alternative_service( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13547 | AlternateProtocolFromNextProto(GetProtocol()), alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 13548 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13549 | http_server_properties->SetAlternativeService(origin, alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 13550 | 1.0, expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13551 | |
| 13552 | // First transaction to alternative to open an HTTP/1.1 socket. |
| 13553 | scoped_ptr<HttpTransaction> trans1( |
| 13554 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 13555 | HttpRequestInfo request1; |
| 13556 | request1.method = "GET"; |
| 13557 | request1.url = GURL(alternative_url); |
| 13558 | request1.load_flags = 0; |
| 13559 | TestCompletionCallback callback1; |
| 13560 | |
| 13561 | int rv = trans1->Start(&request1, callback1.callback(), BoundNetLog()); |
| 13562 | EXPECT_EQ(OK, callback1.GetResult(rv)); |
| 13563 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 13564 | ASSERT_TRUE(response1); |
| 13565 | ASSERT_TRUE(response1->headers.get()); |
| 13566 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
| 13567 | EXPECT_TRUE(response1->was_npn_negotiated); |
| 13568 | EXPECT_FALSE(response1->was_fetched_via_spdy); |
| 13569 | std::string response_data1; |
| 13570 | ASSERT_EQ(OK, ReadTransaction(trans1.get(), &response_data1)); |
| 13571 | EXPECT_EQ("first HTTP/1.1 response from alternative", response_data1); |
| 13572 | |
| 13573 | // Request for origin.example.org, which has an alternative service. This |
| 13574 | // will start two Jobs: the alternative looks for connections to pool to, |
| 13575 | // finds one which is HTTP/1.1, and should ignore it, and should not try to |
| 13576 | // open other connections to alternative server. The Job to origin fails, so |
| 13577 | // this request fails. |
| 13578 | scoped_ptr<HttpTransaction> trans2( |
| 13579 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 13580 | HttpRequestInfo request2; |
| 13581 | request2.method = "GET"; |
| 13582 | request2.url = GURL(origin_url); |
| 13583 | request2.load_flags = 0; |
| 13584 | TestCompletionCallback callback2; |
| 13585 | |
| 13586 | rv = trans2->Start(&request2, callback2.callback(), BoundNetLog()); |
| 13587 | EXPECT_EQ(ERR_CONNECTION_REFUSED, callback2.GetResult(rv)); |
| 13588 | |
| 13589 | // Another transaction to alternative. This is to test that the HTTP/1.1 |
| 13590 | // socket is still open and in the pool. |
| 13591 | scoped_ptr<HttpTransaction> trans3( |
| 13592 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 13593 | HttpRequestInfo request3; |
| 13594 | request3.method = "GET"; |
| 13595 | request3.url = GURL(alternative_url); |
| 13596 | request3.load_flags = 0; |
| 13597 | TestCompletionCallback callback3; |
| 13598 | |
| 13599 | rv = trans3->Start(&request3, callback3.callback(), BoundNetLog()); |
| 13600 | EXPECT_EQ(OK, callback3.GetResult(rv)); |
| 13601 | const HttpResponseInfo* response3 = trans3->GetResponseInfo(); |
| 13602 | ASSERT_TRUE(response3); |
| 13603 | ASSERT_TRUE(response3->headers.get()); |
| 13604 | EXPECT_EQ("HTTP/1.1 200 OK", response3->headers->GetStatusLine()); |
| 13605 | EXPECT_TRUE(response3->was_npn_negotiated); |
| 13606 | EXPECT_FALSE(response3->was_fetched_via_spdy); |
| 13607 | std::string response_data3; |
| 13608 | ASSERT_EQ(OK, ReadTransaction(trans3.get(), &response_data3)); |
| 13609 | EXPECT_EQ("second HTTP/1.1 response from alternative", response_data3); |
| 13610 | } |
| 13611 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13612 | TEST_P(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttpOverTunnel) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13613 | const std::string https_url = "https://www.example.org:8080/"; |
| 13614 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13615 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13616 | // Separate SPDY util instance for naked and wrapped requests. |
| 13617 | SpdyTestUtil spdy_util_wrapped(GetProtocol(), GetDependenciesFromPriority()); |
| 13618 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13619 | // SPDY GET for HTTPS URL (through CONNECT tunnel) |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13620 | const HostPortPair host_port_pair("www.example.org", 8080); |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 13621 | scoped_ptr<SpdyFrame> connect( |
| 13622 | spdy_util_.ConstructSpdyConnect(NULL, 0, 1, LOWEST, host_port_pair)); |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 13623 | scoped_ptr<SpdyFrame> req1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13624 | spdy_util_wrapped.ConstructSpdyGet(https_url.c_str(), false, 1, LOWEST)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13625 | scoped_ptr<SpdyFrame> wrapped_req1( |
| 13626 | spdy_util_.ConstructWrappedSpdyFrame(req1, 1)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 13627 | |
| 13628 | // SPDY GET for HTTP URL (through the proxy, but not the tunnel). |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 13629 | SpdyHeaderBlock req2_block; |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 13630 | spdy_util_.MaybeAddVersionHeader(&req2_block); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 13631 | req2_block[spdy_util_.GetMethodKey()] = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13632 | req2_block[spdy_util_.GetHostKey()] = "www.example.org:8080"; |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 13633 | req2_block[spdy_util_.GetSchemeKey()] = "http"; |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 13634 | req2_block[spdy_util_.GetPathKey()] = "/"; |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 13635 | scoped_ptr<SpdyFrame> req2( |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 13636 | spdy_util_.ConstructSpdySyn(3, req2_block, MEDIUM, false, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13637 | |
| 13638 | MockWrite writes1[] = { |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13639 | CreateMockWrite(*connect, 0), CreateMockWrite(*wrapped_req1, 2), |
| 13640 | CreateMockWrite(*req2, 6), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13641 | }; |
| 13642 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13643 | scoped_ptr<SpdyFrame> conn_resp( |
| 13644 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 13645 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 13646 | scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 13647 | scoped_ptr<SpdyFrame> wrapped_resp1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13648 | spdy_util_wrapped.ConstructWrappedSpdyFrame(resp1, 1)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13649 | scoped_ptr<SpdyFrame> wrapped_body1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13650 | spdy_util_wrapped.ConstructWrappedSpdyFrame(body1, 1)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13651 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 13652 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13653 | MockRead reads1[] = { |
| 13654 | CreateMockRead(*conn_resp, 1), |
| 13655 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
| 13656 | CreateMockRead(*wrapped_resp1, 4), |
| 13657 | CreateMockRead(*wrapped_body1, 5), |
| 13658 | MockRead(ASYNC, ERR_IO_PENDING, 7), |
| 13659 | CreateMockRead(*resp2, 8), |
| 13660 | CreateMockRead(*body2, 9), |
| 13661 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 10), |
| 13662 | }; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13663 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13664 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 13665 | arraysize(writes1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13666 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 13667 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13668 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 13669 | session_deps_.proxy_service = |
| 13670 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 13671 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13672 | session_deps_.net_log = &log; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13673 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13674 | ssl1.SetNextProto(GetProtocol()); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13675 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13676 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13677 | ssl2.SetNextProto(GetProtocol()); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13678 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 13679 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13680 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13681 | scoped_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13682 | |
| 13683 | // Start the first transaction to set up the SpdySession |
| 13684 | HttpRequestInfo request1; |
| 13685 | request1.method = "GET"; |
| 13686 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13687 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13688 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13689 | TestCompletionCallback callback1; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13690 | int rv = trans1.Start(&request1, callback1.callback(), BoundNetLog()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13691 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13692 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 13693 | data1.RunUntilPaused(); |
| 13694 | base::RunLoop().RunUntilIdle(); |
| 13695 | data1.Resume(); |
| 13696 | EXPECT_EQ(OK, callback1.GetResult(rv)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13697 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 13698 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 13699 | LoadTimingInfo load_timing_info1; |
| 13700 | EXPECT_TRUE(trans1.GetLoadTimingInfo(&load_timing_info1)); |
| 13701 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 13702 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 13703 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13704 | // Now, start the HTTP request. |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13705 | HttpRequestInfo request2; |
| 13706 | request2.method = "GET"; |
| 13707 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13708 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13709 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13710 | TestCompletionCallback callback2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13711 | rv = trans2.Start(&request2, callback2.callback(), BoundNetLog()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13712 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13713 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 13714 | data1.RunUntilPaused(); |
| 13715 | base::RunLoop().RunUntilIdle(); |
| 13716 | data1.Resume(); |
| 13717 | EXPECT_EQ(OK, callback2.GetResult(rv)); |
| 13718 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13719 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 13720 | |
| 13721 | LoadTimingInfo load_timing_info2; |
| 13722 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
| 13723 | // The established SPDY sessions is considered reused by the HTTP request. |
| 13724 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 13725 | // HTTP requests over a SPDY session should have a different connection |
| 13726 | // socket_log_id than requests over a tunnel. |
| 13727 | 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] | 13728 | } |
| 13729 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13730 | // Test that in the case where we have a SPDY session to a SPDY proxy |
| 13731 | // that we do not pool other origins that resolve to the same IP when |
| 13732 | // the certificate does not match the new origin. |
| 13733 | // http://crbug.com/134690 |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13734 | TEST_P(HttpNetworkTransactionTest, DoNotUseSpdySessionIfCertDoesNotMatch) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13735 | const std::string url1 = "http://www.example.org/"; |
| 13736 | const std::string url2 = "https://news.example.org/"; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13737 | const std::string ip_addr = "1.2.3.4"; |
| 13738 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13739 | // Second SpdyTestUtil instance for the second socket. |
| 13740 | SpdyTestUtil spdy_util_secure(GetProtocol(), GetDependenciesFromPriority()); |
| 13741 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13742 | // SPDY GET for HTTP URL (through SPDY proxy) |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13743 | scoped_ptr<SpdyHeaderBlock> headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13744 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 13745 | scoped_ptr<SpdyFrame> req1( |
| 13746 | spdy_util_.ConstructSpdySyn(1, *headers, LOWEST, false, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13747 | |
| 13748 | MockWrite writes1[] = { |
| 13749 | CreateMockWrite(*req1, 0), |
| 13750 | }; |
| 13751 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13752 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 13753 | scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13754 | MockRead reads1[] = { |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13755 | MockRead(ASYNC, ERR_IO_PENDING, 1), CreateMockRead(*resp1, 2), |
| 13756 | CreateMockRead(*body1, 3), MockRead(ASYNC, OK, 4), // EOF |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13757 | }; |
| 13758 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13759 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 13760 | arraysize(writes1)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13761 | IPAddressNumber ip; |
| 13762 | ASSERT_TRUE(ParseIPLiteralToNumber(ip_addr, &ip)); |
| 13763 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 13764 | MockConnect connect_data1(ASYNC, OK, peer_addr); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13765 | data1.set_connect_data(connect_data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13766 | |
| 13767 | // SPDY GET for HTTPS URL (direct) |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 13768 | scoped_ptr<SpdyFrame> req2( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13769 | spdy_util_secure.ConstructSpdyGet(url2.c_str(), false, 1, MEDIUM)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13770 | |
| 13771 | MockWrite writes2[] = { |
| 13772 | CreateMockWrite(*req2, 0), |
| 13773 | }; |
| 13774 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13775 | scoped_ptr<SpdyFrame> resp2( |
| 13776 | spdy_util_secure.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 13777 | scoped_ptr<SpdyFrame> body2(spdy_util_secure.ConstructSpdyBodyFrame(1, true)); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13778 | MockRead reads2[] = {CreateMockRead(*resp2, 1), CreateMockRead(*body2, 2), |
| 13779 | MockRead(ASYNC, OK, 3)}; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13780 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13781 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 13782 | arraysize(writes2)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13783 | MockConnect connect_data2(ASYNC, OK); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13784 | data2.set_connect_data(connect_data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13785 | |
| 13786 | // Set up a proxy config that sends HTTP requests to a proxy, and |
| 13787 | // all others direct. |
| 13788 | ProxyConfig proxy_config; |
| 13789 | proxy_config.proxy_rules().ParseFromString("http=https://proxy:443"); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13790 | session_deps_.proxy_service.reset(new ProxyService( |
csharrison | b7e3a08 | 2015-09-22 19:13:04 | [diff] [blame] | 13791 | make_scoped_ptr(new ProxyConfigServiceFixed(proxy_config)), nullptr, |
| 13792 | NULL)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13793 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13794 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13795 | ssl1.SetNextProto(GetProtocol()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13796 | // Load a valid cert. Note, that this does not need to |
| 13797 | // be valid for proxy because the MockSSLClientSocket does |
| 13798 | // not actually verify it. But SpdySession will use this |
| 13799 | // to see if it is valid for the new origin |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13800 | ssl1.cert = ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem"); |
| 13801 | ASSERT_TRUE(ssl1.cert.get()); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13802 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 13803 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13804 | |
| 13805 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13806 | ssl2.SetNextProto(GetProtocol()); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13807 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 13808 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13809 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13810 | session_deps_.host_resolver.reset(new MockCachingHostResolver()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13811 | session_deps_.host_resolver->rules()->AddRule("news.example.org", ip_addr); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13812 | session_deps_.host_resolver->rules()->AddRule("proxy", ip_addr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13813 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13814 | scoped_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13815 | |
| 13816 | // Start the first transaction to set up the SpdySession |
| 13817 | HttpRequestInfo request1; |
| 13818 | request1.method = "GET"; |
| 13819 | request1.url = GURL(url1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13820 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13821 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13822 | TestCompletionCallback callback1; |
| 13823 | ASSERT_EQ(ERR_IO_PENDING, |
| 13824 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 13825 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 13826 | data1.RunUntilPaused(); |
| 13827 | base::RunLoop().RunUntilIdle(); |
| 13828 | data1.Resume(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13829 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13830 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 13831 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 13832 | |
| 13833 | // Now, start the HTTP request |
| 13834 | HttpRequestInfo request2; |
| 13835 | request2.method = "GET"; |
| 13836 | request2.url = GURL(url2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13837 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13838 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13839 | TestCompletionCallback callback2; |
| 13840 | EXPECT_EQ(ERR_IO_PENDING, |
| 13841 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 13842 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13843 | |
| 13844 | ASSERT_TRUE(callback2.have_result()); |
| 13845 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 13846 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 13847 | } |
| 13848 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13849 | // Test to verify that a failed socket read (due to an ERR_CONNECTION_CLOSED |
| 13850 | // error) in SPDY session, removes the socket from pool and closes the SPDY |
| 13851 | // session. Verify that new url's from the same HttpNetworkSession (and a new |
| 13852 | // SpdySession) do work. http://crbug.com/224701 |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13853 | TEST_P(HttpNetworkTransactionTest, ErrorSocketNotConnected) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13854 | const std::string https_url = "https://www.example.org/"; |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13855 | |
| 13856 | MockRead reads1[] = { |
| 13857 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED, 0) |
| 13858 | }; |
| 13859 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 13860 | SequencedSocketData data1(reads1, arraysize(reads1), NULL, 0); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13861 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 13862 | scoped_ptr<SpdyFrame> req2( |
| 13863 | spdy_util_.ConstructSpdyGet(https_url.c_str(), false, 1, MEDIUM)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13864 | MockWrite writes2[] = { |
| 13865 | CreateMockWrite(*req2, 0), |
| 13866 | }; |
| 13867 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13868 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 13869 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13870 | MockRead reads2[] = { |
| 13871 | CreateMockRead(*resp2, 1), |
| 13872 | CreateMockRead(*body2, 2), |
| 13873 | MockRead(ASYNC, OK, 3) // EOF |
| 13874 | }; |
| 13875 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 13876 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 13877 | arraysize(writes2)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13878 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13879 | SSLSocketDataProvider ssl1(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13880 | ssl1.SetNextProto(GetProtocol()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 13881 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 13882 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13883 | |
| 13884 | SSLSocketDataProvider ssl2(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13885 | ssl2.SetNextProto(GetProtocol()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 13886 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 13887 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13888 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 13889 | scoped_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 13890 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13891 | |
| 13892 | // Start the first transaction to set up the SpdySession and verify that |
| 13893 | // connection was closed. |
| 13894 | HttpRequestInfo request1; |
| 13895 | request1.method = "GET"; |
| 13896 | request1.url = GURL(https_url); |
| 13897 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13898 | HttpNetworkTransaction trans1(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13899 | TestCompletionCallback callback1; |
| 13900 | EXPECT_EQ(ERR_IO_PENDING, |
| 13901 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13902 | EXPECT_EQ(ERR_CONNECTION_CLOSED, callback1.WaitForResult()); |
| 13903 | |
| 13904 | // Now, start the second request and make sure it succeeds. |
| 13905 | HttpRequestInfo request2; |
| 13906 | request2.method = "GET"; |
| 13907 | request2.url = GURL(https_url); |
| 13908 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13909 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13910 | TestCompletionCallback callback2; |
| 13911 | EXPECT_EQ(ERR_IO_PENDING, |
| 13912 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13913 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 13914 | ASSERT_EQ(OK, callback2.WaitForResult()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13915 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 13916 | } |
| 13917 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13918 | TEST_P(HttpNetworkTransactionTest, CloseIdleSpdySessionToOpenNewOne) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 13919 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13920 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 13921 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 13922 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 13923 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 13924 | |
| 13925 | // Use two different hosts with different IPs so they don't get pooled. |
| 13926 | session_deps_.host_resolver->rules()->AddRule("www.a.com", "10.0.0.1"); |
| 13927 | session_deps_.host_resolver->rules()->AddRule("www.b.com", "10.0.0.2"); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 13928 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13929 | |
| 13930 | SSLSocketDataProvider ssl1(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13931 | ssl1.SetNextProto(GetProtocol()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13932 | SSLSocketDataProvider ssl2(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13933 | ssl2.SetNextProto(GetProtocol()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13934 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 13935 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 13936 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 13937 | scoped_ptr<SpdyFrame> host1_req(spdy_util_.ConstructSpdyGet( |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13938 | "https://www.a.com", false, 1, DEFAULT_PRIORITY)); |
| 13939 | MockWrite spdy1_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13940 | CreateMockWrite(*host1_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13941 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13942 | scoped_ptr<SpdyFrame> host1_resp( |
| 13943 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 13944 | scoped_ptr<SpdyFrame> host1_resp_body( |
| 13945 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13946 | MockRead spdy1_reads[] = { |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 13947 | CreateMockRead(*host1_resp, 1), CreateMockRead(*host1_resp_body, 2), |
| 13948 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13949 | }; |
| 13950 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13951 | // Use a separate test instance for the separate SpdySession that will be |
| 13952 | // created. |
| 13953 | SpdyTestUtil spdy_util_2(GetProtocol(), GetDependenciesFromPriority()); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13954 | scoped_ptr<SequencedSocketData> spdy1_data( |
| 13955 | new SequencedSocketData(spdy1_reads, arraysize(spdy1_reads), spdy1_writes, |
| 13956 | arraysize(spdy1_writes))); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13957 | session_deps_.socket_factory->AddSocketDataProvider(spdy1_data.get()); |
| 13958 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13959 | scoped_ptr<SpdyFrame> host2_req(spdy_util_2.ConstructSpdyGet( |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13960 | "https://www.b.com", false, 1, DEFAULT_PRIORITY)); |
| 13961 | MockWrite spdy2_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13962 | CreateMockWrite(*host2_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13963 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13964 | scoped_ptr<SpdyFrame> host2_resp( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13965 | spdy_util_2.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13966 | scoped_ptr<SpdyFrame> host2_resp_body( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13967 | spdy_util_2.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13968 | MockRead spdy2_reads[] = { |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 13969 | CreateMockRead(*host2_resp, 1), CreateMockRead(*host2_resp_body, 2), |
| 13970 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13971 | }; |
| 13972 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13973 | scoped_ptr<SequencedSocketData> spdy2_data( |
| 13974 | new SequencedSocketData(spdy2_reads, arraysize(spdy2_reads), spdy2_writes, |
| 13975 | arraysize(spdy2_writes))); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13976 | session_deps_.socket_factory->AddSocketDataProvider(spdy2_data.get()); |
| 13977 | |
| 13978 | MockWrite http_write[] = { |
| 13979 | MockWrite("GET / HTTP/1.1\r\n" |
| 13980 | "Host: www.a.com\r\n" |
| 13981 | "Connection: keep-alive\r\n\r\n"), |
| 13982 | }; |
| 13983 | |
| 13984 | MockRead http_read[] = { |
| 13985 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13986 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 13987 | MockRead("Content-Length: 6\r\n\r\n"), |
| 13988 | MockRead("hello!"), |
| 13989 | }; |
| 13990 | StaticSocketDataProvider http_data(http_read, arraysize(http_read), |
| 13991 | http_write, arraysize(http_write)); |
| 13992 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 13993 | |
| 13994 | HostPortPair host_port_pair_a("www.a.com", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 13995 | SpdySessionKey spdy_session_key_a( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 13996 | host_port_pair_a, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13997 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13998 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13999 | |
| 14000 | TestCompletionCallback callback; |
| 14001 | HttpRequestInfo request1; |
| 14002 | request1.method = "GET"; |
| 14003 | request1.url = GURL("https://www.a.com/"); |
| 14004 | request1.load_flags = 0; |
| 14005 | scoped_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14006 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14007 | |
| 14008 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
| 14009 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14010 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 14011 | |
| 14012 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 14013 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14014 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14015 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14016 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 14017 | EXPECT_TRUE(response->was_npn_negotiated); |
| 14018 | |
| 14019 | std::string response_data; |
| 14020 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 14021 | EXPECT_EQ("hello!", response_data); |
| 14022 | trans.reset(); |
| 14023 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14024 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14025 | |
| 14026 | HostPortPair host_port_pair_b("www.b.com", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 14027 | SpdySessionKey spdy_session_key_b( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 14028 | host_port_pair_b, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14029 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14030 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14031 | HttpRequestInfo request2; |
| 14032 | request2.method = "GET"; |
| 14033 | request2.url = GURL("https://www.b.com/"); |
| 14034 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14035 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14036 | |
| 14037 | rv = trans->Start(&request2, callback.callback(), BoundNetLog()); |
| 14038 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14039 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 14040 | |
| 14041 | response = trans->GetResponseInfo(); |
| 14042 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14043 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14044 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14045 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 14046 | EXPECT_TRUE(response->was_npn_negotiated); |
| 14047 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 14048 | EXPECT_EQ("hello!", response_data); |
| 14049 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14050 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14051 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14052 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14053 | |
| 14054 | HostPortPair host_port_pair_a1("www.a.com", 80); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 14055 | SpdySessionKey spdy_session_key_a1( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 14056 | host_port_pair_a1, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14057 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14058 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a1)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14059 | HttpRequestInfo request3; |
| 14060 | request3.method = "GET"; |
| 14061 | request3.url = GURL("http://www.a.com/"); |
| 14062 | request3.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14063 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14064 | |
| 14065 | rv = trans->Start(&request3, callback.callback(), BoundNetLog()); |
| 14066 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14067 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 14068 | |
| 14069 | response = trans->GetResponseInfo(); |
| 14070 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14071 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14072 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 14073 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 14074 | EXPECT_FALSE(response->was_npn_negotiated); |
| 14075 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 14076 | EXPECT_EQ("hello!", response_data); |
| 14077 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14078 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14079 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14080 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14081 | } |
| 14082 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14083 | TEST_P(HttpNetworkTransactionTest, HttpSyncConnectError) { |
| 14084 | HttpRequestInfo request; |
| 14085 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14086 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14087 | request.load_flags = 0; |
| 14088 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14089 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14090 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14091 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14092 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14093 | MockConnect mock_connect(SYNCHRONOUS, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14094 | StaticSocketDataProvider data; |
| 14095 | data.set_connect_data(mock_connect); |
| 14096 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14097 | |
| 14098 | TestCompletionCallback callback; |
| 14099 | |
| 14100 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14101 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14102 | |
| 14103 | rv = callback.WaitForResult(); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14104 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, rv); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14105 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14106 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 14107 | HttpRequestHeaders request_headers; |
| 14108 | trans->GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 14109 | |
| 14110 | ConnectionAttempts attempts; |
| 14111 | trans->GetConnectionAttempts(&attempts); |
| 14112 | ASSERT_EQ(1u, attempts.size()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14113 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, attempts[0].result); |
| 14114 | |
| 14115 | IPEndPoint endpoint; |
| 14116 | EXPECT_FALSE(trans->GetRemoteEndpoint(&endpoint)); |
| 14117 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14118 | } |
| 14119 | |
| 14120 | TEST_P(HttpNetworkTransactionTest, HttpAsyncConnectError) { |
| 14121 | HttpRequestInfo request; |
| 14122 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14123 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14124 | request.load_flags = 0; |
| 14125 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14126 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14127 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14128 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14129 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14130 | MockConnect mock_connect(ASYNC, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14131 | StaticSocketDataProvider data; |
| 14132 | data.set_connect_data(mock_connect); |
| 14133 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14134 | |
| 14135 | TestCompletionCallback callback; |
| 14136 | |
| 14137 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14138 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14139 | |
| 14140 | rv = callback.WaitForResult(); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14141 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, rv); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14142 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14143 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 14144 | HttpRequestHeaders request_headers; |
| 14145 | trans->GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 14146 | |
| 14147 | ConnectionAttempts attempts; |
| 14148 | trans->GetConnectionAttempts(&attempts); |
| 14149 | ASSERT_EQ(1u, attempts.size()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14150 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, attempts[0].result); |
| 14151 | |
| 14152 | IPEndPoint endpoint; |
| 14153 | EXPECT_FALSE(trans->GetRemoteEndpoint(&endpoint)); |
| 14154 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14155 | } |
| 14156 | |
| 14157 | TEST_P(HttpNetworkTransactionTest, HttpSyncWriteError) { |
| 14158 | HttpRequestInfo request; |
| 14159 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14160 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14161 | request.load_flags = 0; |
| 14162 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14163 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14164 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14165 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14166 | |
| 14167 | MockWrite data_writes[] = { |
| 14168 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14169 | }; |
| 14170 | MockRead data_reads[] = { |
| 14171 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 14172 | }; |
| 14173 | |
| 14174 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 14175 | data_writes, arraysize(data_writes)); |
| 14176 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14177 | |
| 14178 | TestCompletionCallback callback; |
| 14179 | |
| 14180 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14181 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14182 | |
| 14183 | rv = callback.WaitForResult(); |
| 14184 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 14185 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14186 | HttpRequestHeaders request_headers; |
| 14187 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 14188 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 14189 | } |
| 14190 | |
| 14191 | TEST_P(HttpNetworkTransactionTest, HttpAsyncWriteError) { |
| 14192 | HttpRequestInfo request; |
| 14193 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14194 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14195 | request.load_flags = 0; |
| 14196 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14197 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14198 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14199 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14200 | |
| 14201 | MockWrite data_writes[] = { |
| 14202 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
| 14203 | }; |
| 14204 | MockRead data_reads[] = { |
| 14205 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 14206 | }; |
| 14207 | |
| 14208 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 14209 | data_writes, arraysize(data_writes)); |
| 14210 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14211 | |
| 14212 | TestCompletionCallback callback; |
| 14213 | |
| 14214 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14215 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14216 | |
| 14217 | rv = callback.WaitForResult(); |
| 14218 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 14219 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14220 | HttpRequestHeaders request_headers; |
| 14221 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 14222 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 14223 | } |
| 14224 | |
| 14225 | TEST_P(HttpNetworkTransactionTest, HttpSyncReadError) { |
| 14226 | HttpRequestInfo request; |
| 14227 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14228 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14229 | request.load_flags = 0; |
| 14230 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14231 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14232 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14233 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14234 | |
| 14235 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14236 | MockWrite( |
| 14237 | "GET / HTTP/1.1\r\n" |
| 14238 | "Host: www.example.org\r\n" |
| 14239 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14240 | }; |
| 14241 | MockRead data_reads[] = { |
| 14242 | MockRead(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14243 | }; |
| 14244 | |
| 14245 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 14246 | data_writes, arraysize(data_writes)); |
| 14247 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14248 | |
| 14249 | TestCompletionCallback callback; |
| 14250 | |
| 14251 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14252 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14253 | |
| 14254 | rv = callback.WaitForResult(); |
| 14255 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 14256 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14257 | HttpRequestHeaders request_headers; |
| 14258 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 14259 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 14260 | } |
| 14261 | |
| 14262 | TEST_P(HttpNetworkTransactionTest, HttpAsyncReadError) { |
| 14263 | HttpRequestInfo request; |
| 14264 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14265 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14266 | request.load_flags = 0; |
| 14267 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14268 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14269 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14270 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14271 | |
| 14272 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14273 | MockWrite( |
| 14274 | "GET / HTTP/1.1\r\n" |
| 14275 | "Host: www.example.org\r\n" |
| 14276 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14277 | }; |
| 14278 | MockRead data_reads[] = { |
| 14279 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
| 14280 | }; |
| 14281 | |
| 14282 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 14283 | data_writes, arraysize(data_writes)); |
| 14284 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14285 | |
| 14286 | TestCompletionCallback callback; |
| 14287 | |
| 14288 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14289 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14290 | |
| 14291 | rv = callback.WaitForResult(); |
| 14292 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 14293 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14294 | HttpRequestHeaders request_headers; |
| 14295 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 14296 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 14297 | } |
| 14298 | |
| 14299 | TEST_P(HttpNetworkTransactionTest, GetFullRequestHeadersIncludesExtraHeader) { |
| 14300 | HttpRequestInfo request; |
| 14301 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14302 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14303 | request.load_flags = 0; |
| 14304 | request.extra_headers.SetHeader("X-Foo", "bar"); |
| 14305 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14306 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14307 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14308 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14309 | |
| 14310 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14311 | MockWrite( |
| 14312 | "GET / HTTP/1.1\r\n" |
| 14313 | "Host: www.example.org\r\n" |
| 14314 | "Connection: keep-alive\r\n" |
| 14315 | "X-Foo: bar\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14316 | }; |
| 14317 | MockRead data_reads[] = { |
| 14318 | MockRead("HTTP/1.1 200 OK\r\n" |
| 14319 | "Content-Length: 5\r\n\r\n" |
| 14320 | "hello"), |
| 14321 | MockRead(ASYNC, ERR_UNEXPECTED), |
| 14322 | }; |
| 14323 | |
| 14324 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 14325 | data_writes, arraysize(data_writes)); |
| 14326 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14327 | |
| 14328 | TestCompletionCallback callback; |
| 14329 | |
| 14330 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14331 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14332 | |
| 14333 | rv = callback.WaitForResult(); |
| 14334 | EXPECT_EQ(OK, rv); |
| 14335 | |
| 14336 | HttpRequestHeaders request_headers; |
| 14337 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 14338 | std::string foo; |
| 14339 | EXPECT_TRUE(request_headers.GetHeader("X-Foo", &foo)); |
| 14340 | EXPECT_EQ("bar", foo); |
| 14341 | } |
| 14342 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14343 | namespace { |
| 14344 | |
yhirano | a7e05bb | 2014-11-06 05:40:39 | [diff] [blame] | 14345 | // Fake HttpStream that simply records calls to SetPriority(). |
| 14346 | class FakeStream : public HttpStream, |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14347 | public base::SupportsWeakPtr<FakeStream> { |
| 14348 | public: |
| 14349 | explicit FakeStream(RequestPriority priority) : priority_(priority) {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14350 | ~FakeStream() override {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14351 | |
| 14352 | RequestPriority priority() const { return priority_; } |
| 14353 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14354 | int InitializeStream(const HttpRequestInfo* request_info, |
| 14355 | RequestPriority priority, |
| 14356 | const BoundNetLog& net_log, |
| 14357 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14358 | return ERR_IO_PENDING; |
| 14359 | } |
| 14360 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14361 | int SendRequest(const HttpRequestHeaders& request_headers, |
| 14362 | HttpResponseInfo* response, |
| 14363 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14364 | ADD_FAILURE(); |
| 14365 | return ERR_UNEXPECTED; |
| 14366 | } |
| 14367 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14368 | int ReadResponseHeaders(const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14369 | ADD_FAILURE(); |
| 14370 | return ERR_UNEXPECTED; |
| 14371 | } |
| 14372 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14373 | int ReadResponseBody(IOBuffer* buf, |
| 14374 | int buf_len, |
| 14375 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14376 | ADD_FAILURE(); |
| 14377 | return ERR_UNEXPECTED; |
| 14378 | } |
| 14379 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14380 | void Close(bool not_reusable) override {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14381 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14382 | bool IsResponseBodyComplete() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14383 | ADD_FAILURE(); |
| 14384 | return false; |
| 14385 | } |
| 14386 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14387 | bool IsConnectionReused() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14388 | ADD_FAILURE(); |
| 14389 | return false; |
| 14390 | } |
| 14391 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14392 | void SetConnectionReused() override { ADD_FAILURE(); } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14393 | |
mmenke | bd84c39 | 2015-09-02 14:12:34 | [diff] [blame] | 14394 | bool CanReuseConnection() const override { return false; } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14395 | |
sclittle | 4de1bab9 | 2015-09-22 21:28:24 | [diff] [blame] | 14396 | int64_t GetTotalReceivedBytes() const override { |
[email protected] | bc92bc97 | 2013-12-13 08:32:59 | [diff] [blame] | 14397 | ADD_FAILURE(); |
| 14398 | return 0; |
| 14399 | } |
| 14400 | |
sclittle | be1ccf6 | 2015-09-02 19:40:36 | [diff] [blame] | 14401 | int64_t GetTotalSentBytes() const override { |
| 14402 | ADD_FAILURE(); |
| 14403 | return 0; |
| 14404 | } |
| 14405 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14406 | bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14407 | ADD_FAILURE(); |
| 14408 | return false; |
| 14409 | } |
| 14410 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14411 | void GetSSLInfo(SSLInfo* ssl_info) override { ADD_FAILURE(); } |
| 14412 | |
| 14413 | void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14414 | ADD_FAILURE(); |
| 14415 | } |
| 14416 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14417 | bool GetRemoteEndpoint(IPEndPoint* endpoint) override { return false; } |
| 14418 | |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 14419 | Error GetSignedEKMForTokenBinding(crypto::ECPrivateKey* key, |
| 14420 | std::vector<uint8_t>* out) override { |
| 14421 | ADD_FAILURE(); |
| 14422 | return ERR_NOT_IMPLEMENTED; |
| 14423 | } |
| 14424 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14425 | void Drain(HttpNetworkSession* session) override { ADD_FAILURE(); } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14426 | |
zhongyi | ca364fbb | 2015-12-12 03:39:12 | [diff] [blame] | 14427 | void PopulateNetErrorDetails(NetErrorDetails* details) override { return; } |
| 14428 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14429 | void SetPriority(RequestPriority priority) override { priority_ = priority; } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14430 | |
yhirano | a7e05bb | 2014-11-06 05:40:39 | [diff] [blame] | 14431 | UploadProgress GetUploadProgress() const override { return UploadProgress(); } |
| 14432 | |
| 14433 | HttpStream* RenewStreamForAuth() override { return NULL; } |
| 14434 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14435 | private: |
| 14436 | RequestPriority priority_; |
| 14437 | |
| 14438 | DISALLOW_COPY_AND_ASSIGN(FakeStream); |
| 14439 | }; |
| 14440 | |
| 14441 | // Fake HttpStreamRequest that simply records calls to SetPriority() |
| 14442 | // and vends FakeStreams with its current priority. |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14443 | class FakeStreamRequest : public HttpStreamRequest, |
| 14444 | public base::SupportsWeakPtr<FakeStreamRequest> { |
| 14445 | public: |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14446 | FakeStreamRequest(RequestPriority priority, |
| 14447 | HttpStreamRequest::Delegate* delegate) |
| 14448 | : priority_(priority), |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14449 | delegate_(delegate), |
| 14450 | websocket_stream_create_helper_(NULL) {} |
| 14451 | |
| 14452 | FakeStreamRequest(RequestPriority priority, |
| 14453 | HttpStreamRequest::Delegate* delegate, |
| 14454 | WebSocketHandshakeStreamBase::CreateHelper* create_helper) |
| 14455 | : priority_(priority), |
| 14456 | delegate_(delegate), |
| 14457 | websocket_stream_create_helper_(create_helper) {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14458 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14459 | ~FakeStreamRequest() override {} |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14460 | |
| 14461 | RequestPriority priority() const { return priority_; } |
| 14462 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14463 | const WebSocketHandshakeStreamBase::CreateHelper* |
| 14464 | websocket_stream_create_helper() const { |
| 14465 | return websocket_stream_create_helper_; |
| 14466 | } |
| 14467 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14468 | // Create a new FakeStream and pass it to the request's |
| 14469 | // delegate. Returns a weak pointer to the FakeStream. |
| 14470 | base::WeakPtr<FakeStream> FinishStreamRequest() { |
| 14471 | FakeStream* fake_stream = new FakeStream(priority_); |
| 14472 | // Do this before calling OnStreamReady() as OnStreamReady() may |
| 14473 | // immediately delete |fake_stream|. |
| 14474 | base::WeakPtr<FakeStream> weak_stream = fake_stream->AsWeakPtr(); |
| 14475 | delegate_->OnStreamReady(SSLConfig(), ProxyInfo(), fake_stream); |
| 14476 | return weak_stream; |
| 14477 | } |
| 14478 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14479 | int RestartTunnelWithProxyAuth(const AuthCredentials& credentials) override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14480 | ADD_FAILURE(); |
| 14481 | return ERR_UNEXPECTED; |
| 14482 | } |
| 14483 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14484 | LoadState GetLoadState() const override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14485 | ADD_FAILURE(); |
| 14486 | return LoadState(); |
| 14487 | } |
| 14488 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14489 | void SetPriority(RequestPriority priority) override { priority_ = priority; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14490 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14491 | bool was_npn_negotiated() const override { return false; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14492 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14493 | NextProto protocol_negotiated() const override { return kProtoUnknown; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14494 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14495 | bool using_spdy() const override { return false; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14496 | |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 14497 | const ConnectionAttempts& connection_attempts() const override { |
| 14498 | static ConnectionAttempts no_attempts; |
| 14499 | return no_attempts; |
| 14500 | } |
| 14501 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14502 | private: |
| 14503 | RequestPriority priority_; |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14504 | HttpStreamRequest::Delegate* const delegate_; |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14505 | WebSocketHandshakeStreamBase::CreateHelper* websocket_stream_create_helper_; |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14506 | |
| 14507 | DISALLOW_COPY_AND_ASSIGN(FakeStreamRequest); |
| 14508 | }; |
| 14509 | |
| 14510 | // Fake HttpStreamFactory that vends FakeStreamRequests. |
| 14511 | class FakeStreamFactory : public HttpStreamFactory { |
| 14512 | public: |
| 14513 | FakeStreamFactory() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14514 | ~FakeStreamFactory() override {} |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14515 | |
| 14516 | // Returns a WeakPtr<> to the last HttpStreamRequest returned by |
| 14517 | // RequestStream() (which may be NULL if it was destroyed already). |
| 14518 | base::WeakPtr<FakeStreamRequest> last_stream_request() { |
| 14519 | return last_stream_request_; |
| 14520 | } |
| 14521 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14522 | HttpStreamRequest* RequestStream(const HttpRequestInfo& info, |
| 14523 | RequestPriority priority, |
| 14524 | const SSLConfig& server_ssl_config, |
| 14525 | const SSLConfig& proxy_ssl_config, |
| 14526 | HttpStreamRequest::Delegate* delegate, |
| 14527 | const BoundNetLog& net_log) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14528 | FakeStreamRequest* fake_request = new FakeStreamRequest(priority, delegate); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14529 | last_stream_request_ = fake_request->AsWeakPtr(); |
| 14530 | return fake_request; |
| 14531 | } |
| 14532 | |
xunjieli | 11834f0 | 2015-12-22 04:27:08 | [diff] [blame] | 14533 | HttpStreamRequest* RequestBidirectionalStreamJob( |
| 14534 | const HttpRequestInfo& info, |
| 14535 | RequestPriority priority, |
| 14536 | const SSLConfig& server_ssl_config, |
| 14537 | const SSLConfig& proxy_ssl_config, |
| 14538 | HttpStreamRequest::Delegate* delegate, |
| 14539 | const BoundNetLog& net_log) override { |
| 14540 | NOTREACHED(); |
| 14541 | return nullptr; |
| 14542 | } |
| 14543 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14544 | HttpStreamRequest* RequestWebSocketHandshakeStream( |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14545 | const HttpRequestInfo& info, |
| 14546 | RequestPriority priority, |
| 14547 | const SSLConfig& server_ssl_config, |
| 14548 | const SSLConfig& proxy_ssl_config, |
| 14549 | HttpStreamRequest::Delegate* delegate, |
[email protected] | 467086b | 2013-11-12 08:19:46 | [diff] [blame] | 14550 | WebSocketHandshakeStreamBase::CreateHelper* create_helper, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 14551 | const BoundNetLog& net_log) override { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14552 | FakeStreamRequest* fake_request = |
| 14553 | new FakeStreamRequest(priority, delegate, create_helper); |
| 14554 | last_stream_request_ = fake_request->AsWeakPtr(); |
| 14555 | return fake_request; |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14556 | } |
| 14557 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14558 | void PreconnectStreams(int num_streams, |
| 14559 | const HttpRequestInfo& info, |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14560 | const SSLConfig& server_ssl_config, |
| 14561 | const SSLConfig& proxy_ssl_config) override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14562 | ADD_FAILURE(); |
| 14563 | } |
| 14564 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14565 | const HostMappingRules* GetHostMappingRules() const override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14566 | ADD_FAILURE(); |
| 14567 | return NULL; |
| 14568 | } |
| 14569 | |
| 14570 | private: |
| 14571 | base::WeakPtr<FakeStreamRequest> last_stream_request_; |
| 14572 | |
| 14573 | DISALLOW_COPY_AND_ASSIGN(FakeStreamFactory); |
| 14574 | }; |
| 14575 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14576 | // TODO(ricea): Maybe unify this with the one in |
| 14577 | // url_request_http_job_unittest.cc ? |
| 14578 | class FakeWebSocketBasicHandshakeStream : public WebSocketHandshakeStreamBase { |
| 14579 | public: |
| 14580 | FakeWebSocketBasicHandshakeStream(scoped_ptr<ClientSocketHandle> connection, |
| 14581 | bool using_proxy) |
| 14582 | : state_(connection.release(), using_proxy) {} |
| 14583 | |
| 14584 | // Fake implementation of HttpStreamBase methods. |
| 14585 | // This ends up being quite "real" because this object has to really send data |
| 14586 | // on the mock socket. It might be easier to use the real implementation, but |
| 14587 | // the fact that the WebSocket code is not compiled on iOS makes that |
| 14588 | // difficult. |
| 14589 | int InitializeStream(const HttpRequestInfo* request_info, |
| 14590 | RequestPriority priority, |
| 14591 | const BoundNetLog& net_log, |
| 14592 | const CompletionCallback& callback) override { |
| 14593 | state_.Initialize(request_info, priority, net_log, callback); |
| 14594 | return OK; |
| 14595 | } |
| 14596 | |
| 14597 | int SendRequest(const HttpRequestHeaders& request_headers, |
| 14598 | HttpResponseInfo* response, |
| 14599 | const CompletionCallback& callback) override { |
| 14600 | return parser()->SendRequest(state_.GenerateRequestLine(), request_headers, |
| 14601 | response, callback); |
| 14602 | } |
| 14603 | |
| 14604 | int ReadResponseHeaders(const CompletionCallback& callback) override { |
| 14605 | return parser()->ReadResponseHeaders(callback); |
| 14606 | } |
| 14607 | |
| 14608 | int ReadResponseBody(IOBuffer* buf, |
| 14609 | int buf_len, |
| 14610 | const CompletionCallback& callback) override { |
| 14611 | NOTREACHED(); |
| 14612 | return ERR_IO_PENDING; |
| 14613 | } |
| 14614 | |
| 14615 | void Close(bool not_reusable) override { |
| 14616 | if (parser()) |
| 14617 | parser()->Close(true); |
| 14618 | } |
| 14619 | |
| 14620 | bool IsResponseBodyComplete() const override { |
| 14621 | NOTREACHED(); |
| 14622 | return false; |
| 14623 | } |
| 14624 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14625 | bool IsConnectionReused() const override { |
| 14626 | NOTREACHED(); |
| 14627 | return false; |
| 14628 | } |
| 14629 | void SetConnectionReused() override { NOTREACHED(); } |
| 14630 | |
mmenke | bd84c39 | 2015-09-02 14:12:34 | [diff] [blame] | 14631 | bool CanReuseConnection() const override { return false; } |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14632 | |
sclittle | 4de1bab9 | 2015-09-22 21:28:24 | [diff] [blame] | 14633 | int64_t GetTotalReceivedBytes() const override { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14634 | NOTREACHED(); |
| 14635 | return 0; |
| 14636 | } |
| 14637 | |
sclittle | be1ccf6 | 2015-09-02 19:40:36 | [diff] [blame] | 14638 | int64_t GetTotalSentBytes() const override { |
| 14639 | NOTREACHED(); |
| 14640 | return 0; |
| 14641 | } |
| 14642 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14643 | bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override { |
| 14644 | NOTREACHED(); |
| 14645 | return false; |
| 14646 | } |
| 14647 | |
Adam Rice | cb76ac6 | 2015-02-20 05:33:25 | [diff] [blame] | 14648 | void GetSSLInfo(SSLInfo* ssl_info) override {} |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14649 | |
| 14650 | void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override { |
| 14651 | NOTREACHED(); |
| 14652 | } |
| 14653 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14654 | bool GetRemoteEndpoint(IPEndPoint* endpoint) override { return false; } |
| 14655 | |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 14656 | Error GetSignedEKMForTokenBinding(crypto::ECPrivateKey* key, |
| 14657 | std::vector<uint8_t>* out) override { |
| 14658 | ADD_FAILURE(); |
| 14659 | return ERR_NOT_IMPLEMENTED; |
| 14660 | } |
| 14661 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14662 | void Drain(HttpNetworkSession* session) override { NOTREACHED(); } |
| 14663 | |
zhongyi | ca364fbb | 2015-12-12 03:39:12 | [diff] [blame] | 14664 | void PopulateNetErrorDetails(NetErrorDetails* details) override { return; } |
| 14665 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14666 | void SetPriority(RequestPriority priority) override { NOTREACHED(); } |
| 14667 | |
| 14668 | UploadProgress GetUploadProgress() const override { |
| 14669 | NOTREACHED(); |
| 14670 | return UploadProgress(); |
| 14671 | } |
| 14672 | |
| 14673 | HttpStream* RenewStreamForAuth() override { |
| 14674 | NOTREACHED(); |
| 14675 | return nullptr; |
| 14676 | } |
| 14677 | |
| 14678 | // Fake implementation of WebSocketHandshakeStreamBase method(s) |
| 14679 | scoped_ptr<WebSocketStream> Upgrade() override { |
| 14680 | NOTREACHED(); |
| 14681 | return scoped_ptr<WebSocketStream>(); |
| 14682 | } |
| 14683 | |
| 14684 | private: |
| 14685 | HttpStreamParser* parser() const { return state_.parser(); } |
| 14686 | HttpBasicState state_; |
| 14687 | |
| 14688 | DISALLOW_COPY_AND_ASSIGN(FakeWebSocketBasicHandshakeStream); |
| 14689 | }; |
| 14690 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14691 | // TODO(yhirano): Split this class out into a net/websockets file, if it is |
| 14692 | // worth doing. |
| 14693 | class FakeWebSocketStreamCreateHelper : |
| 14694 | public WebSocketHandshakeStreamBase::CreateHelper { |
| 14695 | public: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14696 | WebSocketHandshakeStreamBase* CreateBasicStream( |
[email protected] | 7e841a5 | 2013-11-22 09:04:21 | [diff] [blame] | 14697 | scoped_ptr<ClientSocketHandle> connection, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 14698 | bool using_proxy) override { |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 14699 | return new FakeWebSocketBasicHandshakeStream(std::move(connection), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14700 | using_proxy); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14701 | } |
| 14702 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14703 | WebSocketHandshakeStreamBase* CreateSpdyStream( |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14704 | const base::WeakPtr<SpdySession>& session, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 14705 | bool use_relative_url) override { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14706 | NOTREACHED(); |
| 14707 | return NULL; |
| 14708 | }; |
| 14709 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14710 | ~FakeWebSocketStreamCreateHelper() override {} |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14711 | |
| 14712 | virtual scoped_ptr<WebSocketStream> Upgrade() { |
| 14713 | NOTREACHED(); |
| 14714 | return scoped_ptr<WebSocketStream>(); |
| 14715 | } |
| 14716 | }; |
| 14717 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14718 | } // namespace |
| 14719 | |
| 14720 | // Make sure that HttpNetworkTransaction passes on its priority to its |
| 14721 | // stream request on start. |
| 14722 | TEST_P(HttpNetworkTransactionTest, SetStreamRequestPriorityOnStart) { |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14723 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14724 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14725 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14726 | peer.SetHttpStreamFactory(scoped_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14727 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14728 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14729 | |
| 14730 | ASSERT_TRUE(fake_factory->last_stream_request() == NULL); |
| 14731 | |
| 14732 | HttpRequestInfo request; |
| 14733 | TestCompletionCallback callback; |
| 14734 | EXPECT_EQ(ERR_IO_PENDING, |
| 14735 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 14736 | |
| 14737 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 14738 | fake_factory->last_stream_request(); |
| 14739 | ASSERT_TRUE(fake_request != NULL); |
| 14740 | EXPECT_EQ(LOW, fake_request->priority()); |
| 14741 | } |
| 14742 | |
| 14743 | // Make sure that HttpNetworkTransaction passes on its priority |
| 14744 | // updates to its stream request. |
| 14745 | TEST_P(HttpNetworkTransactionTest, SetStreamRequestPriority) { |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14746 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14747 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14748 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14749 | peer.SetHttpStreamFactory(scoped_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14750 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14751 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14752 | |
| 14753 | HttpRequestInfo request; |
| 14754 | TestCompletionCallback callback; |
| 14755 | EXPECT_EQ(ERR_IO_PENDING, |
| 14756 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 14757 | |
| 14758 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 14759 | fake_factory->last_stream_request(); |
| 14760 | ASSERT_TRUE(fake_request != NULL); |
| 14761 | EXPECT_EQ(LOW, fake_request->priority()); |
| 14762 | |
| 14763 | trans.SetPriority(LOWEST); |
| 14764 | ASSERT_TRUE(fake_request != NULL); |
| 14765 | EXPECT_EQ(LOWEST, fake_request->priority()); |
| 14766 | } |
| 14767 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14768 | // Make sure that HttpNetworkTransaction passes on its priority |
| 14769 | // updates to its stream. |
| 14770 | TEST_P(HttpNetworkTransactionTest, SetStreamPriority) { |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14771 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14772 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14773 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14774 | peer.SetHttpStreamFactory(scoped_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14775 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14776 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14777 | |
| 14778 | HttpRequestInfo request; |
| 14779 | TestCompletionCallback callback; |
| 14780 | EXPECT_EQ(ERR_IO_PENDING, |
| 14781 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 14782 | |
| 14783 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 14784 | fake_factory->last_stream_request(); |
| 14785 | ASSERT_TRUE(fake_request != NULL); |
| 14786 | base::WeakPtr<FakeStream> fake_stream = fake_request->FinishStreamRequest(); |
| 14787 | ASSERT_TRUE(fake_stream != NULL); |
| 14788 | EXPECT_EQ(LOW, fake_stream->priority()); |
| 14789 | |
| 14790 | trans.SetPriority(LOWEST); |
| 14791 | EXPECT_EQ(LOWEST, fake_stream->priority()); |
| 14792 | } |
| 14793 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14794 | TEST_P(HttpNetworkTransactionTest, CreateWebSocketHandshakeStream) { |
| 14795 | // The same logic needs to be tested for both ws: and wss: schemes, but this |
| 14796 | // test is already parameterised on NextProto, so it uses a loop to verify |
| 14797 | // that the different schemes work. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14798 | std::string test_cases[] = {"ws://www.example.org/", |
| 14799 | "wss://www.example.org/"}; |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14800 | for (size_t i = 0; i < arraysize(test_cases); ++i) { |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14801 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14802 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14803 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
| 14804 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
[email protected] | 0191b51c | 2013-11-18 10:55:23 | [diff] [blame] | 14805 | peer.SetHttpStreamFactoryForWebSocket( |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14806 | scoped_ptr<HttpStreamFactory>(fake_factory)); |
| 14807 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14808 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14809 | trans.SetWebSocketHandshakeStreamCreateHelper( |
| 14810 | &websocket_stream_create_helper); |
| 14811 | |
| 14812 | HttpRequestInfo request; |
| 14813 | TestCompletionCallback callback; |
| 14814 | request.method = "GET"; |
| 14815 | request.url = GURL(test_cases[i]); |
| 14816 | |
| 14817 | EXPECT_EQ(ERR_IO_PENDING, |
| 14818 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 14819 | |
| 14820 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 14821 | fake_factory->last_stream_request(); |
| 14822 | ASSERT_TRUE(fake_request != NULL); |
| 14823 | EXPECT_EQ(&websocket_stream_create_helper, |
| 14824 | fake_request->websocket_stream_create_helper()); |
| 14825 | } |
| 14826 | } |
| 14827 | |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14828 | // Tests that when a used socket is returned to the SSL socket pool, it's closed |
| 14829 | // if the transport socket pool is stalled on the global socket limit. |
| 14830 | TEST_P(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest) { |
| 14831 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 14832 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 14833 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 14834 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 14835 | |
| 14836 | // Set up SSL request. |
| 14837 | |
| 14838 | HttpRequestInfo ssl_request; |
| 14839 | ssl_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14840 | ssl_request.url = GURL("https://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14841 | |
| 14842 | MockWrite ssl_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14843 | MockWrite( |
| 14844 | "GET / HTTP/1.1\r\n" |
| 14845 | "Host: www.example.org\r\n" |
| 14846 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14847 | }; |
| 14848 | MockRead ssl_reads[] = { |
| 14849 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14850 | MockRead("Content-Length: 11\r\n\r\n"), |
| 14851 | MockRead("hello world"), |
| 14852 | MockRead(SYNCHRONOUS, OK), |
| 14853 | }; |
| 14854 | StaticSocketDataProvider ssl_data(ssl_reads, arraysize(ssl_reads), |
| 14855 | ssl_writes, arraysize(ssl_writes)); |
| 14856 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 14857 | |
| 14858 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 14859 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 14860 | |
| 14861 | // Set up HTTP request. |
| 14862 | |
| 14863 | HttpRequestInfo http_request; |
| 14864 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14865 | http_request.url = GURL("http://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14866 | |
| 14867 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14868 | MockWrite( |
| 14869 | "GET / HTTP/1.1\r\n" |
| 14870 | "Host: www.example.org\r\n" |
| 14871 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14872 | }; |
| 14873 | MockRead http_reads[] = { |
| 14874 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14875 | MockRead("Content-Length: 7\r\n\r\n"), |
| 14876 | MockRead("falafel"), |
| 14877 | MockRead(SYNCHRONOUS, OK), |
| 14878 | }; |
| 14879 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 14880 | http_writes, arraysize(http_writes)); |
| 14881 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 14882 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14883 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14884 | |
| 14885 | // Start the SSL request. |
| 14886 | TestCompletionCallback ssl_callback; |
| 14887 | scoped_ptr<HttpTransaction> ssl_trans( |
| 14888 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 14889 | ASSERT_EQ(ERR_IO_PENDING, |
| 14890 | ssl_trans->Start(&ssl_request, ssl_callback.callback(), |
| 14891 | BoundNetLog())); |
| 14892 | |
| 14893 | // Start the HTTP request. Pool should stall. |
| 14894 | TestCompletionCallback http_callback; |
| 14895 | scoped_ptr<HttpTransaction> http_trans( |
| 14896 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 14897 | ASSERT_EQ(ERR_IO_PENDING, |
| 14898 | http_trans->Start(&http_request, http_callback.callback(), |
| 14899 | BoundNetLog())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14900 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14901 | |
| 14902 | // Wait for response from SSL request. |
| 14903 | ASSERT_EQ(OK, ssl_callback.WaitForResult()); |
| 14904 | std::string response_data; |
| 14905 | ASSERT_EQ(OK, ReadTransaction(ssl_trans.get(), &response_data)); |
| 14906 | EXPECT_EQ("hello world", response_data); |
| 14907 | |
| 14908 | // The SSL socket should automatically be closed, so the HTTP request can |
| 14909 | // start. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14910 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 14911 | ASSERT_FALSE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14912 | |
| 14913 | // The HTTP request can now complete. |
| 14914 | ASSERT_EQ(OK, http_callback.WaitForResult()); |
| 14915 | ASSERT_EQ(OK, ReadTransaction(http_trans.get(), &response_data)); |
| 14916 | EXPECT_EQ("falafel", response_data); |
| 14917 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14918 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14919 | } |
| 14920 | |
| 14921 | // Tests that when a SSL connection is established but there's no corresponding |
| 14922 | // request that needs it, the new socket is closed if the transport socket pool |
| 14923 | // is stalled on the global socket limit. |
| 14924 | TEST_P(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest2) { |
| 14925 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 14926 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 14927 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 14928 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 14929 | |
| 14930 | // Set up an ssl request. |
| 14931 | |
| 14932 | HttpRequestInfo ssl_request; |
| 14933 | ssl_request.method = "GET"; |
| 14934 | ssl_request.url = GURL("https://www.foopy.com/"); |
| 14935 | |
| 14936 | // No data will be sent on the SSL socket. |
| 14937 | StaticSocketDataProvider ssl_data; |
| 14938 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 14939 | |
| 14940 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 14941 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 14942 | |
| 14943 | // Set up HTTP request. |
| 14944 | |
| 14945 | HttpRequestInfo http_request; |
| 14946 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14947 | http_request.url = GURL("http://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14948 | |
| 14949 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14950 | MockWrite( |
| 14951 | "GET / HTTP/1.1\r\n" |
| 14952 | "Host: www.example.org\r\n" |
| 14953 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14954 | }; |
| 14955 | MockRead http_reads[] = { |
| 14956 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14957 | MockRead("Content-Length: 7\r\n\r\n"), |
| 14958 | MockRead("falafel"), |
| 14959 | MockRead(SYNCHRONOUS, OK), |
| 14960 | }; |
| 14961 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 14962 | http_writes, arraysize(http_writes)); |
| 14963 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 14964 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14965 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14966 | |
| 14967 | // Preconnect an SSL socket. A preconnect is needed because connect jobs are |
| 14968 | // cancelled when a normal transaction is cancelled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14969 | HttpStreamFactory* http_stream_factory = session->http_stream_factory(); |
| 14970 | SSLConfig ssl_config; |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14971 | session->ssl_config_service()->GetSSLConfig(&ssl_config); |
mmenke | d1205bd | 2015-07-15 22:26:35 | [diff] [blame] | 14972 | http_stream_factory->PreconnectStreams(1, ssl_request, ssl_config, |
| 14973 | ssl_config); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14974 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14975 | |
| 14976 | // Start the HTTP request. Pool should stall. |
| 14977 | TestCompletionCallback http_callback; |
| 14978 | scoped_ptr<HttpTransaction> http_trans( |
| 14979 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 14980 | ASSERT_EQ(ERR_IO_PENDING, |
| 14981 | http_trans->Start(&http_request, http_callback.callback(), |
| 14982 | BoundNetLog())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14983 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14984 | |
| 14985 | // The SSL connection will automatically be closed once the connection is |
| 14986 | // established, to let the HTTP request start. |
| 14987 | ASSERT_EQ(OK, http_callback.WaitForResult()); |
| 14988 | std::string response_data; |
| 14989 | ASSERT_EQ(OK, ReadTransaction(http_trans.get(), &response_data)); |
| 14990 | EXPECT_EQ("falafel", response_data); |
| 14991 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14992 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14993 | } |
| 14994 | |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14995 | TEST_P(HttpNetworkTransactionTest, PostReadsErrorResponseAfterReset) { |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 14996 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 14997 | element_readers.push_back( |
| 14998 | make_scoped_ptr(new UploadBytesElementReader("foo", 3))); |
| 14999 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15000 | |
| 15001 | HttpRequestInfo request; |
| 15002 | request.method = "POST"; |
| 15003 | request.url = GURL("http://www.foo.com/"); |
| 15004 | request.upload_data_stream = &upload_data_stream; |
| 15005 | request.load_flags = 0; |
| 15006 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15007 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15008 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15009 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15010 | // Send headers successfully, but get an error while sending the body. |
| 15011 | MockWrite data_writes[] = { |
| 15012 | MockWrite("POST / HTTP/1.1\r\n" |
| 15013 | "Host: www.foo.com\r\n" |
| 15014 | "Connection: keep-alive\r\n" |
| 15015 | "Content-Length: 3\r\n\r\n"), |
| 15016 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15017 | }; |
| 15018 | |
| 15019 | MockRead data_reads[] = { |
| 15020 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 15021 | MockRead("hello world"), |
| 15022 | MockRead(SYNCHRONOUS, OK), |
| 15023 | }; |
| 15024 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15025 | arraysize(data_writes)); |
| 15026 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15027 | |
| 15028 | TestCompletionCallback callback; |
| 15029 | |
| 15030 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 15031 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 15032 | |
| 15033 | rv = callback.WaitForResult(); |
| 15034 | EXPECT_EQ(OK, rv); |
| 15035 | |
| 15036 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 15037 | ASSERT_TRUE(response != NULL); |
| 15038 | |
| 15039 | EXPECT_TRUE(response->headers.get() != NULL); |
| 15040 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 15041 | |
| 15042 | std::string response_data; |
| 15043 | rv = ReadTransaction(trans.get(), &response_data); |
| 15044 | EXPECT_EQ(OK, rv); |
| 15045 | EXPECT_EQ("hello world", response_data); |
| 15046 | } |
| 15047 | |
| 15048 | // This test makes sure the retry logic doesn't trigger when reading an error |
| 15049 | // response from a server that rejected a POST with a CONNECTION_RESET. |
| 15050 | TEST_P(HttpNetworkTransactionTest, |
| 15051 | PostReadsErrorResponseAfterResetOnReusedSocket) { |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15052 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15053 | MockWrite data_writes[] = { |
| 15054 | MockWrite("GET / HTTP/1.1\r\n" |
| 15055 | "Host: www.foo.com\r\n" |
| 15056 | "Connection: keep-alive\r\n\r\n"), |
| 15057 | MockWrite("POST / HTTP/1.1\r\n" |
| 15058 | "Host: www.foo.com\r\n" |
| 15059 | "Connection: keep-alive\r\n" |
| 15060 | "Content-Length: 3\r\n\r\n"), |
| 15061 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15062 | }; |
| 15063 | |
| 15064 | MockRead data_reads[] = { |
| 15065 | MockRead("HTTP/1.1 200 Peachy\r\n" |
| 15066 | "Content-Length: 14\r\n\r\n"), |
| 15067 | MockRead("first response"), |
| 15068 | MockRead("HTTP/1.1 400 Not OK\r\n" |
| 15069 | "Content-Length: 15\r\n\r\n"), |
| 15070 | MockRead("second response"), |
| 15071 | MockRead(SYNCHRONOUS, OK), |
| 15072 | }; |
| 15073 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15074 | arraysize(data_writes)); |
| 15075 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15076 | |
| 15077 | TestCompletionCallback callback; |
| 15078 | HttpRequestInfo request1; |
| 15079 | request1.method = "GET"; |
| 15080 | request1.url = GURL("http://www.foo.com/"); |
| 15081 | request1.load_flags = 0; |
| 15082 | |
| 15083 | scoped_ptr<HttpTransaction> trans1( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15084 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15085 | int rv = trans1->Start(&request1, callback.callback(), BoundNetLog()); |
| 15086 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 15087 | |
| 15088 | rv = callback.WaitForResult(); |
| 15089 | EXPECT_EQ(OK, rv); |
| 15090 | |
| 15091 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 15092 | ASSERT_TRUE(response1 != NULL); |
| 15093 | |
| 15094 | EXPECT_TRUE(response1->headers.get() != NULL); |
| 15095 | EXPECT_EQ("HTTP/1.1 200 Peachy", response1->headers->GetStatusLine()); |
| 15096 | |
| 15097 | std::string response_data1; |
| 15098 | rv = ReadTransaction(trans1.get(), &response_data1); |
| 15099 | EXPECT_EQ(OK, rv); |
| 15100 | EXPECT_EQ("first response", response_data1); |
| 15101 | // Delete the transaction to release the socket back into the socket pool. |
| 15102 | trans1.reset(); |
| 15103 | |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15104 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 15105 | element_readers.push_back( |
| 15106 | make_scoped_ptr(new UploadBytesElementReader("foo", 3))); |
| 15107 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15108 | |
| 15109 | HttpRequestInfo request2; |
| 15110 | request2.method = "POST"; |
| 15111 | request2.url = GURL("http://www.foo.com/"); |
| 15112 | request2.upload_data_stream = &upload_data_stream; |
| 15113 | request2.load_flags = 0; |
| 15114 | |
| 15115 | scoped_ptr<HttpTransaction> trans2( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15116 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15117 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
| 15118 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 15119 | |
| 15120 | rv = callback.WaitForResult(); |
| 15121 | EXPECT_EQ(OK, rv); |
| 15122 | |
| 15123 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 15124 | ASSERT_TRUE(response2 != NULL); |
| 15125 | |
| 15126 | EXPECT_TRUE(response2->headers.get() != NULL); |
| 15127 | EXPECT_EQ("HTTP/1.1 400 Not OK", response2->headers->GetStatusLine()); |
| 15128 | |
| 15129 | std::string response_data2; |
| 15130 | rv = ReadTransaction(trans2.get(), &response_data2); |
| 15131 | EXPECT_EQ(OK, rv); |
| 15132 | EXPECT_EQ("second response", response_data2); |
| 15133 | } |
| 15134 | |
| 15135 | TEST_P(HttpNetworkTransactionTest, |
| 15136 | PostReadsErrorResponseAfterResetPartialBodySent) { |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15137 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 15138 | element_readers.push_back( |
| 15139 | make_scoped_ptr(new UploadBytesElementReader("foo", 3))); |
| 15140 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15141 | |
| 15142 | HttpRequestInfo request; |
| 15143 | request.method = "POST"; |
| 15144 | request.url = GURL("http://www.foo.com/"); |
| 15145 | request.upload_data_stream = &upload_data_stream; |
| 15146 | request.load_flags = 0; |
| 15147 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15148 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15149 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15150 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15151 | // Send headers successfully, but get an error while sending the body. |
| 15152 | MockWrite data_writes[] = { |
| 15153 | MockWrite("POST / HTTP/1.1\r\n" |
| 15154 | "Host: www.foo.com\r\n" |
| 15155 | "Connection: keep-alive\r\n" |
| 15156 | "Content-Length: 3\r\n\r\n" |
| 15157 | "fo"), |
| 15158 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15159 | }; |
| 15160 | |
| 15161 | MockRead data_reads[] = { |
| 15162 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 15163 | MockRead("hello world"), |
| 15164 | MockRead(SYNCHRONOUS, OK), |
| 15165 | }; |
| 15166 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15167 | arraysize(data_writes)); |
| 15168 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15169 | |
| 15170 | TestCompletionCallback callback; |
| 15171 | |
| 15172 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 15173 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 15174 | |
| 15175 | rv = callback.WaitForResult(); |
| 15176 | EXPECT_EQ(OK, rv); |
| 15177 | |
| 15178 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 15179 | ASSERT_TRUE(response != NULL); |
| 15180 | |
| 15181 | EXPECT_TRUE(response->headers.get() != NULL); |
| 15182 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 15183 | |
| 15184 | std::string response_data; |
| 15185 | rv = ReadTransaction(trans.get(), &response_data); |
| 15186 | EXPECT_EQ(OK, rv); |
| 15187 | EXPECT_EQ("hello world", response_data); |
| 15188 | } |
| 15189 | |
| 15190 | // This tests the more common case than the previous test, where headers and |
| 15191 | // body are not merged into a single request. |
| 15192 | TEST_P(HttpNetworkTransactionTest, ChunkedPostReadsErrorResponseAfterReset) { |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 15193 | ChunkedUploadDataStream upload_data_stream(0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15194 | |
| 15195 | HttpRequestInfo request; |
| 15196 | request.method = "POST"; |
| 15197 | request.url = GURL("http://www.foo.com/"); |
| 15198 | request.upload_data_stream = &upload_data_stream; |
| 15199 | request.load_flags = 0; |
| 15200 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15201 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15202 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15203 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15204 | // Send headers successfully, but get an error while sending the body. |
| 15205 | MockWrite data_writes[] = { |
| 15206 | MockWrite("POST / HTTP/1.1\r\n" |
| 15207 | "Host: www.foo.com\r\n" |
| 15208 | "Connection: keep-alive\r\n" |
| 15209 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 15210 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15211 | }; |
| 15212 | |
| 15213 | MockRead data_reads[] = { |
| 15214 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 15215 | MockRead("hello world"), |
| 15216 | MockRead(SYNCHRONOUS, OK), |
| 15217 | }; |
| 15218 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15219 | arraysize(data_writes)); |
| 15220 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15221 | |
| 15222 | TestCompletionCallback callback; |
| 15223 | |
| 15224 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 15225 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 15226 | // Make sure the headers are sent before adding a chunk. This ensures that |
| 15227 | // they can't be merged with the body in a single send. Not currently |
| 15228 | // necessary since a chunked body is never merged with headers, but this makes |
| 15229 | // the test more future proof. |
| 15230 | base::RunLoop().RunUntilIdle(); |
| 15231 | |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 15232 | upload_data_stream.AppendData("last chunk", 10, true); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15233 | |
| 15234 | rv = callback.WaitForResult(); |
| 15235 | EXPECT_EQ(OK, rv); |
| 15236 | |
| 15237 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 15238 | ASSERT_TRUE(response != NULL); |
| 15239 | |
| 15240 | EXPECT_TRUE(response->headers.get() != NULL); |
| 15241 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 15242 | |
| 15243 | std::string response_data; |
| 15244 | rv = ReadTransaction(trans.get(), &response_data); |
| 15245 | EXPECT_EQ(OK, rv); |
| 15246 | EXPECT_EQ("hello world", response_data); |
| 15247 | } |
| 15248 | |
| 15249 | TEST_P(HttpNetworkTransactionTest, PostReadsErrorResponseAfterResetAnd100) { |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15250 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 15251 | element_readers.push_back( |
| 15252 | make_scoped_ptr(new UploadBytesElementReader("foo", 3))); |
| 15253 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15254 | |
| 15255 | HttpRequestInfo request; |
| 15256 | request.method = "POST"; |
| 15257 | request.url = GURL("http://www.foo.com/"); |
| 15258 | request.upload_data_stream = &upload_data_stream; |
| 15259 | request.load_flags = 0; |
| 15260 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15261 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15262 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15263 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15264 | |
| 15265 | MockWrite data_writes[] = { |
| 15266 | MockWrite("POST / HTTP/1.1\r\n" |
| 15267 | "Host: www.foo.com\r\n" |
| 15268 | "Connection: keep-alive\r\n" |
| 15269 | "Content-Length: 3\r\n\r\n"), |
| 15270 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15271 | }; |
| 15272 | |
| 15273 | MockRead data_reads[] = { |
| 15274 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 15275 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 15276 | MockRead("hello world"), |
| 15277 | MockRead(SYNCHRONOUS, OK), |
| 15278 | }; |
| 15279 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15280 | arraysize(data_writes)); |
| 15281 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15282 | |
| 15283 | TestCompletionCallback callback; |
| 15284 | |
| 15285 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 15286 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 15287 | |
| 15288 | rv = callback.WaitForResult(); |
| 15289 | EXPECT_EQ(OK, rv); |
| 15290 | |
| 15291 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 15292 | ASSERT_TRUE(response != NULL); |
| 15293 | |
| 15294 | EXPECT_TRUE(response->headers.get() != NULL); |
| 15295 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 15296 | |
| 15297 | std::string response_data; |
| 15298 | rv = ReadTransaction(trans.get(), &response_data); |
| 15299 | EXPECT_EQ(OK, rv); |
| 15300 | EXPECT_EQ("hello world", response_data); |
| 15301 | } |
| 15302 | |
| 15303 | TEST_P(HttpNetworkTransactionTest, PostIgnoresNonErrorResponseAfterReset) { |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15304 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 15305 | element_readers.push_back( |
| 15306 | make_scoped_ptr(new UploadBytesElementReader("foo", 3))); |
| 15307 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15308 | |
| 15309 | HttpRequestInfo request; |
| 15310 | request.method = "POST"; |
| 15311 | request.url = GURL("http://www.foo.com/"); |
| 15312 | request.upload_data_stream = &upload_data_stream; |
| 15313 | request.load_flags = 0; |
| 15314 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15315 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15316 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15317 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15318 | // Send headers successfully, but get an error while sending the body. |
| 15319 | MockWrite data_writes[] = { |
| 15320 | MockWrite("POST / HTTP/1.1\r\n" |
| 15321 | "Host: www.foo.com\r\n" |
| 15322 | "Connection: keep-alive\r\n" |
| 15323 | "Content-Length: 3\r\n\r\n"), |
| 15324 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15325 | }; |
| 15326 | |
| 15327 | MockRead data_reads[] = { |
| 15328 | MockRead("HTTP/1.0 200 Just Dandy\r\n\r\n"), |
| 15329 | MockRead("hello world"), |
| 15330 | MockRead(SYNCHRONOUS, OK), |
| 15331 | }; |
| 15332 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15333 | arraysize(data_writes)); |
| 15334 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15335 | |
| 15336 | TestCompletionCallback callback; |
| 15337 | |
| 15338 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 15339 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 15340 | |
| 15341 | rv = callback.WaitForResult(); |
| 15342 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15343 | } |
| 15344 | |
| 15345 | TEST_P(HttpNetworkTransactionTest, |
| 15346 | PostIgnoresNonErrorResponseAfterResetAnd100) { |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15347 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 15348 | element_readers.push_back( |
| 15349 | make_scoped_ptr(new UploadBytesElementReader("foo", 3))); |
| 15350 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15351 | |
| 15352 | HttpRequestInfo request; |
| 15353 | request.method = "POST"; |
| 15354 | request.url = GURL("http://www.foo.com/"); |
| 15355 | request.upload_data_stream = &upload_data_stream; |
| 15356 | request.load_flags = 0; |
| 15357 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15358 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15359 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15360 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15361 | // Send headers successfully, but get an error while sending the body. |
| 15362 | MockWrite data_writes[] = { |
| 15363 | MockWrite("POST / HTTP/1.1\r\n" |
| 15364 | "Host: www.foo.com\r\n" |
| 15365 | "Connection: keep-alive\r\n" |
| 15366 | "Content-Length: 3\r\n\r\n"), |
| 15367 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15368 | }; |
| 15369 | |
| 15370 | MockRead data_reads[] = { |
| 15371 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 15372 | MockRead("HTTP/1.0 302 Redirect\r\n"), |
| 15373 | MockRead("Location: http://somewhere-else.com/\r\n"), |
| 15374 | MockRead("Content-Length: 0\r\n\r\n"), |
| 15375 | MockRead(SYNCHRONOUS, OK), |
| 15376 | }; |
| 15377 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15378 | arraysize(data_writes)); |
| 15379 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15380 | |
| 15381 | TestCompletionCallback callback; |
| 15382 | |
| 15383 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 15384 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 15385 | |
| 15386 | rv = callback.WaitForResult(); |
| 15387 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15388 | } |
| 15389 | |
| 15390 | TEST_P(HttpNetworkTransactionTest, PostIgnoresHttp09ResponseAfterReset) { |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15391 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 15392 | element_readers.push_back( |
| 15393 | make_scoped_ptr(new UploadBytesElementReader("foo", 3))); |
| 15394 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15395 | |
| 15396 | HttpRequestInfo request; |
| 15397 | request.method = "POST"; |
| 15398 | request.url = GURL("http://www.foo.com/"); |
| 15399 | request.upload_data_stream = &upload_data_stream; |
| 15400 | request.load_flags = 0; |
| 15401 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15402 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15403 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15404 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15405 | // Send headers successfully, but get an error while sending the body. |
| 15406 | MockWrite data_writes[] = { |
| 15407 | MockWrite("POST / HTTP/1.1\r\n" |
| 15408 | "Host: www.foo.com\r\n" |
| 15409 | "Connection: keep-alive\r\n" |
| 15410 | "Content-Length: 3\r\n\r\n"), |
| 15411 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15412 | }; |
| 15413 | |
| 15414 | MockRead data_reads[] = { |
| 15415 | MockRead("HTTP 0.9 rocks!"), |
| 15416 | MockRead(SYNCHRONOUS, OK), |
| 15417 | }; |
| 15418 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15419 | arraysize(data_writes)); |
| 15420 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15421 | |
| 15422 | TestCompletionCallback callback; |
| 15423 | |
| 15424 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 15425 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 15426 | |
| 15427 | rv = callback.WaitForResult(); |
| 15428 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15429 | } |
| 15430 | |
| 15431 | TEST_P(HttpNetworkTransactionTest, PostIgnoresPartial400HeadersAfterReset) { |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15432 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 15433 | element_readers.push_back( |
| 15434 | make_scoped_ptr(new UploadBytesElementReader("foo", 3))); |
| 15435 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15436 | |
| 15437 | HttpRequestInfo request; |
| 15438 | request.method = "POST"; |
| 15439 | request.url = GURL("http://www.foo.com/"); |
| 15440 | request.upload_data_stream = &upload_data_stream; |
| 15441 | request.load_flags = 0; |
| 15442 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15443 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15444 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15445 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15446 | // Send headers successfully, but get an error while sending the body. |
| 15447 | MockWrite data_writes[] = { |
| 15448 | MockWrite("POST / HTTP/1.1\r\n" |
| 15449 | "Host: www.foo.com\r\n" |
| 15450 | "Connection: keep-alive\r\n" |
| 15451 | "Content-Length: 3\r\n\r\n"), |
| 15452 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15453 | }; |
| 15454 | |
| 15455 | MockRead data_reads[] = { |
| 15456 | MockRead("HTTP/1.0 400 Not a Full Response\r\n"), |
| 15457 | MockRead(SYNCHRONOUS, OK), |
| 15458 | }; |
| 15459 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15460 | arraysize(data_writes)); |
| 15461 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15462 | |
| 15463 | TestCompletionCallback callback; |
| 15464 | |
| 15465 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 15466 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 15467 | |
| 15468 | rv = callback.WaitForResult(); |
| 15469 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15470 | } |
| 15471 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15472 | // Verify that proxy headers are not sent to the destination server when |
| 15473 | // establishing a tunnel for a secure WebSocket connection. |
| 15474 | TEST_P(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWssTunnel) { |
| 15475 | HttpRequestInfo request; |
| 15476 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15477 | request.url = GURL("wss://www.example.org/"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15478 | AddWebSocketHeaders(&request.extra_headers); |
| 15479 | |
| 15480 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 15481 | session_deps_.proxy_service = |
| 15482 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15483 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15484 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15485 | |
| 15486 | // Since a proxy is configured, try to establish a tunnel. |
| 15487 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15488 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 15489 | "Host: www.example.org:443\r\n" |
| 15490 | "Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15491 | |
| 15492 | // After calling trans->RestartWithAuth(), this is the request we should |
| 15493 | // be issuing -- the final header line contains the credentials. |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15494 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 15495 | "Host: www.example.org:443\r\n" |
| 15496 | "Proxy-Connection: keep-alive\r\n" |
| 15497 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15498 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15499 | MockWrite("GET / HTTP/1.1\r\n" |
| 15500 | "Host: www.example.org\r\n" |
| 15501 | "Connection: Upgrade\r\n" |
| 15502 | "Upgrade: websocket\r\n" |
| 15503 | "Origin: http://www.example.org\r\n" |
| 15504 | "Sec-WebSocket-Version: 13\r\n" |
| 15505 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15506 | }; |
| 15507 | |
| 15508 | // The proxy responds to the connect with a 407, using a persistent |
| 15509 | // connection. |
| 15510 | MockRead data_reads[] = { |
| 15511 | // No credentials. |
| 15512 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 15513 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 15514 | MockRead("Content-Length: 0\r\n"), |
| 15515 | MockRead("Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15516 | |
| 15517 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 15518 | |
| 15519 | MockRead("HTTP/1.1 101 Switching Protocols\r\n"), |
| 15520 | MockRead("Upgrade: websocket\r\n"), |
| 15521 | MockRead("Connection: Upgrade\r\n"), |
| 15522 | MockRead("Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n"), |
| 15523 | }; |
| 15524 | |
| 15525 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15526 | arraysize(data_writes)); |
| 15527 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15528 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 15529 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 15530 | |
| 15531 | scoped_ptr<HttpTransaction> trans( |
| 15532 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 15533 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
| 15534 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 15535 | &websocket_stream_create_helper); |
| 15536 | |
| 15537 | { |
| 15538 | TestCompletionCallback callback; |
| 15539 | |
| 15540 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 15541 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 15542 | |
| 15543 | rv = callback.WaitForResult(); |
| 15544 | EXPECT_EQ(OK, rv); |
| 15545 | } |
| 15546 | |
| 15547 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 15548 | ASSERT_TRUE(response); |
| 15549 | ASSERT_TRUE(response->headers.get()); |
| 15550 | EXPECT_EQ(407, response->headers->response_code()); |
| 15551 | |
| 15552 | { |
| 15553 | TestCompletionCallback callback; |
| 15554 | |
| 15555 | int rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 15556 | callback.callback()); |
| 15557 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 15558 | |
| 15559 | rv = callback.WaitForResult(); |
| 15560 | EXPECT_EQ(OK, rv); |
| 15561 | } |
| 15562 | |
| 15563 | response = trans->GetResponseInfo(); |
| 15564 | ASSERT_TRUE(response); |
| 15565 | ASSERT_TRUE(response->headers.get()); |
| 15566 | |
| 15567 | EXPECT_EQ(101, response->headers->response_code()); |
| 15568 | |
| 15569 | trans.reset(); |
| 15570 | session->CloseAllConnections(); |
| 15571 | } |
| 15572 | |
| 15573 | // Verify that proxy headers are not sent to the destination server when |
| 15574 | // establishing a tunnel for an insecure WebSocket connection. |
| 15575 | // This requires the authentication info to be injected into the auth cache |
| 15576 | // due to crbug.com/395064 |
| 15577 | // TODO(ricea): Change to use a 407 response once issue 395064 is fixed. |
| 15578 | TEST_P(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWsTunnel) { |
| 15579 | HttpRequestInfo request; |
| 15580 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15581 | request.url = GURL("ws://www.example.org/"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15582 | AddWebSocketHeaders(&request.extra_headers); |
| 15583 | |
| 15584 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 15585 | session_deps_.proxy_service = |
| 15586 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15587 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15588 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15589 | |
| 15590 | MockWrite data_writes[] = { |
| 15591 | // Try to establish a tunnel for the WebSocket connection, with |
| 15592 | // credentials. Because WebSockets have a separate set of socket pools, |
| 15593 | // they cannot and will not use the same TCP/IP connection as the |
| 15594 | // preflight HTTP request. |
| 15595 | MockWrite( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15596 | "CONNECT www.example.org:80 HTTP/1.1\r\n" |
| 15597 | "Host: www.example.org:80\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15598 | "Proxy-Connection: keep-alive\r\n" |
| 15599 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 15600 | |
| 15601 | MockWrite( |
| 15602 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15603 | "Host: www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15604 | "Connection: Upgrade\r\n" |
| 15605 | "Upgrade: websocket\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15606 | "Origin: http://www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15607 | "Sec-WebSocket-Version: 13\r\n" |
| 15608 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n\r\n"), |
| 15609 | }; |
| 15610 | |
| 15611 | MockRead data_reads[] = { |
| 15612 | // HTTP CONNECT with credentials. |
| 15613 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 15614 | |
| 15615 | // WebSocket connection established inside tunnel. |
| 15616 | MockRead("HTTP/1.1 101 Switching Protocols\r\n"), |
| 15617 | MockRead("Upgrade: websocket\r\n"), |
| 15618 | MockRead("Connection: Upgrade\r\n"), |
| 15619 | MockRead("Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n"), |
| 15620 | }; |
| 15621 | |
| 15622 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15623 | arraysize(data_writes)); |
| 15624 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15625 | |
| 15626 | session->http_auth_cache()->Add( |
| 15627 | GURL("http://myproxy:70/"), "MyRealm1", HttpAuth::AUTH_SCHEME_BASIC, |
| 15628 | "Basic realm=MyRealm1", AuthCredentials(kFoo, kBar), "/"); |
| 15629 | |
| 15630 | scoped_ptr<HttpTransaction> trans( |
| 15631 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 15632 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
| 15633 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 15634 | &websocket_stream_create_helper); |
| 15635 | |
| 15636 | TestCompletionCallback callback; |
| 15637 | |
| 15638 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 15639 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 15640 | |
| 15641 | rv = callback.WaitForResult(); |
| 15642 | EXPECT_EQ(OK, rv); |
| 15643 | |
| 15644 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 15645 | ASSERT_TRUE(response); |
| 15646 | ASSERT_TRUE(response->headers.get()); |
| 15647 | |
| 15648 | EXPECT_EQ(101, response->headers->response_code()); |
| 15649 | |
| 15650 | trans.reset(); |
| 15651 | session->CloseAllConnections(); |
| 15652 | } |
| 15653 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15654 | TEST_P(HttpNetworkTransactionTest, TotalNetworkBytesPost) { |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15655 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 15656 | element_readers.push_back( |
| 15657 | make_scoped_ptr(new UploadBytesElementReader("foo", 3))); |
| 15658 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15659 | |
| 15660 | HttpRequestInfo request; |
| 15661 | request.method = "POST"; |
| 15662 | request.url = GURL("http://www.foo.com/"); |
| 15663 | request.upload_data_stream = &upload_data_stream; |
| 15664 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15665 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15666 | scoped_ptr<HttpTransaction> trans( |
| 15667 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 15668 | MockWrite data_writes[] = { |
| 15669 | MockWrite("POST / HTTP/1.1\r\n" |
| 15670 | "Host: www.foo.com\r\n" |
| 15671 | "Connection: keep-alive\r\n" |
| 15672 | "Content-Length: 3\r\n\r\n"), |
| 15673 | MockWrite("foo"), |
| 15674 | }; |
| 15675 | |
| 15676 | MockRead data_reads[] = { |
| 15677 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 15678 | MockRead(SYNCHRONOUS, OK), |
| 15679 | }; |
| 15680 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15681 | arraysize(data_writes)); |
| 15682 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15683 | |
| 15684 | TestCompletionCallback callback; |
| 15685 | |
| 15686 | EXPECT_EQ(ERR_IO_PENDING, |
| 15687 | trans->Start(&request, callback.callback(), BoundNetLog())); |
| 15688 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 15689 | |
| 15690 | std::string response_data; |
| 15691 | EXPECT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 15692 | |
| 15693 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
| 15694 | trans->GetTotalSentBytes()); |
| 15695 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
| 15696 | trans->GetTotalReceivedBytes()); |
| 15697 | } |
| 15698 | |
| 15699 | TEST_P(HttpNetworkTransactionTest, TotalNetworkBytesPost100Continue) { |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15700 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 15701 | element_readers.push_back( |
| 15702 | make_scoped_ptr(new UploadBytesElementReader("foo", 3))); |
| 15703 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15704 | |
| 15705 | HttpRequestInfo request; |
| 15706 | request.method = "POST"; |
| 15707 | request.url = GURL("http://www.foo.com/"); |
| 15708 | request.upload_data_stream = &upload_data_stream; |
| 15709 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15710 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15711 | scoped_ptr<HttpTransaction> trans( |
| 15712 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 15713 | MockWrite data_writes[] = { |
| 15714 | MockWrite("POST / HTTP/1.1\r\n" |
| 15715 | "Host: www.foo.com\r\n" |
| 15716 | "Connection: keep-alive\r\n" |
| 15717 | "Content-Length: 3\r\n\r\n"), |
| 15718 | MockWrite("foo"), |
| 15719 | }; |
| 15720 | |
| 15721 | MockRead data_reads[] = { |
| 15722 | MockRead("HTTP/1.1 100 Continue\r\n\r\n"), |
| 15723 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 15724 | MockRead(SYNCHRONOUS, OK), |
| 15725 | }; |
| 15726 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15727 | arraysize(data_writes)); |
| 15728 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15729 | |
| 15730 | TestCompletionCallback callback; |
| 15731 | |
| 15732 | EXPECT_EQ(ERR_IO_PENDING, |
| 15733 | trans->Start(&request, callback.callback(), BoundNetLog())); |
| 15734 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 15735 | |
| 15736 | std::string response_data; |
| 15737 | EXPECT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 15738 | |
| 15739 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
| 15740 | trans->GetTotalSentBytes()); |
| 15741 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
| 15742 | trans->GetTotalReceivedBytes()); |
| 15743 | } |
| 15744 | |
| 15745 | TEST_P(HttpNetworkTransactionTest, TotalNetworkBytesChunkedPost) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15746 | ChunkedUploadDataStream upload_data_stream(0); |
| 15747 | |
| 15748 | HttpRequestInfo request; |
| 15749 | request.method = "POST"; |
| 15750 | request.url = GURL("http://www.foo.com/"); |
| 15751 | request.upload_data_stream = &upload_data_stream; |
| 15752 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15753 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15754 | scoped_ptr<HttpTransaction> trans( |
| 15755 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 15756 | // Send headers successfully, but get an error while sending the body. |
| 15757 | MockWrite data_writes[] = { |
| 15758 | MockWrite("POST / HTTP/1.1\r\n" |
| 15759 | "Host: www.foo.com\r\n" |
| 15760 | "Connection: keep-alive\r\n" |
| 15761 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 15762 | MockWrite("1\r\nf\r\n"), MockWrite("2\r\noo\r\n"), MockWrite("0\r\n\r\n"), |
| 15763 | }; |
| 15764 | |
| 15765 | MockRead data_reads[] = { |
| 15766 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 15767 | MockRead(SYNCHRONOUS, OK), |
| 15768 | }; |
| 15769 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15770 | arraysize(data_writes)); |
| 15771 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15772 | |
| 15773 | TestCompletionCallback callback; |
| 15774 | |
| 15775 | EXPECT_EQ(ERR_IO_PENDING, |
| 15776 | trans->Start(&request, callback.callback(), BoundNetLog())); |
| 15777 | |
| 15778 | base::RunLoop().RunUntilIdle(); |
| 15779 | upload_data_stream.AppendData("f", 1, false); |
| 15780 | |
| 15781 | base::RunLoop().RunUntilIdle(); |
| 15782 | upload_data_stream.AppendData("oo", 2, true); |
| 15783 | |
| 15784 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 15785 | |
| 15786 | std::string response_data; |
| 15787 | EXPECT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 15788 | |
| 15789 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
| 15790 | trans->GetTotalSentBytes()); |
| 15791 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
| 15792 | trans->GetTotalReceivedBytes()); |
| 15793 | } |
| 15794 | |
bnc | f458840 | 2015-11-24 13:33:18 | [diff] [blame] | 15795 | TEST_P(HttpNetworkTransactionTest, EnableNPN) { |
| 15796 | session_deps_.next_protos = NextProtosDefaults(); |
| 15797 | session_deps_.enable_npn = true; |
| 15798 | |
| 15799 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 15800 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 15801 | |
| 15802 | EXPECT_THAT(trans.server_ssl_config_.alpn_protos, |
| 15803 | testing::ElementsAre(kProtoHTTP2, kProtoSPDY31, kProtoHTTP11)); |
| 15804 | EXPECT_THAT(trans.server_ssl_config_.npn_protos, |
| 15805 | testing::ElementsAre(kProtoHTTP2, kProtoSPDY31, kProtoHTTP11)); |
| 15806 | } |
| 15807 | |
| 15808 | TEST_P(HttpNetworkTransactionTest, DisableNPN) { |
| 15809 | session_deps_.next_protos = NextProtosDefaults(); |
| 15810 | session_deps_.enable_npn = false; |
| 15811 | |
| 15812 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 15813 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 15814 | |
| 15815 | EXPECT_THAT(trans.server_ssl_config_.alpn_protos, |
| 15816 | testing::ElementsAre(kProtoHTTP2, kProtoSPDY31, kProtoHTTP11)); |
| 15817 | EXPECT_TRUE(trans.server_ssl_config_.npn_protos.empty()); |
| 15818 | } |
| 15819 | |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 15820 | #if !defined(OS_IOS) |
| 15821 | TEST_P(HttpNetworkTransactionTest, TokenBindingSpdy) { |
| 15822 | const std::string https_url = "https://www.example.com"; |
| 15823 | HttpRequestInfo request; |
| 15824 | request.url = GURL(https_url); |
| 15825 | request.method = "GET"; |
| 15826 | |
| 15827 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 15828 | ssl.token_binding_negotiated = true; |
| 15829 | ssl.token_binding_key_param = TB_PARAM_ECDSAP256; |
| 15830 | ssl.SetNextProto(GetProtocol()); |
| 15831 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 15832 | |
| 15833 | scoped_ptr<SpdyFrame> resp( |
| 15834 | spdy_util_.ConstructSpdyGetSynReply(nullptr, 0, 1)); |
| 15835 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 15836 | MockRead reads[] = {CreateMockRead(*resp), CreateMockRead(*body), |
| 15837 | MockRead(ASYNC, ERR_IO_PENDING)}; |
| 15838 | StaticSocketDataProvider data(reads, arraysize(reads), nullptr, 0); |
| 15839 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15840 | session_deps_.channel_id_service.reset(new ChannelIDService( |
| 15841 | new DefaultChannelIDStore(nullptr), base::ThreadTaskRunnerHandle::Get())); |
| 15842 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 15843 | |
| 15844 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 15845 | TestCompletionCallback callback; |
| 15846 | EXPECT_EQ(ERR_IO_PENDING, |
| 15847 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 15848 | base::MessageLoop::current()->RunUntilIdle(); |
| 15849 | |
| 15850 | EXPECT_TRUE(trans.GetResponseInfo()->was_fetched_via_spdy); |
| 15851 | HttpRequestHeaders headers; |
| 15852 | ASSERT_TRUE(trans.GetFullRequestHeaders(&headers)); |
| 15853 | EXPECT_TRUE(headers.HasHeader(HttpRequestHeaders::kTokenBinding)); |
| 15854 | } |
| 15855 | #endif // !defined(OS_IOS) |
| 15856 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 15857 | } // namespace net |