[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> |
| 10 | |
[email protected] | 5285d97 | 2011-10-18 18:56:34 | [diff] [blame] | 11 | #include <string> |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 12 | #include <vector> |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 13 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 14 | #include "base/basictypes.h" |
[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" |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 20 | #include "base/memory/scoped_ptr.h" |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 21 | #include "base/memory/weak_ptr.h" |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 22 | #include "base/run_loop.h" |
[email protected] | 125ef48 | 2013-06-11 18:32:47 | [diff] [blame] | 23 | #include "base/strings/string_util.h" |
[email protected] | 750b2f3c | 2013-06-07 18:41:05 | [diff] [blame] | 24 | #include "base/strings/utf_string_conversions.h" |
[email protected] | f36a813 | 2011-09-02 18:36:33 | [diff] [blame] | 25 | #include "base/test/test_file_util.h" |
skyostil | 4891b25b | 2015-06-11 11:43:45 | [diff] [blame] | 26 | #include "base/thread_task_runner_handle.h" |
[email protected] | 277d594 | 2010-08-11 21:02:35 | [diff] [blame] | 27 | #include "net/base/auth.h" |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 28 | #include "net/base/chunked_upload_data_stream.h" |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 29 | #include "net/base/completion_callback.h" |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 30 | #include "net/base/elements_upload_data_stream.h" |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 31 | #include "net/base/load_timing_info.h" |
| 32 | #include "net/base/load_timing_info_test_util.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 33 | #include "net/base/net_errors.h" |
[email protected] | ac790b4 | 2009-12-02 04:31:31 | [diff] [blame] | 34 | #include "net/base/request_priority.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 35 | #include "net/base/test_completion_callback.h" |
[email protected] | 42fdb45 | 2012-11-01 12:44:40 | [diff] [blame] | 36 | #include "net/base/test_data_directory.h" |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 37 | #include "net/base/upload_bytes_element_reader.h" |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 38 | #include "net/base/upload_file_element_reader.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 39 | #include "net/cert/mock_cert_verifier.h" |
[email protected] | bc71b877 | 2013-04-10 20:55:16 | [diff] [blame] | 40 | #include "net/dns/host_cache.h" |
[email protected] | f2cb3cf | 2013-03-21 01:40:53 | [diff] [blame] | 41 | #include "net/dns/mock_host_resolver.h" |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 42 | #include "net/http/http_auth_challenge_tokenizer.h" |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 43 | #include "net/http/http_auth_handler_digest.h" |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 44 | #include "net/http/http_auth_handler_mock.h" |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 45 | #include "net/http/http_auth_handler_ntlm.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 46 | #include "net/http/http_basic_state.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 47 | #include "net/http/http_basic_stream.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 48 | #include "net/http/http_network_session.h" |
[email protected] | 87bfa3f | 2010-09-30 14:54:56 | [diff] [blame] | 49 | #include "net/http/http_network_session_peer.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 50 | #include "net/http/http_request_headers.h" |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 51 | #include "net/http/http_server_properties_impl.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 52 | #include "net/http/http_stream.h" |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 53 | #include "net/http/http_stream_factory.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 54 | #include "net/http/http_stream_parser.h" |
[email protected] | c41737d | 2014-05-14 07:47:19 | [diff] [blame] | 55 | #include "net/http/http_transaction_test_util.h" |
eroman | 87c53d6 | 2015-04-02 06:51:07 | [diff] [blame] | 56 | #include "net/log/net_log.h" |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 57 | #include "net/log/test_net_log.h" |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 58 | #include "net/log/test_net_log_entry.h" |
| 59 | #include "net/log/test_net_log_util.h" |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 60 | #include "net/proxy/mock_proxy_resolver.h" |
[email protected] | 51fff29d | 2008-12-19 22:17:53 | [diff] [blame] | 61 | #include "net/proxy/proxy_config_service_fixed.h" |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 62 | #include "net/proxy/proxy_info.h" |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 63 | #include "net/proxy/proxy_resolver.h" |
| 64 | #include "net/proxy/proxy_service.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 65 | #include "net/socket/client_socket_factory.h" |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 66 | #include "net/socket/client_socket_pool_manager.h" |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 67 | #include "net/socket/connection_attempts.h" |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 68 | #include "net/socket/mock_client_socket_pool_manager.h" |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 69 | #include "net/socket/next_proto.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 70 | #include "net/socket/socket_test_util.h" |
| 71 | #include "net/socket/ssl_client_socket.h" |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 72 | #include "net/spdy/spdy_framer.h" |
| 73 | #include "net/spdy/spdy_session.h" |
| 74 | #include "net/spdy/spdy_session_pool.h" |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 75 | #include "net/spdy/spdy_test_util_common.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 76 | #include "net/ssl/ssl_cert_request_info.h" |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 77 | #include "net/ssl/ssl_config_service.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 78 | #include "net/ssl/ssl_config_service_defaults.h" |
| 79 | #include "net/ssl/ssl_info.h" |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 80 | #include "net/ssl/ssl_private_key.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 81 | #include "net/test/cert_test_util.h" |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 82 | #include "net/websockets/websocket_handshake_stream_base.h" |
bnc | f458840 | 2015-11-24 13:33:18 | [diff] [blame] | 83 | #include "testing/gmock/include/gmock/gmock.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 84 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | 23887f04f | 2008-12-02 19:20:15 | [diff] [blame] | 85 | #include "testing/platform_test.h" |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 86 | #include "url/gurl.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 87 | |
[email protected] | ad65a3e | 2013-12-25 18:18:01 | [diff] [blame] | 88 | using base::ASCIIToUTF16; |
| 89 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 90 | //----------------------------------------------------------------------------- |
| 91 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 92 | namespace net { |
| 93 | |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 94 | namespace { |
| 95 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 96 | enum TestCase { |
| 97 | // Test using the SPDY/3.1 protocol. |
| 98 | kTestCaseSPDY31, |
| 99 | |
| 100 | // Test using the HTTP/2 protocol, without specifying a stream |
| 101 | // dependency based on the RequestPriority. |
| 102 | kTestCaseHTTP2NoPriorityDependencies, |
| 103 | |
| 104 | // Test using the HTTP/2 protocol, specifying a stream |
| 105 | // dependency based on the RequestPriority. |
| 106 | kTestCaseHTTP2PriorityDependencies |
| 107 | }; |
| 108 | |
[email protected] | 42cba2fb | 2013-03-29 19:58:57 | [diff] [blame] | 109 | const base::string16 kBar(ASCIIToUTF16("bar")); |
| 110 | const base::string16 kBar2(ASCIIToUTF16("bar2")); |
| 111 | const base::string16 kBar3(ASCIIToUTF16("bar3")); |
| 112 | const base::string16 kBaz(ASCIIToUTF16("baz")); |
| 113 | const base::string16 kFirst(ASCIIToUTF16("first")); |
| 114 | const base::string16 kFoo(ASCIIToUTF16("foo")); |
| 115 | const base::string16 kFoo2(ASCIIToUTF16("foo2")); |
| 116 | const base::string16 kFoo3(ASCIIToUTF16("foo3")); |
| 117 | const base::string16 kFou(ASCIIToUTF16("fou")); |
| 118 | const base::string16 kSecond(ASCIIToUTF16("second")); |
| 119 | const base::string16 kTestingNTLM(ASCIIToUTF16("testing-ntlm")); |
| 120 | const base::string16 kWrongPassword(ASCIIToUTF16("wrongpassword")); |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 121 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 122 | int GetIdleSocketCountInTransportSocketPool(HttpNetworkSession* session) { |
| 123 | return session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 124 | ->IdleSocketCount(); |
[email protected] | e5c02664 | 2012-03-17 00:14:02 | [diff] [blame] | 125 | } |
| 126 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 127 | int GetIdleSocketCountInSSLSocketPool(HttpNetworkSession* session) { |
| 128 | return session->GetSSLSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 129 | ->IdleSocketCount(); |
[email protected] | e5c02664 | 2012-03-17 00:14:02 | [diff] [blame] | 130 | } |
| 131 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 132 | bool IsTransportSocketPoolStalled(HttpNetworkSession* session) { |
| 133 | return session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 134 | ->IsStalled(); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 135 | } |
| 136 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 137 | // Takes in a Value created from a NetLogHttpResponseParameter, and returns |
| 138 | // a JSONified list of headers as a single string. Uses single quotes instead |
| 139 | // of double quotes for easier comparison. Returns false on failure. |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 140 | bool GetHeaders(base::DictionaryValue* params, std::string* headers) { |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 141 | if (!params) |
| 142 | return false; |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 143 | base::ListValue* header_list; |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 144 | if (!params->GetList("headers", &header_list)) |
| 145 | return false; |
| 146 | std::string double_quote_headers; |
estade | 8d04646 | 2015-05-16 01:02:34 | [diff] [blame] | 147 | base::JSONWriter::Write(*header_list, &double_quote_headers); |
[email protected] | 466c986 | 2013-12-03 22:05:28 | [diff] [blame] | 148 | base::ReplaceChars(double_quote_headers, "\"", "'", headers); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 149 | return true; |
| 150 | } |
| 151 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 152 | // Tests LoadTimingInfo in the case a socket is reused and no PAC script is |
| 153 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 154 | void TestLoadTimingReused(const LoadTimingInfo& load_timing_info) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 155 | EXPECT_TRUE(load_timing_info.socket_reused); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 156 | EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 157 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 158 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 159 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 160 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 161 | ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 162 | EXPECT_FALSE(load_timing_info.send_start.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 163 | |
| 164 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 165 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 166 | // Set at a higher level. |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 167 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 168 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 169 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 170 | } |
| 171 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 172 | // Tests LoadTimingInfo in the case a new socket is used and no PAC script is |
| 173 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 174 | void TestLoadTimingNotReused(const LoadTimingInfo& load_timing_info, |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 175 | int connect_timing_flags) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 176 | EXPECT_FALSE(load_timing_info.socket_reused); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 177 | EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 178 | |
| 179 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 180 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 181 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 182 | ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 183 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 184 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 185 | load_timing_info.send_start); |
| 186 | |
| 187 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 188 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 189 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 190 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 191 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 192 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | // Tests LoadTimingInfo in the case a socket is reused and a PAC script is |
| 196 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 197 | void TestLoadTimingReusedWithPac(const LoadTimingInfo& load_timing_info) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 198 | EXPECT_TRUE(load_timing_info.socket_reused); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 199 | EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 200 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 201 | ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 202 | |
| 203 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 204 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 205 | load_timing_info.proxy_resolve_end); |
| 206 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 207 | load_timing_info.send_start); |
| 208 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 209 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 210 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 211 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 212 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 213 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | // Tests LoadTimingInfo in the case a new socket is used and a PAC script is |
| 217 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 218 | void TestLoadTimingNotReusedWithPac(const LoadTimingInfo& load_timing_info, |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 219 | int connect_timing_flags) { |
| 220 | EXPECT_FALSE(load_timing_info.socket_reused); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 221 | EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 222 | |
| 223 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 224 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 225 | load_timing_info.proxy_resolve_end); |
| 226 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 227 | load_timing_info.connect_timing.connect_start); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 228 | ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 229 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 230 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 231 | load_timing_info.send_start); |
| 232 | |
| 233 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 234 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 235 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 236 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 237 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 238 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 239 | } |
| 240 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 241 | void AddWebSocketHeaders(HttpRequestHeaders* headers) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 242 | headers->SetHeader("Connection", "Upgrade"); |
| 243 | headers->SetHeader("Upgrade", "websocket"); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 244 | headers->SetHeader("Origin", "http://www.example.org"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 245 | headers->SetHeader("Sec-WebSocket-Version", "13"); |
| 246 | headers->SetHeader("Sec-WebSocket-Key", "dGhlIHNhbXBsZSBub25jZQ=="); |
| 247 | } |
| 248 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 249 | scoped_ptr<HttpNetworkSession> CreateSession( |
| 250 | SpdySessionDependencies* session_deps) { |
[email protected] | c6bf815 | 2012-12-02 07:43:34 | [diff] [blame] | 251 | return SpdySessionDependencies::SpdyCreateSession(session_deps); |
[email protected] | e8d53619 | 2008-10-17 22:21:14 | [diff] [blame] | 252 | } |
| 253 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 254 | } // namespace |
| 255 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 256 | class HttpNetworkTransactionTest |
| 257 | : public PlatformTest, |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 258 | public ::testing::WithParamInterface<TestCase> { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 259 | public: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 260 | virtual ~HttpNetworkTransactionTest() { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 261 | // Important to restore the per-pool limit first, since the pool limit must |
| 262 | // always be greater than group limit, and the tests reduce both limits. |
| 263 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 264 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_pool_sockets_); |
| 265 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 266 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_group_sockets_); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 267 | SpdySession::SetPriorityDependencyDefaultForTesting(false); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 268 | } |
| 269 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 270 | protected: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 271 | HttpNetworkTransactionTest() |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 272 | : spdy_util_(GetProtocol(), GetDependenciesFromPriority()), |
| 273 | session_deps_(GetProtocol()), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 274 | old_max_group_sockets_(ClientSocketPoolManager::max_sockets_per_group( |
| 275 | HttpNetworkSession::NORMAL_SOCKET_POOL)), |
| 276 | old_max_pool_sockets_(ClientSocketPoolManager::max_sockets_per_pool( |
| 277 | HttpNetworkSession::NORMAL_SOCKET_POOL)) { |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 278 | SpdySession::SetPriorityDependencyDefaultForTesting( |
| 279 | GetDependenciesFromPriority()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 280 | } |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 281 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 282 | struct SimpleGetHelperResult { |
| 283 | int rv; |
| 284 | std::string status_line; |
| 285 | std::string response_data; |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 286 | int64_t total_received_bytes; |
| 287 | int64_t total_sent_bytes; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 288 | LoadTimingInfo load_timing_info; |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 289 | ConnectionAttempts connection_attempts; |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 290 | IPEndPoint remote_endpoint_after_start; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 291 | }; |
| 292 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 293 | void SetUp() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 294 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 295 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 296 | } |
| 297 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 298 | void TearDown() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 299 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 300 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 301 | // Empty the current queue. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 302 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 303 | PlatformTest::TearDown(); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 304 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 305 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 306 | } |
| 307 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 308 | NextProto GetProtocol() const { |
| 309 | return GetParam() == kTestCaseSPDY31 ? kProtoSPDY31 : kProtoHTTP2; |
| 310 | } |
| 311 | |
| 312 | bool GetDependenciesFromPriority() const { |
| 313 | return GetParam() == kTestCaseHTTP2PriorityDependencies; |
| 314 | } |
| 315 | |
bnc | 33b8cef4 | 2014-11-19 17:30:38 | [diff] [blame] | 316 | const char* GetAlternateProtocolFromParam() { |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 317 | return AlternateProtocolToString( |
| 318 | AlternateProtocolFromNextProto(GetProtocol())); |
bnc | 33b8cef4 | 2014-11-19 17:30:38 | [diff] [blame] | 319 | } |
| 320 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 321 | std::string GetAlternativeServiceHttpHeader() { |
| 322 | return std::string("Alt-Svc: ") + GetAlternateProtocolFromParam() + |
| 323 | "=\"www.example.com:443\"\r\n"; |
| 324 | } |
| 325 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 326 | std::string GetAlternateProtocolHttpHeader() { |
bnc | 33b8cef4 | 2014-11-19 17:30:38 | [diff] [blame] | 327 | return std::string("Alternate-Protocol: 443:") + |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 328 | GetAlternateProtocolFromParam() + "\r\n"; |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 329 | } |
| 330 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 331 | // Either |write_failure| specifies a write failure or |read_failure| |
| 332 | // specifies a read failure when using a reused socket. In either case, the |
| 333 | // failure should cause the network transaction to resend the request, and the |
| 334 | // other argument should be NULL. |
| 335 | void KeepAliveConnectionResendRequestTest(const MockWrite* write_failure, |
| 336 | const MockRead* read_failure); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 337 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 338 | // Either |write_failure| specifies a write failure or |read_failure| |
| 339 | // specifies a read failure when using a reused socket. In either case, the |
| 340 | // failure should cause the network transaction to resend the request, and the |
| 341 | // other argument should be NULL. |
| 342 | void PreconnectErrorResendRequestTest(const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 343 | const MockRead* read_failure, |
| 344 | bool use_spdy); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 345 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 346 | SimpleGetHelperResult SimpleGetHelperForData(StaticSocketDataProvider* data[], |
| 347 | size_t data_count) { |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 348 | SimpleGetHelperResult out; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 349 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 350 | HttpRequestInfo request; |
| 351 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 352 | request.url = GURL("http://www.example.org/"); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 353 | request.load_flags = 0; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 354 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 355 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 356 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 357 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 358 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 359 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 360 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 361 | for (size_t i = 0; i < data_count; ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 362 | session_deps_.socket_factory->AddSocketDataProvider(data[i]); |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 363 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 364 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 365 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 366 | |
eroman | 24bc6a1 | 2015-05-06 19:55:48 | [diff] [blame] | 367 | EXPECT_TRUE(log.bound().IsCapturing()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 368 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 369 | EXPECT_EQ(ERR_IO_PENDING, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 370 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 371 | out.rv = callback.WaitForResult(); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 372 | out.total_received_bytes = trans->GetTotalReceivedBytes(); |
| 373 | out.total_sent_bytes = trans->GetTotalSentBytes(); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 374 | |
| 375 | // Even in the failure cases that use this function, connections are always |
| 376 | // successfully established before the error. |
| 377 | EXPECT_TRUE(trans->GetLoadTimingInfo(&out.load_timing_info)); |
| 378 | TestLoadTimingNotReused(out.load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 379 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 380 | if (out.rv != OK) |
| 381 | return out; |
| 382 | |
| 383 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 384 | // Can't use ASSERT_* inside helper functions like this, so |
| 385 | // return an error. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 386 | if (response == NULL || response->headers.get() == NULL) { |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 387 | out.rv = ERR_UNEXPECTED; |
| 388 | return out; |
| 389 | } |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 390 | out.status_line = response->headers->GetStatusLine(); |
| 391 | |
[email protected] | 80a09a8 | 2012-11-16 17:40:06 | [diff] [blame] | 392 | EXPECT_EQ("127.0.0.1", response->socket_address.host()); |
| 393 | EXPECT_EQ(80, response->socket_address.port()); |
[email protected] | 6d81b48 | 2011-02-22 19:47:19 | [diff] [blame] | 394 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 395 | bool got_endpoint = |
| 396 | trans->GetRemoteEndpoint(&out.remote_endpoint_after_start); |
| 397 | EXPECT_EQ(got_endpoint, |
| 398 | out.remote_endpoint_after_start.address().size() > 0); |
| 399 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 400 | rv = ReadTransaction(trans.get(), &out.response_data); |
| 401 | EXPECT_EQ(OK, rv); |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 402 | |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 403 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 404 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 405 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 406 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST_HEADERS, |
[email protected] | 169d001 | 2010-05-10 23:20:12 | [diff] [blame] | 407 | NetLog::PHASE_NONE); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 408 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 409 | entries, pos, |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 410 | NetLog::TYPE_HTTP_TRANSACTION_READ_RESPONSE_HEADERS, |
| 411 | NetLog::PHASE_NONE); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 412 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 413 | std::string line; |
| 414 | EXPECT_TRUE(entries[pos].GetStringValue("line", &line)); |
| 415 | EXPECT_EQ("GET / HTTP/1.1\r\n", line); |
| 416 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 417 | HttpRequestHeaders request_headers; |
| 418 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 419 | std::string value; |
| 420 | EXPECT_TRUE(request_headers.GetHeader("Host", &value)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 421 | EXPECT_EQ("www.example.org", value); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 422 | EXPECT_TRUE(request_headers.GetHeader("Connection", &value)); |
| 423 | EXPECT_EQ("keep-alive", value); |
| 424 | |
| 425 | std::string response_headers; |
| 426 | EXPECT_TRUE(GetHeaders(entries[pos].params.get(), &response_headers)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 427 | EXPECT_EQ("['Host: www.example.org','Connection: keep-alive']", |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 428 | response_headers); |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 429 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 430 | out.total_received_bytes = trans->GetTotalReceivedBytes(); |
| 431 | // The total number of sent bytes should not have changed. |
| 432 | EXPECT_EQ(out.total_sent_bytes, trans->GetTotalSentBytes()); |
| 433 | |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 434 | trans->GetConnectionAttempts(&out.connection_attempts); |
[email protected] | aecfbf2 | 2008-10-16 02:02:47 | [diff] [blame] | 435 | return out; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 436 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 437 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 438 | SimpleGetHelperResult SimpleGetHelper(MockRead data_reads[], |
| 439 | size_t reads_count) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 440 | MockWrite data_writes[] = { |
| 441 | MockWrite("GET / HTTP/1.1\r\n" |
| 442 | "Host: www.example.org\r\n" |
| 443 | "Connection: keep-alive\r\n\r\n"), |
| 444 | }; |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 445 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 446 | StaticSocketDataProvider reads(data_reads, reads_count, data_writes, |
| 447 | arraysize(data_writes)); |
| 448 | StaticSocketDataProvider* data[] = {&reads}; |
| 449 | SimpleGetHelperResult out = SimpleGetHelperForData(data, 1); |
| 450 | |
| 451 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
| 452 | out.total_sent_bytes); |
| 453 | return out; |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 454 | } |
| 455 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 456 | void ConnectStatusHelperWithExpectedStatus(const MockRead& status, |
| 457 | int expected_status); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 458 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 459 | void ConnectStatusHelper(const MockRead& status); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 460 | |
| 461 | void BypassHostCacheOnRefreshHelper(int load_flags); |
| 462 | |
| 463 | void CheckErrorIsPassedBack(int error, IoMode mode); |
| 464 | |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 465 | SpdyTestUtil spdy_util_; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 466 | SpdySessionDependencies session_deps_; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 467 | |
| 468 | // Original socket limits. Some tests set these. Safest to always restore |
| 469 | // them once each test has been run. |
| 470 | int old_max_group_sockets_; |
| 471 | int old_max_pool_sockets_; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 472 | }; |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 473 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 474 | INSTANTIATE_TEST_CASE_P(ProtoPlusDepend, |
bnc | 57685ae6 | 2015-03-10 21:27:20 | [diff] [blame] | 475 | HttpNetworkTransactionTest, |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 476 | testing::Values(kTestCaseSPDY31, |
| 477 | kTestCaseHTTP2NoPriorityDependencies, |
| 478 | kTestCaseHTTP2PriorityDependencies)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 479 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 480 | namespace { |
| 481 | |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 482 | class BeforeNetworkStartHandler { |
| 483 | public: |
| 484 | explicit BeforeNetworkStartHandler(bool defer) |
| 485 | : defer_on_before_network_start_(defer), |
| 486 | observed_before_network_start_(false) {} |
| 487 | |
| 488 | void OnBeforeNetworkStart(bool* defer) { |
| 489 | *defer = defer_on_before_network_start_; |
| 490 | observed_before_network_start_ = true; |
| 491 | } |
| 492 | |
| 493 | bool observed_before_network_start() const { |
| 494 | return observed_before_network_start_; |
| 495 | } |
| 496 | |
| 497 | private: |
| 498 | const bool defer_on_before_network_start_; |
| 499 | bool observed_before_network_start_; |
| 500 | |
| 501 | DISALLOW_COPY_AND_ASSIGN(BeforeNetworkStartHandler); |
| 502 | }; |
| 503 | |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 504 | class BeforeProxyHeadersSentHandler { |
| 505 | public: |
| 506 | BeforeProxyHeadersSentHandler() |
| 507 | : observed_before_proxy_headers_sent_(false) {} |
| 508 | |
[email protected] | 1252d42f | 2014-07-01 21:20:20 | [diff] [blame] | 509 | void OnBeforeProxyHeadersSent(const ProxyInfo& proxy_info, |
| 510 | HttpRequestHeaders* request_headers) { |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 511 | observed_before_proxy_headers_sent_ = true; |
| 512 | observed_proxy_server_uri_ = proxy_info.proxy_server().ToURI(); |
| 513 | } |
| 514 | |
| 515 | bool observed_before_proxy_headers_sent() const { |
| 516 | return observed_before_proxy_headers_sent_; |
| 517 | } |
| 518 | |
| 519 | std::string observed_proxy_server_uri() const { |
| 520 | return observed_proxy_server_uri_; |
| 521 | } |
| 522 | |
| 523 | private: |
| 524 | bool observed_before_proxy_headers_sent_; |
| 525 | std::string observed_proxy_server_uri_; |
| 526 | |
| 527 | DISALLOW_COPY_AND_ASSIGN(BeforeProxyHeadersSentHandler); |
| 528 | }; |
| 529 | |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 530 | // Fill |str| with a long header list that consumes >= |size| bytes. |
| 531 | void FillLargeHeadersString(std::string* str, int size) { |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 532 | const char row[] = |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 533 | "SomeHeaderName: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n"; |
| 534 | const int sizeof_row = strlen(row); |
| 535 | const int num_rows = static_cast<int>( |
| 536 | ceil(static_cast<float>(size) / sizeof_row)); |
| 537 | const int sizeof_data = num_rows * sizeof_row; |
| 538 | DCHECK(sizeof_data >= size); |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 539 | str->reserve(sizeof_data); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 540 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 541 | for (int i = 0; i < num_rows; ++i) |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 542 | str->append(row, sizeof_row); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 543 | } |
| 544 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 545 | #if defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 546 | // Alternative functions that eliminate randomness and dependency on the local |
| 547 | // host name so that the generated NTLM messages are reproducible. |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 548 | void MockGenerateRandom1(uint8* output, size_t n) { |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 549 | static const uint8 bytes[] = { |
| 550 | 0x55, 0x29, 0x66, 0x26, 0x6b, 0x9c, 0x73, 0x54 |
| 551 | }; |
| 552 | static size_t current_byte = 0; |
| 553 | for (size_t i = 0; i < n; ++i) { |
| 554 | output[i] = bytes[current_byte++]; |
| 555 | current_byte %= arraysize(bytes); |
| 556 | } |
| 557 | } |
| 558 | |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 559 | void MockGenerateRandom2(uint8* output, size_t n) { |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 560 | static const uint8 bytes[] = { |
| 561 | 0x96, 0x79, 0x85, 0xe7, 0x49, 0x93, 0x70, 0xa1, |
| 562 | 0x4e, 0xe7, 0x87, 0x45, 0x31, 0x5b, 0xd3, 0x1f |
| 563 | }; |
| 564 | static size_t current_byte = 0; |
| 565 | for (size_t i = 0; i < n; ++i) { |
| 566 | output[i] = bytes[current_byte++]; |
| 567 | current_byte %= arraysize(bytes); |
| 568 | } |
| 569 | } |
| 570 | |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 571 | std::string MockGetHostName() { |
| 572 | return "WTC-WIN7"; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 573 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 574 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 575 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 576 | template<typename ParentPool> |
| 577 | class CaptureGroupNameSocketPool : public ParentPool { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 578 | public: |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 579 | CaptureGroupNameSocketPool(HostResolver* host_resolver, |
| 580 | CertVerifier* cert_verifier); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 581 | |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 582 | const std::string last_group_name_received() const { |
| 583 | return last_group_name_; |
| 584 | } |
| 585 | |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 586 | int RequestSocket(const std::string& group_name, |
| 587 | const void* socket_params, |
| 588 | RequestPriority priority, |
| 589 | ClientSocketHandle* handle, |
| 590 | const CompletionCallback& callback, |
| 591 | const BoundNetLog& net_log) override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 592 | last_group_name_ = group_name; |
| 593 | return ERR_IO_PENDING; |
| 594 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 595 | void CancelRequest(const std::string& group_name, |
| 596 | ClientSocketHandle* handle) override {} |
| 597 | void ReleaseSocket(const std::string& group_name, |
| 598 | scoped_ptr<StreamSocket> socket, |
| 599 | int id) override {} |
| 600 | void CloseIdleSockets() override {} |
| 601 | int IdleSocketCount() const override { return 0; } |
| 602 | int IdleSocketCountInGroup(const std::string& group_name) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 603 | return 0; |
| 604 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 605 | LoadState GetLoadState(const std::string& group_name, |
| 606 | const ClientSocketHandle* handle) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 607 | return LOAD_STATE_IDLE; |
| 608 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 609 | base::TimeDelta ConnectionTimeout() const override { |
[email protected] | a796bcec | 2010-03-22 17:17:26 | [diff] [blame] | 610 | return base::TimeDelta(); |
| 611 | } |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 612 | |
| 613 | private: |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 614 | std::string last_group_name_; |
| 615 | }; |
| 616 | |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 617 | typedef CaptureGroupNameSocketPool<TransportClientSocketPool> |
| 618 | CaptureGroupNameTransportSocketPool; |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 619 | typedef CaptureGroupNameSocketPool<HttpProxyClientSocketPool> |
| 620 | CaptureGroupNameHttpProxySocketPool; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 621 | typedef CaptureGroupNameSocketPool<SOCKSClientSocketPool> |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 622 | CaptureGroupNameSOCKSSocketPool; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 623 | typedef CaptureGroupNameSocketPool<SSLClientSocketPool> |
| 624 | CaptureGroupNameSSLSocketPool; |
| 625 | |
rkaplow | d90695c | 2015-03-25 22:12:41 | [diff] [blame] | 626 | template <typename ParentPool> |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 627 | CaptureGroupNameSocketPool<ParentPool>::CaptureGroupNameSocketPool( |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 628 | HostResolver* host_resolver, |
| 629 | CertVerifier* /* cert_verifier */) |
rkaplow | d90695c | 2015-03-25 22:12:41 | [diff] [blame] | 630 | : ParentPool(0, 0, host_resolver, NULL, NULL) { |
| 631 | } |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 632 | |
hashimoto | 0d3e4fb | 2015-01-09 05:02:50 | [diff] [blame] | 633 | template <> |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 634 | CaptureGroupNameHttpProxySocketPool::CaptureGroupNameSocketPool( |
hashimoto | dae13b0 | 2015-01-15 04:28:21 | [diff] [blame] | 635 | HostResolver* /* host_resolver */, |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 636 | CertVerifier* /* cert_verifier */) |
rkaplow | d90695c | 2015-03-25 22:12:41 | [diff] [blame] | 637 | : HttpProxyClientSocketPool(0, 0, NULL, NULL, NULL) { |
hashimoto | 0d3e4fb | 2015-01-09 05:02:50 | [diff] [blame] | 638 | } |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 639 | |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 640 | template <> |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 641 | CaptureGroupNameSSLSocketPool::CaptureGroupNameSocketPool( |
hashimoto | dae13b0 | 2015-01-15 04:28:21 | [diff] [blame] | 642 | HostResolver* /* host_resolver */, |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 643 | CertVerifier* cert_verifier) |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 644 | : SSLClientSocketPool(0, |
| 645 | 0, |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 646 | cert_verifier, |
| 647 | NULL, |
| 648 | NULL, |
[email protected] | 284303b6 | 2013-11-28 15:11:54 | [diff] [blame] | 649 | NULL, |
eranm | 6571b2b | 2014-12-03 15:53:23 | [diff] [blame] | 650 | NULL, |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 651 | std::string(), |
| 652 | NULL, |
| 653 | NULL, |
| 654 | NULL, |
| 655 | NULL, |
| 656 | NULL, |
[email protected] | 8e45855 | 2014-08-05 00:02:15 | [diff] [blame] | 657 | NULL) { |
| 658 | } |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 659 | |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 660 | //----------------------------------------------------------------------------- |
| 661 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 662 | // Helper functions for validating that AuthChallengeInfo's are correctly |
| 663 | // configured for common cases. |
| 664 | bool CheckBasicServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 665 | if (!auth_challenge) |
| 666 | return false; |
| 667 | EXPECT_FALSE(auth_challenge->is_proxy); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 668 | EXPECT_EQ("www.example.org:80", auth_challenge->challenger.ToString()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 669 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
| 670 | EXPECT_EQ("basic", auth_challenge->scheme); |
| 671 | return true; |
| 672 | } |
| 673 | |
| 674 | bool CheckBasicProxyAuth(const AuthChallengeInfo* auth_challenge) { |
| 675 | if (!auth_challenge) |
| 676 | return false; |
| 677 | EXPECT_TRUE(auth_challenge->is_proxy); |
| 678 | EXPECT_EQ("myproxy:70", auth_challenge->challenger.ToString()); |
| 679 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
| 680 | EXPECT_EQ("basic", auth_challenge->scheme); |
| 681 | return true; |
| 682 | } |
| 683 | |
| 684 | bool CheckDigestServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 685 | if (!auth_challenge) |
| 686 | return false; |
| 687 | EXPECT_FALSE(auth_challenge->is_proxy); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 688 | EXPECT_EQ("www.example.org:80", auth_challenge->challenger.ToString()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 689 | EXPECT_EQ("digestive", auth_challenge->realm); |
| 690 | EXPECT_EQ("digest", auth_challenge->scheme); |
| 691 | return true; |
| 692 | } |
| 693 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 694 | #if defined(NTLM_PORTABLE) |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 695 | bool CheckNTLMServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 696 | if (!auth_challenge) |
| 697 | return false; |
| 698 | EXPECT_FALSE(auth_challenge->is_proxy); |
| 699 | EXPECT_EQ("172.22.68.17:80", auth_challenge->challenger.ToString()); |
| 700 | EXPECT_EQ(std::string(), auth_challenge->realm); |
| 701 | EXPECT_EQ("ntlm", auth_challenge->scheme); |
| 702 | return true; |
| 703 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 704 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 705 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 706 | } // namespace |
| 707 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 708 | TEST_P(HttpNetworkTransactionTest, Basic) { |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 709 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 710 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 711 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 712 | } |
| 713 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 714 | TEST_P(HttpNetworkTransactionTest, SimpleGET) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 715 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 716 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 717 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 718 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 719 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 720 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 721 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 722 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 723 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 724 | EXPECT_EQ("hello world", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 725 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 726 | EXPECT_EQ(reads_size, out.total_received_bytes); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 727 | EXPECT_EQ(0u, out.connection_attempts.size()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 728 | |
| 729 | EXPECT_FALSE(out.remote_endpoint_after_start.address().empty()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 730 | } |
| 731 | |
| 732 | // Response with no status line. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 733 | TEST_P(HttpNetworkTransactionTest, SimpleGETNoHeaders) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 734 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 735 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 736 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 737 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 738 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 739 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 740 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 741 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 742 | EXPECT_EQ("hello world", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 743 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 744 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 745 | } |
| 746 | |
| 747 | // Allow up to 4 bytes of junk to precede status line. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 748 | TEST_P(HttpNetworkTransactionTest, StatusLineJunk3Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 749 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 750 | MockRead("xxxHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 751 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 752 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 753 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 754 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 755 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 756 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 757 | EXPECT_EQ("DATA", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 758 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 759 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 760 | } |
| 761 | |
| 762 | // Allow up to 4 bytes of junk to precede status line. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 763 | TEST_P(HttpNetworkTransactionTest, StatusLineJunk4Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 764 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 765 | MockRead("\n\nQJHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 766 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 767 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 768 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 769 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 770 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 771 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 772 | EXPECT_EQ("DATA", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 773 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 774 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 775 | } |
| 776 | |
| 777 | // 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] | 778 | TEST_P(HttpNetworkTransactionTest, StatusLineJunk5Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 779 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 780 | MockRead("xxxxxHTTP/1.1 404 Not Found\nServer: blah"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 781 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 782 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 783 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 784 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 785 | EXPECT_EQ(OK, out.rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 786 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 787 | EXPECT_EQ("xxxxxHTTP/1.1 404 Not Found\nServer: blah", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 788 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 789 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 790 | } |
| 791 | |
| 792 | // Same as StatusLineJunk4Bytes, except the read chunks are smaller. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 793 | TEST_P(HttpNetworkTransactionTest, StatusLineJunk4Bytes_Slow) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 794 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 795 | MockRead("\n"), |
| 796 | MockRead("\n"), |
| 797 | MockRead("Q"), |
| 798 | MockRead("J"), |
| 799 | MockRead("HTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 800 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 801 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 802 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 803 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 804 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 805 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 806 | EXPECT_EQ("DATA", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 807 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 808 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 809 | } |
| 810 | |
| 811 | // Close the connection before enough bytes to have a status line. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 812 | TEST_P(HttpNetworkTransactionTest, StatusLinePartial) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 813 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 814 | MockRead("HTT"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 815 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 816 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 817 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 818 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 819 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 820 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 821 | EXPECT_EQ("HTT", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 822 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 823 | EXPECT_EQ(reads_size, out.total_received_bytes); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 824 | } |
| 825 | |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 826 | // Simulate a 204 response, lacking a Content-Length header, sent over a |
| 827 | // persistent connection. The response should still terminate since a 204 |
| 828 | // cannot have a response body. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 829 | TEST_P(HttpNetworkTransactionTest, StopsReading204) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 830 | char junk[] = "junk"; |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 831 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 832 | MockRead("HTTP/1.1 204 No Content\r\n\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 833 | MockRead(junk), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 834 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 835 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 836 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 837 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 838 | EXPECT_EQ(OK, out.rv); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 839 | EXPECT_EQ("HTTP/1.1 204 No Content", out.status_line); |
| 840 | EXPECT_EQ("", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 841 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 842 | int64_t response_size = reads_size - strlen(junk); |
| 843 | EXPECT_EQ(response_size, out.total_received_bytes); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 844 | } |
| 845 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 846 | // A simple request using chunked encoding with some extra data after. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 847 | TEST_P(HttpNetworkTransactionTest, ChunkedEncoding) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 848 | std::string final_chunk = "0\r\n\r\n"; |
| 849 | std::string extra_data = "HTTP/1.1 200 OK\r\n"; |
| 850 | std::string last_read = final_chunk + extra_data; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 851 | MockRead data_reads[] = { |
| 852 | MockRead("HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n"), |
| 853 | MockRead("5\r\nHello\r\n"), |
| 854 | MockRead("1\r\n"), |
| 855 | MockRead(" \r\n"), |
| 856 | MockRead("5\r\nworld\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 857 | MockRead(last_read.data()), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 858 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 859 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 860 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 861 | arraysize(data_reads)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 862 | EXPECT_EQ(OK, out.rv); |
| 863 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 864 | EXPECT_EQ("Hello world", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 865 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 866 | int64_t response_size = reads_size - extra_data.size(); |
| 867 | EXPECT_EQ(response_size, out.total_received_bytes); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 868 | } |
| 869 | |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 870 | // Next tests deal with http://crbug.com/56344. |
| 871 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 872 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 873 | MultipleContentLengthHeadersNoTransferEncoding) { |
| 874 | MockRead data_reads[] = { |
| 875 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 876 | MockRead("Content-Length: 10\r\n"), |
| 877 | MockRead("Content-Length: 5\r\n\r\n"), |
| 878 | }; |
| 879 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 880 | arraysize(data_reads)); |
| 881 | EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH, out.rv); |
| 882 | } |
| 883 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 884 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 885 | DuplicateContentLengthHeadersNoTransferEncoding) { |
| 886 | MockRead data_reads[] = { |
| 887 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 888 | MockRead("Content-Length: 5\r\n"), |
| 889 | MockRead("Content-Length: 5\r\n\r\n"), |
| 890 | MockRead("Hello"), |
| 891 | }; |
| 892 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 893 | arraysize(data_reads)); |
| 894 | EXPECT_EQ(OK, out.rv); |
| 895 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 896 | EXPECT_EQ("Hello", out.response_data); |
| 897 | } |
| 898 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 899 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 900 | ComplexContentLengthHeadersNoTransferEncoding) { |
| 901 | // More than 2 dupes. |
| 902 | { |
| 903 | MockRead data_reads[] = { |
| 904 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 905 | MockRead("Content-Length: 5\r\n"), |
| 906 | MockRead("Content-Length: 5\r\n"), |
| 907 | MockRead("Content-Length: 5\r\n\r\n"), |
| 908 | MockRead("Hello"), |
| 909 | }; |
| 910 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 911 | arraysize(data_reads)); |
| 912 | EXPECT_EQ(OK, out.rv); |
| 913 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 914 | EXPECT_EQ("Hello", out.response_data); |
| 915 | } |
| 916 | // HTTP/1.0 |
| 917 | { |
| 918 | MockRead data_reads[] = { |
| 919 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 920 | MockRead("Content-Length: 5\r\n"), |
| 921 | MockRead("Content-Length: 5\r\n"), |
| 922 | MockRead("Content-Length: 5\r\n\r\n"), |
| 923 | MockRead("Hello"), |
| 924 | }; |
| 925 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 926 | arraysize(data_reads)); |
| 927 | EXPECT_EQ(OK, out.rv); |
| 928 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 929 | EXPECT_EQ("Hello", out.response_data); |
| 930 | } |
| 931 | // 2 dupes and one mismatched. |
| 932 | { |
| 933 | MockRead data_reads[] = { |
| 934 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 935 | MockRead("Content-Length: 10\r\n"), |
| 936 | MockRead("Content-Length: 10\r\n"), |
| 937 | MockRead("Content-Length: 5\r\n\r\n"), |
| 938 | }; |
| 939 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 940 | arraysize(data_reads)); |
| 941 | EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH, out.rv); |
| 942 | } |
| 943 | } |
| 944 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 945 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 946 | MultipleContentLengthHeadersTransferEncoding) { |
| 947 | MockRead data_reads[] = { |
| 948 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 949 | MockRead("Content-Length: 666\r\n"), |
| 950 | MockRead("Content-Length: 1337\r\n"), |
| 951 | MockRead("Transfer-Encoding: chunked\r\n\r\n"), |
| 952 | MockRead("5\r\nHello\r\n"), |
| 953 | MockRead("1\r\n"), |
| 954 | MockRead(" \r\n"), |
| 955 | MockRead("5\r\nworld\r\n"), |
| 956 | MockRead("0\r\n\r\nHTTP/1.1 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 957 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 958 | }; |
| 959 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 960 | arraysize(data_reads)); |
| 961 | EXPECT_EQ(OK, out.rv); |
| 962 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 963 | EXPECT_EQ("Hello world", out.response_data); |
| 964 | } |
| 965 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 966 | // Next tests deal with http://crbug.com/98895. |
| 967 | |
| 968 | // Checks that a single Content-Disposition header results in no error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 969 | TEST_P(HttpNetworkTransactionTest, SingleContentDispositionHeader) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 970 | MockRead data_reads[] = { |
| 971 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 972 | MockRead("Content-Disposition: attachment;filename=\"salutations.txt\"r\n"), |
| 973 | MockRead("Content-Length: 5\r\n\r\n"), |
| 974 | MockRead("Hello"), |
| 975 | }; |
| 976 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 977 | arraysize(data_reads)); |
| 978 | EXPECT_EQ(OK, out.rv); |
| 979 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 980 | EXPECT_EQ("Hello", out.response_data); |
| 981 | } |
| 982 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 983 | // Checks that two identical Content-Disposition headers result in no error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 984 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 985 | TwoIdenticalContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 986 | MockRead data_reads[] = { |
| 987 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 988 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 989 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 990 | MockRead("Content-Length: 5\r\n\r\n"), |
| 991 | MockRead("Hello"), |
| 992 | }; |
| 993 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 994 | arraysize(data_reads)); |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 995 | EXPECT_EQ(OK, out.rv); |
| 996 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 997 | EXPECT_EQ("Hello", out.response_data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 998 | } |
| 999 | |
| 1000 | // Checks that two distinct Content-Disposition headers result in an error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1001 | TEST_P(HttpNetworkTransactionTest, TwoDistinctContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1002 | MockRead data_reads[] = { |
| 1003 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1004 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1005 | MockRead("Content-Disposition: attachment;filename=\"hi.txt\"r\n"), |
| 1006 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1007 | MockRead("Hello"), |
| 1008 | }; |
| 1009 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1010 | arraysize(data_reads)); |
| 1011 | EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION, out.rv); |
| 1012 | } |
| 1013 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1014 | // Checks that two identical Location headers result in no error. |
| 1015 | // Also tests Location header behavior. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1016 | TEST_P(HttpNetworkTransactionTest, TwoIdenticalLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1017 | MockRead data_reads[] = { |
| 1018 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 1019 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1020 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1021 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1022 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1023 | }; |
| 1024 | |
| 1025 | HttpRequestInfo request; |
| 1026 | request.method = "GET"; |
| 1027 | request.url = GURL("http://redirect.com/"); |
| 1028 | request.load_flags = 0; |
| 1029 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1030 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1031 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1032 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1033 | |
| 1034 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1035 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1036 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1037 | TestCompletionCallback callback; |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1038 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1039 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1040 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1041 | |
| 1042 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 1043 | |
| 1044 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1045 | ASSERT_TRUE(response != NULL && response->headers.get() != NULL); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1046 | EXPECT_EQ("HTTP/1.1 302 Redirect", response->headers->GetStatusLine()); |
| 1047 | std::string url; |
| 1048 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 1049 | EXPECT_EQ("http://good.com/", url); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 1050 | EXPECT_TRUE(response->proxy_server.IsEmpty()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1051 | } |
| 1052 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1053 | // Checks that two distinct Location headers result in an error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1054 | TEST_P(HttpNetworkTransactionTest, TwoDistinctLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1055 | MockRead data_reads[] = { |
| 1056 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 1057 | MockRead("Location: http://good.com/\r\n"), |
| 1058 | MockRead("Location: http://evil.com/\r\n"), |
| 1059 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1060 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1061 | }; |
| 1062 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1063 | arraysize(data_reads)); |
| 1064 | EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_LOCATION, out.rv); |
| 1065 | } |
| 1066 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1067 | // Do a request using the HEAD method. Verify that we don't try to read the |
| 1068 | // message body (since HEAD has none). |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1069 | TEST_P(HttpNetworkTransactionTest, Head) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1070 | HttpRequestInfo request; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1071 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1072 | request.url = GURL("http://www.example.org/"); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1073 | request.load_flags = 0; |
| 1074 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1075 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1076 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1077 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 1078 | BeforeProxyHeadersSentHandler proxy_headers_handler; |
| 1079 | trans->SetBeforeProxyHeadersSentCallback( |
| 1080 | base::Bind(&BeforeProxyHeadersSentHandler::OnBeforeProxyHeadersSent, |
| 1081 | base::Unretained(&proxy_headers_handler))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1082 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1083 | MockWrite data_writes1[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 1084 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 1085 | "Host: www.example.org\r\n" |
| 1086 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1087 | }; |
| 1088 | MockRead data_reads1[] = { |
| 1089 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 1090 | MockRead("Server: Blah\r\n"), |
| 1091 | MockRead("Content-Length: 1234\r\n\r\n"), |
| 1092 | |
| 1093 | // No response body because the test stops reading here. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1094 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1095 | }; |
| 1096 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1097 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 1098 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1099 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1100 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1101 | TestCompletionCallback callback1; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1102 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1103 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1104 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1105 | |
| 1106 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1107 | EXPECT_EQ(OK, rv); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1108 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1109 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1110 | ASSERT_TRUE(response != NULL); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1111 | |
| 1112 | // Check that the headers got parsed. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1113 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1114 | EXPECT_EQ(1234, response->headers->GetContentLength()); |
| 1115 | EXPECT_EQ("HTTP/1.1 404 Not Found", response->headers->GetStatusLine()); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 1116 | EXPECT_TRUE(response->proxy_server.IsEmpty()); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 1117 | EXPECT_FALSE(proxy_headers_handler.observed_before_proxy_headers_sent()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1118 | |
| 1119 | std::string server_header; |
| 1120 | void* iter = NULL; |
| 1121 | bool has_server_header = response->headers->EnumerateHeader( |
| 1122 | &iter, "Server", &server_header); |
| 1123 | EXPECT_TRUE(has_server_header); |
| 1124 | EXPECT_EQ("Blah", server_header); |
| 1125 | |
| 1126 | // Reading should give EOF right away, since there is no message body |
| 1127 | // (despite non-zero content-length). |
| 1128 | std::string response_data; |
| 1129 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1130 | EXPECT_EQ(OK, rv); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1131 | EXPECT_EQ("", response_data); |
| 1132 | } |
| 1133 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1134 | TEST_P(HttpNetworkTransactionTest, ReuseConnection) { |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1135 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1136 | |
| 1137 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1138 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1139 | MockRead("hello"), |
| 1140 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1141 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1142 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1143 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1144 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1145 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1146 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1147 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1148 | "hello", "world" |
| 1149 | }; |
| 1150 | |
| 1151 | for (int i = 0; i < 2; ++i) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1152 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1153 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1154 | request.url = GURL("http://www.example.org/"); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1155 | request.load_flags = 0; |
| 1156 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1157 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1158 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1159 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1160 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1161 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1162 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1163 | EXPECT_EQ(ERR_IO_PENDING, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1164 | |
| 1165 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1166 | EXPECT_EQ(OK, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1167 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1168 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1169 | ASSERT_TRUE(response != NULL); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1170 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1171 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1172 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 1173 | EXPECT_TRUE(response->proxy_server.IsEmpty()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1174 | |
| 1175 | std::string response_data; |
[email protected] | af4876d | 2008-10-21 23:10:57 | [diff] [blame] | 1176 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1177 | EXPECT_EQ(OK, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1178 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1179 | } |
| 1180 | } |
| 1181 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1182 | TEST_P(HttpNetworkTransactionTest, Ignores100) { |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 1183 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 1184 | element_readers.push_back( |
| 1185 | make_scoped_ptr(new UploadBytesElementReader("foo", 3))); |
| 1186 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1187 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1188 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1189 | request.method = "POST"; |
| 1190 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1191 | request.upload_data_stream = &upload_data_stream; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1192 | request.load_flags = 0; |
| 1193 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1194 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1195 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1196 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1197 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1198 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1199 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 1200 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 1201 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1202 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1203 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1204 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1205 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1206 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1207 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1208 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1209 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1210 | EXPECT_EQ(ERR_IO_PENDING, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1211 | |
| 1212 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1213 | EXPECT_EQ(OK, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1214 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1215 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1216 | ASSERT_TRUE(response != NULL); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1217 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1218 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1219 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1220 | |
| 1221 | std::string response_data; |
[email protected] | af4876d | 2008-10-21 23:10:57 | [diff] [blame] | 1222 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1223 | EXPECT_EQ(OK, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1224 | EXPECT_EQ("hello world", response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1225 | } |
| 1226 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1227 | // This test is almost the same as Ignores100 above, but the response contains |
| 1228 | // 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] | 1229 | // HTTP/1.1 and the two status headers are read in one read. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1230 | TEST_P(HttpNetworkTransactionTest, Ignores1xx) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1231 | HttpRequestInfo request; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1232 | request.method = "GET"; |
| 1233 | request.url = GURL("http://www.foo.com/"); |
| 1234 | request.load_flags = 0; |
| 1235 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1236 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1237 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1238 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1239 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1240 | MockRead data_reads[] = { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1241 | MockRead("HTTP/1.1 102 Unspecified status code\r\n\r\n" |
| 1242 | "HTTP/1.1 200 OK\r\n\r\n"), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1243 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1244 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1245 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1246 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1247 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1248 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1249 | TestCompletionCallback callback; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1250 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1251 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1252 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1253 | |
| 1254 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1255 | EXPECT_EQ(OK, rv); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1256 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1257 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1258 | ASSERT_TRUE(response != NULL); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1259 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1260 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1261 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1262 | |
| 1263 | std::string response_data; |
| 1264 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1265 | EXPECT_EQ(OK, rv); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1266 | EXPECT_EQ("hello world", response_data); |
| 1267 | } |
| 1268 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1269 | TEST_P(HttpNetworkTransactionTest, Incomplete100ThenEOF) { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1270 | HttpRequestInfo request; |
| 1271 | request.method = "POST"; |
| 1272 | request.url = GURL("http://www.foo.com/"); |
| 1273 | request.load_flags = 0; |
| 1274 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1275 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1276 | scoped_ptr<HttpTransaction> trans( |
| 1277 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 1278 | |
| 1279 | MockRead data_reads[] = { |
| 1280 | MockRead(SYNCHRONOUS, "HTTP/1.0 100 Continue\r\n"), |
| 1281 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1282 | }; |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1283 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 1284 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1285 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1286 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1287 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1288 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1289 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1290 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1291 | rv = callback.WaitForResult(); |
| 1292 | EXPECT_EQ(OK, rv); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1293 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1294 | std::string response_data; |
| 1295 | rv = ReadTransaction(trans.get(), &response_data); |
| 1296 | EXPECT_EQ(OK, rv); |
| 1297 | EXPECT_EQ("", response_data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1298 | } |
| 1299 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1300 | TEST_P(HttpNetworkTransactionTest, EmptyResponse) { |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1301 | HttpRequestInfo request; |
| 1302 | request.method = "POST"; |
| 1303 | request.url = GURL("http://www.foo.com/"); |
| 1304 | request.load_flags = 0; |
| 1305 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1306 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1307 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1308 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1309 | |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1310 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1311 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1312 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1313 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1314 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1315 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1316 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1317 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1318 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1319 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1320 | |
| 1321 | rv = callback.WaitForResult(); |
| 1322 | EXPECT_EQ(ERR_EMPTY_RESPONSE, rv); |
| 1323 | } |
| 1324 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1325 | void HttpNetworkTransactionTest::KeepAliveConnectionResendRequestTest( |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1326 | const MockWrite* write_failure, |
| 1327 | const MockRead* read_failure) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1328 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1329 | request.method = "GET"; |
| 1330 | request.url = GURL("http://www.foo.com/"); |
| 1331 | request.load_flags = 0; |
| 1332 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1333 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1334 | session_deps_.net_log = &net_log; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1335 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1336 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1337 | // Written data for successfully sending both requests. |
| 1338 | MockWrite data1_writes[] = { |
| 1339 | MockWrite("GET / HTTP/1.1\r\n" |
| 1340 | "Host: www.foo.com\r\n" |
| 1341 | "Connection: keep-alive\r\n\r\n"), |
| 1342 | MockWrite("GET / HTTP/1.1\r\n" |
| 1343 | "Host: www.foo.com\r\n" |
| 1344 | "Connection: keep-alive\r\n\r\n") |
| 1345 | }; |
| 1346 | |
| 1347 | // Read results for the first request. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1348 | MockRead data1_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1349 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1350 | MockRead("hello"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1351 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1352 | }; |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1353 | |
| 1354 | if (write_failure) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1355 | ASSERT_FALSE(read_failure); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1356 | data1_writes[1] = *write_failure; |
| 1357 | } else { |
| 1358 | ASSERT_TRUE(read_failure); |
| 1359 | data1_reads[2] = *read_failure; |
| 1360 | } |
| 1361 | |
| 1362 | StaticSocketDataProvider data1(data1_reads, arraysize(data1_reads), |
| 1363 | data1_writes, arraysize(data1_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1364 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1365 | |
| 1366 | MockRead data2_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1367 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1368 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1369 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1370 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1371 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1372 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1373 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 1374 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1375 | "hello", "world" |
| 1376 | }; |
| 1377 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1378 | uint32 first_socket_log_id = NetLog::Source::kInvalidId; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1379 | for (int i = 0; i < 2; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1380 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1381 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1382 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1383 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1384 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1385 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1386 | EXPECT_EQ(ERR_IO_PENDING, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1387 | |
| 1388 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1389 | EXPECT_EQ(OK, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1390 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1391 | LoadTimingInfo load_timing_info; |
| 1392 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 1393 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1394 | if (i == 0) { |
| 1395 | first_socket_log_id = load_timing_info.socket_log_id; |
| 1396 | } else { |
| 1397 | // The second request should be using a new socket. |
| 1398 | EXPECT_NE(first_socket_log_id, load_timing_info.socket_log_id); |
| 1399 | } |
| 1400 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1401 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1402 | ASSERT_TRUE(response != NULL); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1403 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1404 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1405 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1406 | |
| 1407 | std::string response_data; |
[email protected] | af4876d | 2008-10-21 23:10:57 | [diff] [blame] | 1408 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1409 | EXPECT_EQ(OK, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1410 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1411 | } |
| 1412 | } |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1413 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1414 | void HttpNetworkTransactionTest::PreconnectErrorResendRequestTest( |
| 1415 | const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1416 | const MockRead* read_failure, |
| 1417 | bool use_spdy) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1418 | HttpRequestInfo request; |
| 1419 | request.method = "GET"; |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1420 | request.url = GURL("https://www.foo.com/"); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1421 | request.load_flags = 0; |
| 1422 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1423 | TestNetLog net_log; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1424 | session_deps_.net_log = &net_log; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1425 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1426 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1427 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 1428 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 1429 | if (use_spdy) { |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 1430 | ssl1.SetNextProto(GetProtocol()); |
| 1431 | ssl2.SetNextProto(GetProtocol()); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1432 | } |
| 1433 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 1434 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1435 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1436 | // SPDY versions of the request and response. |
| 1437 | scoped_ptr<SpdyFrame> spdy_request(spdy_util_.ConstructSpdyGet( |
| 1438 | request.url.spec().c_str(), false, 1, DEFAULT_PRIORITY)); |
| 1439 | scoped_ptr<SpdyFrame> spdy_response( |
| 1440 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 1441 | scoped_ptr<SpdyFrame> spdy_data( |
| 1442 | spdy_util_.ConstructSpdyBodyFrame(1, "hello", 5, true)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1443 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1444 | // HTTP/1.1 versions of the request and response. |
| 1445 | const char kHttpRequest[] = "GET / HTTP/1.1\r\n" |
| 1446 | "Host: www.foo.com\r\n" |
| 1447 | "Connection: keep-alive\r\n\r\n"; |
| 1448 | const char kHttpResponse[] = "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"; |
| 1449 | const char kHttpData[] = "hello"; |
| 1450 | |
| 1451 | std::vector<MockRead> data1_reads; |
| 1452 | std::vector<MockWrite> data1_writes; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1453 | if (write_failure) { |
| 1454 | ASSERT_FALSE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1455 | data1_writes.push_back(*write_failure); |
| 1456 | data1_reads.push_back(MockRead(ASYNC, OK)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1457 | } else { |
| 1458 | ASSERT_TRUE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1459 | if (use_spdy) { |
| 1460 | data1_writes.push_back(CreateMockWrite(*spdy_request)); |
| 1461 | } else { |
| 1462 | data1_writes.push_back(MockWrite(kHttpRequest)); |
| 1463 | } |
| 1464 | data1_reads.push_back(*read_failure); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1465 | } |
| 1466 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1467 | StaticSocketDataProvider data1(&data1_reads[0], data1_reads.size(), |
| 1468 | &data1_writes[0], data1_writes.size()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1469 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1470 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1471 | std::vector<MockRead> data2_reads; |
| 1472 | std::vector<MockWrite> data2_writes; |
| 1473 | |
| 1474 | if (use_spdy) { |
| 1475 | data2_writes.push_back(CreateMockWrite(*spdy_request, 0, ASYNC)); |
| 1476 | |
| 1477 | data2_reads.push_back(CreateMockRead(*spdy_response, 1, ASYNC)); |
| 1478 | data2_reads.push_back(CreateMockRead(*spdy_data, 2, ASYNC)); |
| 1479 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1480 | } else { |
| 1481 | data2_writes.push_back( |
| 1482 | MockWrite(ASYNC, kHttpRequest, strlen(kHttpRequest), 0)); |
| 1483 | |
| 1484 | data2_reads.push_back( |
| 1485 | MockRead(ASYNC, kHttpResponse, strlen(kHttpResponse), 1)); |
| 1486 | data2_reads.push_back(MockRead(ASYNC, kHttpData, strlen(kHttpData), 2)); |
| 1487 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1488 | } |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 1489 | SequencedSocketData data2(&data2_reads[0], data2_reads.size(), |
| 1490 | &data2_writes[0], data2_writes.size()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1491 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1492 | |
| 1493 | // Preconnect a socket. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 1494 | SSLConfig ssl_config; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1495 | session->ssl_config_service()->GetSSLConfig(&ssl_config); |
bnc | 1f29537 | 2015-10-21 23:24:22 | [diff] [blame] | 1496 | session->GetAlpnProtos(&ssl_config.alpn_protos); |
| 1497 | session->GetNpnProtos(&ssl_config.npn_protos); |
mmenke | d1205bd | 2015-07-15 22:26:35 | [diff] [blame] | 1498 | session->http_stream_factory()->PreconnectStreams(1, request, ssl_config, |
| 1499 | ssl_config); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1500 | // Wait for the preconnect to complete. |
| 1501 | // TODO(davidben): Some way to wait for an idle socket count might be handy. |
| 1502 | base::RunLoop().RunUntilIdle(); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1503 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1504 | |
| 1505 | // Make the request. |
| 1506 | TestCompletionCallback callback; |
| 1507 | |
| 1508 | scoped_ptr<HttpTransaction> trans( |
| 1509 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 1510 | |
| 1511 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1512 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1513 | |
| 1514 | rv = callback.WaitForResult(); |
| 1515 | EXPECT_EQ(OK, rv); |
| 1516 | |
| 1517 | LoadTimingInfo load_timing_info; |
| 1518 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1519 | TestLoadTimingNotReused( |
| 1520 | load_timing_info, |
| 1521 | CONNECT_TIMING_HAS_DNS_TIMES|CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1522 | |
| 1523 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 1524 | ASSERT_TRUE(response != NULL); |
| 1525 | |
| 1526 | EXPECT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame^] | 1527 | if (response->was_fetched_via_spdy) { |
| 1528 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 1529 | } else { |
| 1530 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1531 | } |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1532 | |
| 1533 | std::string response_data; |
| 1534 | rv = ReadTransaction(trans.get(), &response_data); |
| 1535 | EXPECT_EQ(OK, rv); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1536 | EXPECT_EQ(kHttpData, response_data); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1537 | } |
| 1538 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1539 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 1540 | KeepAliveConnectionNotConnectedOnWrite) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1541 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1542 | KeepAliveConnectionResendRequestTest(&write_failure, NULL); |
| 1543 | } |
| 1544 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1545 | TEST_P(HttpNetworkTransactionTest, KeepAliveConnectionReset) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1546 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1547 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1548 | } |
| 1549 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1550 | TEST_P(HttpNetworkTransactionTest, KeepAliveConnectionEOF) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1551 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1552 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1553 | } |
| 1554 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1555 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1556 | // if the socket was a reused keep alive socket. |
| 1557 | TEST_P(HttpNetworkTransactionTest, KeepAlive408) { |
| 1558 | MockRead read_failure(SYNCHRONOUS, |
| 1559 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1560 | "Connection: Keep-Alive\r\n" |
| 1561 | "Content-Length: 6\r\n\r\n" |
| 1562 | "Pickle"); |
| 1563 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
| 1564 | } |
| 1565 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1566 | TEST_P(HttpNetworkTransactionTest, |
| 1567 | PreconnectErrorNotConnectedOnWrite) { |
| 1568 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1569 | PreconnectErrorResendRequestTest(&write_failure, NULL, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1570 | } |
| 1571 | |
| 1572 | TEST_P(HttpNetworkTransactionTest, PreconnectErrorReset) { |
| 1573 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1574 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1575 | } |
| 1576 | |
| 1577 | TEST_P(HttpNetworkTransactionTest, PreconnectErrorEOF) { |
| 1578 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1579 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1580 | } |
| 1581 | |
| 1582 | TEST_P(HttpNetworkTransactionTest, PreconnectErrorAsyncEOF) { |
| 1583 | MockRead read_failure(ASYNC, OK); // EOF |
| 1584 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1585 | } |
| 1586 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1587 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1588 | // if the socket was a preconnected (UNUSED_IDLE) socket. |
| 1589 | TEST_P(HttpNetworkTransactionTest, RetryOnIdle408) { |
| 1590 | MockRead read_failure(SYNCHRONOUS, |
| 1591 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1592 | "Connection: Keep-Alive\r\n" |
| 1593 | "Content-Length: 6\r\n\r\n" |
| 1594 | "Pickle"); |
| 1595 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
| 1596 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1597 | } |
| 1598 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1599 | TEST_P(HttpNetworkTransactionTest, |
| 1600 | SpdyPreconnectErrorNotConnectedOnWrite) { |
| 1601 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
| 1602 | PreconnectErrorResendRequestTest(&write_failure, NULL, true); |
| 1603 | } |
| 1604 | |
| 1605 | TEST_P(HttpNetworkTransactionTest, SpdyPreconnectErrorReset) { |
| 1606 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
| 1607 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
| 1608 | } |
| 1609 | |
| 1610 | TEST_P(HttpNetworkTransactionTest, SpdyPreconnectErrorEOF) { |
| 1611 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
| 1612 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
| 1613 | } |
| 1614 | |
| 1615 | TEST_P(HttpNetworkTransactionTest, SpdyPreconnectErrorAsyncEOF) { |
| 1616 | MockRead read_failure(ASYNC, OK); // EOF |
| 1617 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1618 | } |
| 1619 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1620 | TEST_P(HttpNetworkTransactionTest, NonKeepAliveConnectionReset) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1621 | HttpRequestInfo request; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1622 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1623 | request.url = GURL("http://www.example.org/"); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1624 | request.load_flags = 0; |
| 1625 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1626 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1627 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1628 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1629 | |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1630 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1631 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1632 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 1633 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1634 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1635 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1636 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1637 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1638 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1639 | TestCompletionCallback callback; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1640 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1641 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1642 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1643 | |
| 1644 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1645 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 1646 | |
| 1647 | IPEndPoint endpoint; |
| 1648 | EXPECT_TRUE(trans->GetRemoteEndpoint(&endpoint)); |
| 1649 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1650 | } |
| 1651 | |
| 1652 | // What do various browsers do when the server closes a non-keepalive |
| 1653 | // connection without sending any response header or body? |
| 1654 | // |
| 1655 | // IE7: error page |
| 1656 | // Safari 3.1.2 (Windows): error page |
| 1657 | // Firefox 3.0.1: blank page |
| 1658 | // Opera 9.52: after five attempts, blank page |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1659 | // Us with WinHTTP: error page (ERR_INVALID_RESPONSE) |
| 1660 | // Us: error page (EMPTY_RESPONSE) |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1661 | TEST_P(HttpNetworkTransactionTest, NonKeepAliveConnectionEOF) { |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1662 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1663 | MockRead(SYNCHRONOUS, OK), // EOF |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1664 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 1665 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1666 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1667 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1668 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1669 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1670 | EXPECT_EQ(ERR_EMPTY_RESPONSE, out.rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1671 | } |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1672 | |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1673 | // Test that network access can be deferred and resumed. |
| 1674 | TEST_P(HttpNetworkTransactionTest, ThrottleBeforeNetworkStart) { |
| 1675 | HttpRequestInfo request; |
| 1676 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1677 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1678 | request.load_flags = 0; |
| 1679 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1680 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1681 | scoped_ptr<HttpTransaction> trans( |
| 1682 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 1683 | |
| 1684 | // Defer on OnBeforeNetworkStart. |
| 1685 | BeforeNetworkStartHandler net_start_handler(true); // defer |
| 1686 | trans->SetBeforeNetworkStartCallback( |
| 1687 | base::Bind(&BeforeNetworkStartHandler::OnBeforeNetworkStart, |
| 1688 | base::Unretained(&net_start_handler))); |
| 1689 | |
| 1690 | MockRead data_reads[] = { |
| 1691 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1692 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1693 | MockRead("hello"), |
| 1694 | MockRead(SYNCHRONOUS, 0), |
| 1695 | }; |
| 1696 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 1697 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 1698 | |
| 1699 | TestCompletionCallback callback; |
| 1700 | |
| 1701 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1702 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1703 | base::MessageLoop::current()->RunUntilIdle(); |
| 1704 | |
| 1705 | // Should have deferred for network start. |
| 1706 | EXPECT_TRUE(net_start_handler.observed_before_network_start()); |
| 1707 | EXPECT_EQ(LOAD_STATE_WAITING_FOR_DELEGATE, trans->GetLoadState()); |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1708 | |
| 1709 | trans->ResumeNetworkStart(); |
| 1710 | rv = callback.WaitForResult(); |
| 1711 | EXPECT_EQ(OK, rv); |
| 1712 | EXPECT_TRUE(trans->GetResponseInfo() != NULL); |
| 1713 | |
| 1714 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
| 1715 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
| 1716 | if (rv == ERR_IO_PENDING) |
| 1717 | rv = callback.WaitForResult(); |
| 1718 | EXPECT_EQ(5, rv); |
| 1719 | trans.reset(); |
| 1720 | } |
| 1721 | |
| 1722 | // Test that network use can be deferred and canceled. |
| 1723 | TEST_P(HttpNetworkTransactionTest, ThrottleAndCancelBeforeNetworkStart) { |
| 1724 | HttpRequestInfo request; |
| 1725 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1726 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1727 | request.load_flags = 0; |
| 1728 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1729 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1730 | scoped_ptr<HttpTransaction> trans( |
| 1731 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 1732 | |
| 1733 | // Defer on OnBeforeNetworkStart. |
| 1734 | BeforeNetworkStartHandler net_start_handler(true); // defer |
| 1735 | trans->SetBeforeNetworkStartCallback( |
| 1736 | base::Bind(&BeforeNetworkStartHandler::OnBeforeNetworkStart, |
| 1737 | base::Unretained(&net_start_handler))); |
| 1738 | |
| 1739 | TestCompletionCallback callback; |
| 1740 | |
| 1741 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1742 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1743 | base::MessageLoop::current()->RunUntilIdle(); |
| 1744 | |
| 1745 | // Should have deferred for network start. |
| 1746 | EXPECT_TRUE(net_start_handler.observed_before_network_start()); |
| 1747 | EXPECT_EQ(LOAD_STATE_WAITING_FOR_DELEGATE, trans->GetLoadState()); |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1748 | } |
| 1749 | |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1750 | // Next 2 cases (KeepAliveEarlyClose and KeepAliveEarlyClose2) are regression |
| 1751 | // tests. There was a bug causing HttpNetworkTransaction to hang in the |
| 1752 | // destructor in such situations. |
| 1753 | // See http://crbug.com/154712 and http://crbug.com/156609. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1754 | TEST_P(HttpNetworkTransactionTest, KeepAliveEarlyClose) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1755 | HttpRequestInfo request; |
| 1756 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1757 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1758 | request.load_flags = 0; |
| 1759 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1760 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1761 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1762 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1763 | |
| 1764 | MockRead data_reads[] = { |
| 1765 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1766 | MockRead("Connection: keep-alive\r\n"), |
| 1767 | MockRead("Content-Length: 100\r\n\r\n"), |
| 1768 | MockRead("hello"), |
| 1769 | MockRead(SYNCHRONOUS, 0), |
| 1770 | }; |
| 1771 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1772 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1773 | |
| 1774 | TestCompletionCallback callback; |
| 1775 | |
| 1776 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1777 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1778 | |
| 1779 | rv = callback.WaitForResult(); |
| 1780 | EXPECT_EQ(OK, rv); |
| 1781 | |
| 1782 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1783 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1784 | if (rv == ERR_IO_PENDING) |
| 1785 | rv = callback.WaitForResult(); |
| 1786 | EXPECT_EQ(5, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1787 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1788 | EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, rv); |
| 1789 | |
| 1790 | trans.reset(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 1791 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1792 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 1793 | } |
| 1794 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1795 | TEST_P(HttpNetworkTransactionTest, KeepAliveEarlyClose2) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1796 | HttpRequestInfo request; |
| 1797 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1798 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1799 | request.load_flags = 0; |
| 1800 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1801 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1802 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1803 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1804 | |
| 1805 | MockRead data_reads[] = { |
| 1806 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1807 | MockRead("Connection: keep-alive\r\n"), |
| 1808 | MockRead("Content-Length: 100\r\n\r\n"), |
| 1809 | MockRead(SYNCHRONOUS, 0), |
| 1810 | }; |
| 1811 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1812 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1813 | |
| 1814 | TestCompletionCallback callback; |
| 1815 | |
| 1816 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1817 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1818 | |
| 1819 | rv = callback.WaitForResult(); |
| 1820 | EXPECT_EQ(OK, rv); |
| 1821 | |
| 1822 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1823 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1824 | if (rv == ERR_IO_PENDING) |
| 1825 | rv = callback.WaitForResult(); |
| 1826 | EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, rv); |
| 1827 | |
| 1828 | trans.reset(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 1829 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1830 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 1831 | } |
| 1832 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1833 | // Test that we correctly reuse a keep-alive connection after not explicitly |
| 1834 | // reading the body. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1835 | TEST_P(HttpNetworkTransactionTest, KeepAliveAfterUnreadBody) { |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1836 | HttpRequestInfo request; |
| 1837 | request.method = "GET"; |
| 1838 | request.url = GURL("http://www.foo.com/"); |
| 1839 | request.load_flags = 0; |
| 1840 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1841 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1842 | session_deps_.net_log = &net_log; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1843 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1844 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1845 | // Note that because all these reads happen in the same |
| 1846 | // StaticSocketDataProvider, it shows that the same socket is being reused for |
| 1847 | // all transactions. |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1848 | MockRead data1_reads[] = { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1849 | MockRead("HTTP/1.1 204 No Content\r\n\r\n"), |
| 1850 | MockRead("HTTP/1.1 205 Reset Content\r\n\r\n"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1851 | MockRead("HTTP/1.1 304 Not Modified\r\n\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1852 | MockRead("HTTP/1.1 302 Found\r\n" |
| 1853 | "Content-Length: 0\r\n\r\n"), |
| 1854 | MockRead("HTTP/1.1 302 Found\r\n" |
| 1855 | "Content-Length: 5\r\n\r\n" |
| 1856 | "hello"), |
| 1857 | MockRead("HTTP/1.1 301 Moved Permanently\r\n" |
| 1858 | "Content-Length: 0\r\n\r\n"), |
| 1859 | MockRead("HTTP/1.1 301 Moved Permanently\r\n" |
| 1860 | "Content-Length: 5\r\n\r\n" |
| 1861 | "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1862 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1863 | MockRead("hello"), |
| 1864 | }; |
| 1865 | StaticSocketDataProvider data1(data1_reads, arraysize(data1_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1866 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1867 | |
| 1868 | MockRead data2_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1869 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1870 | }; |
| 1871 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1872 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1873 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1874 | const int kNumUnreadBodies = arraysize(data1_reads) - 2; |
| 1875 | std::string response_lines[kNumUnreadBodies]; |
| 1876 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1877 | uint32 first_socket_log_id = NetLog::Source::kInvalidId; |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1878 | for (size_t i = 0; i < arraysize(data1_reads) - 2; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1879 | TestCompletionCallback callback; |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1880 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1881 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1882 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1883 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1884 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1885 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1886 | |
| 1887 | rv = callback.WaitForResult(); |
| 1888 | EXPECT_EQ(OK, rv); |
| 1889 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1890 | LoadTimingInfo load_timing_info; |
| 1891 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 1892 | if (i == 0) { |
| 1893 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1894 | first_socket_log_id = load_timing_info.socket_log_id; |
| 1895 | } else { |
| 1896 | TestLoadTimingReused(load_timing_info); |
| 1897 | EXPECT_EQ(first_socket_log_id, load_timing_info.socket_log_id); |
| 1898 | } |
| 1899 | |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1900 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1901 | ASSERT_TRUE(response != NULL); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1902 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1903 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1904 | response_lines[i] = response->headers->GetStatusLine(); |
| 1905 | |
| 1906 | // We intentionally don't read the response bodies. |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1907 | } |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1908 | |
| 1909 | const char* const kStatusLines[] = { |
| 1910 | "HTTP/1.1 204 No Content", |
| 1911 | "HTTP/1.1 205 Reset Content", |
| 1912 | "HTTP/1.1 304 Not Modified", |
| 1913 | "HTTP/1.1 302 Found", |
| 1914 | "HTTP/1.1 302 Found", |
| 1915 | "HTTP/1.1 301 Moved Permanently", |
| 1916 | "HTTP/1.1 301 Moved Permanently", |
| 1917 | }; |
| 1918 | |
mostynb | 91e0da98 | 2015-01-20 19:17:27 | [diff] [blame] | 1919 | static_assert(kNumUnreadBodies == arraysize(kStatusLines), |
| 1920 | "forgot to update kStatusLines"); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1921 | |
| 1922 | for (int i = 0; i < kNumUnreadBodies; ++i) |
| 1923 | EXPECT_EQ(kStatusLines[i], response_lines[i]); |
| 1924 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1925 | TestCompletionCallback callback; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1926 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1927 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1928 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1929 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1930 | rv = callback.WaitForResult(); |
| 1931 | EXPECT_EQ(OK, rv); |
| 1932 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 1933 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1934 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1935 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1936 | std::string response_data; |
| 1937 | rv = ReadTransaction(trans.get(), &response_data); |
| 1938 | EXPECT_EQ(OK, rv); |
| 1939 | EXPECT_EQ("hello", response_data); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1940 | } |
| 1941 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1942 | // Test the request-challenge-retry sequence for basic auth. |
| 1943 | // (basic auth is the easiest to mock, because it has no randomness). |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1944 | TEST_P(HttpNetworkTransactionTest, BasicAuth) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1945 | HttpRequestInfo request; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1946 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1947 | request.url = GURL("http://www.example.org/"); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1948 | request.load_flags = 0; |
| 1949 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1950 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1951 | session_deps_.net_log = &log; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1952 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1953 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1954 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1955 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 1956 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1957 | MockWrite( |
| 1958 | "GET / HTTP/1.1\r\n" |
| 1959 | "Host: www.example.org\r\n" |
| 1960 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 1961 | }; |
| 1962 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1963 | MockRead data_reads1[] = { |
| 1964 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 1965 | // Give a couple authenticate options (only the middle one is actually |
| 1966 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 1967 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1968 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 1969 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 1970 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 1971 | // Large content-length -- won't matter, as connection will be reset. |
| 1972 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1973 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1974 | }; |
| 1975 | |
| 1976 | // After calling trans->RestartWithAuth(), this is the request we should |
| 1977 | // be issuing -- the final header line contains the credentials. |
| 1978 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1979 | MockWrite( |
| 1980 | "GET / HTTP/1.1\r\n" |
| 1981 | "Host: www.example.org\r\n" |
| 1982 | "Connection: keep-alive\r\n" |
| 1983 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1984 | }; |
| 1985 | |
| 1986 | // Lastly, the server responds with the actual content. |
| 1987 | MockRead data_reads2[] = { |
| 1988 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1989 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 1990 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1991 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1992 | }; |
| 1993 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1994 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 1995 | data_writes1, arraysize(data_writes1)); |
| 1996 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 1997 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1998 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1999 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2000 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2001 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2002 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2003 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2004 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2005 | |
| 2006 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2007 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2008 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2009 | LoadTimingInfo load_timing_info1; |
| 2010 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info1)); |
| 2011 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2012 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2013 | int64_t writes_size1 = CountWriteBytes(data_writes1, arraysize(data_writes1)); |
| 2014 | EXPECT_EQ(writes_size1, trans->GetTotalSentBytes()); |
| 2015 | int64_t reads_size1 = CountReadBytes(data_reads1, arraysize(data_reads1)); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2016 | EXPECT_EQ(reads_size1, trans->GetTotalReceivedBytes()); |
| 2017 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2018 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2019 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2020 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2021 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2022 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2023 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2024 | rv = trans->RestartWithAuth( |
| 2025 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2026 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2027 | |
| 2028 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2029 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2030 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2031 | LoadTimingInfo load_timing_info2; |
| 2032 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info2)); |
| 2033 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2034 | // The load timing after restart should have a new socket ID, and times after |
| 2035 | // those of the first load timing. |
| 2036 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2037 | load_timing_info2.connect_timing.connect_start); |
| 2038 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2039 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2040 | int64_t writes_size2 = CountWriteBytes(data_writes2, arraysize(data_writes2)); |
| 2041 | EXPECT_EQ(writes_size1 + writes_size2, trans->GetTotalSentBytes()); |
| 2042 | int64_t reads_size2 = CountReadBytes(data_reads2, arraysize(data_reads2)); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2043 | EXPECT_EQ(reads_size1 + reads_size2, trans->GetTotalReceivedBytes()); |
| 2044 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2045 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2046 | ASSERT_TRUE(response != NULL); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2047 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 2048 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2049 | } |
| 2050 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2051 | // Test the request-challenge-retry sequence for basic auth. |
| 2052 | // (basic auth is the easiest to mock, because it has no randomness). |
| 2053 | TEST_P(HttpNetworkTransactionTest, BasicAuthWithAddressChange) { |
| 2054 | HttpRequestInfo request; |
| 2055 | request.method = "GET"; |
| 2056 | request.url = GURL("http://www.example.org/"); |
| 2057 | request.load_flags = 0; |
| 2058 | |
| 2059 | TestNetLog log; |
| 2060 | MockHostResolver* resolver = new MockHostResolver(); |
| 2061 | session_deps_.net_log = &log; |
| 2062 | session_deps_.host_resolver.reset(resolver); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 2063 | scoped_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2064 | scoped_ptr<HttpTransaction> trans( |
| 2065 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 2066 | |
| 2067 | resolver->rules()->ClearRules(); |
| 2068 | resolver->rules()->AddRule("www.example.org", "127.0.0.1"); |
| 2069 | |
| 2070 | MockWrite data_writes1[] = { |
| 2071 | MockWrite("GET / HTTP/1.1\r\n" |
| 2072 | "Host: www.example.org\r\n" |
| 2073 | "Connection: keep-alive\r\n\r\n"), |
| 2074 | }; |
| 2075 | |
| 2076 | MockRead data_reads1[] = { |
| 2077 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2078 | // Give a couple authenticate options (only the middle one is actually |
| 2079 | // supported). |
| 2080 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 2081 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2082 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2083 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2084 | // Large content-length -- won't matter, as connection will be reset. |
| 2085 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 2086 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 2087 | }; |
| 2088 | |
| 2089 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2090 | // be issuing -- the final header line contains the credentials. |
| 2091 | MockWrite data_writes2[] = { |
| 2092 | MockWrite("GET / HTTP/1.1\r\n" |
| 2093 | "Host: www.example.org\r\n" |
| 2094 | "Connection: keep-alive\r\n" |
| 2095 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2096 | }; |
| 2097 | |
| 2098 | // Lastly, the server responds with the actual content. |
| 2099 | MockRead data_reads2[] = { |
| 2100 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2101 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2102 | MockRead("Content-Length: 100\r\n\r\n"), MockRead(SYNCHRONOUS, OK), |
| 2103 | }; |
| 2104 | |
| 2105 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2106 | data_writes1, arraysize(data_writes1)); |
| 2107 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2108 | data_writes2, arraysize(data_writes2)); |
| 2109 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2110 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2111 | |
| 2112 | TestCompletionCallback callback1; |
| 2113 | |
| 2114 | EXPECT_EQ(OK, callback1.GetResult(trans->Start(&request, callback1.callback(), |
| 2115 | BoundNetLog()))); |
| 2116 | |
| 2117 | LoadTimingInfo load_timing_info1; |
| 2118 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info1)); |
| 2119 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2120 | |
| 2121 | int64_t writes_size1 = CountWriteBytes(data_writes1, arraysize(data_writes1)); |
| 2122 | EXPECT_EQ(writes_size1, trans->GetTotalSentBytes()); |
| 2123 | int64_t reads_size1 = CountReadBytes(data_reads1, arraysize(data_reads1)); |
| 2124 | EXPECT_EQ(reads_size1, trans->GetTotalReceivedBytes()); |
| 2125 | |
| 2126 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 2127 | ASSERT_TRUE(response); |
| 2128 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 2129 | |
| 2130 | IPEndPoint endpoint; |
| 2131 | EXPECT_TRUE(trans->GetRemoteEndpoint(&endpoint)); |
| 2132 | ASSERT_FALSE(endpoint.address().empty()); |
| 2133 | EXPECT_EQ("127.0.0.1:80", endpoint.ToString()); |
| 2134 | |
| 2135 | resolver->rules()->ClearRules(); |
| 2136 | resolver->rules()->AddRule("www.example.org", "127.0.0.2"); |
| 2137 | |
| 2138 | TestCompletionCallback callback2; |
| 2139 | |
| 2140 | EXPECT_EQ(OK, callback2.GetResult(trans->RestartWithAuth( |
| 2141 | AuthCredentials(kFoo, kBar), callback2.callback()))); |
| 2142 | |
| 2143 | LoadTimingInfo load_timing_info2; |
| 2144 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info2)); |
| 2145 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2146 | // The load timing after restart should have a new socket ID, and times after |
| 2147 | // those of the first load timing. |
| 2148 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2149 | load_timing_info2.connect_timing.connect_start); |
| 2150 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2151 | |
| 2152 | int64_t writes_size2 = CountWriteBytes(data_writes2, arraysize(data_writes2)); |
| 2153 | EXPECT_EQ(writes_size1 + writes_size2, trans->GetTotalSentBytes()); |
| 2154 | int64_t reads_size2 = CountReadBytes(data_reads2, arraysize(data_reads2)); |
| 2155 | EXPECT_EQ(reads_size1 + reads_size2, trans->GetTotalReceivedBytes()); |
| 2156 | |
| 2157 | response = trans->GetResponseInfo(); |
| 2158 | ASSERT_TRUE(response); |
| 2159 | EXPECT_FALSE(response->auth_challenge.get()); |
| 2160 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 2161 | |
| 2162 | EXPECT_TRUE(trans->GetRemoteEndpoint(&endpoint)); |
| 2163 | ASSERT_FALSE(endpoint.address().empty()); |
| 2164 | EXPECT_EQ("127.0.0.2:80", endpoint.ToString()); |
| 2165 | } |
| 2166 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2167 | TEST_P(HttpNetworkTransactionTest, DoNotSendAuth) { |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2168 | HttpRequestInfo request; |
| 2169 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2170 | request.url = GURL("http://www.example.org/"); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2171 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2172 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 2173 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2174 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 2175 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2176 | |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2177 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2178 | MockWrite( |
| 2179 | "GET / HTTP/1.1\r\n" |
| 2180 | "Host: www.example.org\r\n" |
| 2181 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2182 | }; |
| 2183 | |
| 2184 | MockRead data_reads[] = { |
| 2185 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2186 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2187 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2188 | // Large content-length -- won't matter, as connection will be reset. |
| 2189 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2190 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2191 | }; |
| 2192 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2193 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 2194 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2195 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2196 | TestCompletionCallback callback; |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2197 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2198 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2199 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2200 | |
| 2201 | rv = callback.WaitForResult(); |
| 2202 | EXPECT_EQ(0, rv); |
| 2203 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2204 | int64_t writes_size = CountWriteBytes(data_writes, arraysize(data_writes)); |
| 2205 | EXPECT_EQ(writes_size, trans->GetTotalSentBytes()); |
| 2206 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2207 | EXPECT_EQ(reads_size, trans->GetTotalReceivedBytes()); |
| 2208 | |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2209 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2210 | ASSERT_TRUE(response != NULL); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2211 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 2212 | } |
| 2213 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2214 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2215 | // connection. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2216 | TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAlive) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2217 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2218 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2219 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2220 | request.load_flags = 0; |
| 2221 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2222 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2223 | session_deps_.net_log = &log; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 2224 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2225 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2226 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2227 | MockWrite( |
| 2228 | "GET / HTTP/1.1\r\n" |
| 2229 | "Host: www.example.org\r\n" |
| 2230 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2231 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2232 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2233 | // be issuing -- the final header line contains the credentials. |
| 2234 | MockWrite( |
| 2235 | "GET / HTTP/1.1\r\n" |
| 2236 | "Host: www.example.org\r\n" |
| 2237 | "Connection: keep-alive\r\n" |
| 2238 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2239 | }; |
| 2240 | |
| 2241 | MockRead data_reads1[] = { |
| 2242 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2243 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2244 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2245 | MockRead("Content-Length: 14\r\n\r\n"), |
| 2246 | MockRead("Unauthorized\r\n"), |
| 2247 | |
| 2248 | // Lastly, the server responds with the actual content. |
| 2249 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2250 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2251 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2252 | MockRead("Hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2253 | }; |
| 2254 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2255 | // If there is a regression where we disconnect a Keep-Alive |
| 2256 | // connection during an auth roundtrip, we'll end up reading this. |
| 2257 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2258 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2259 | }; |
| 2260 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2261 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2262 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2263 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2264 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2265 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2266 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2267 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2268 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2269 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2270 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2271 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2272 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2273 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2274 | |
| 2275 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2276 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2277 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2278 | LoadTimingInfo load_timing_info1; |
| 2279 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info1)); |
| 2280 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2281 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2282 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2283 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2284 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2285 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2286 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2287 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2288 | rv = trans->RestartWithAuth( |
| 2289 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2290 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2291 | |
| 2292 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2293 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2294 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2295 | LoadTimingInfo load_timing_info2; |
| 2296 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info2)); |
| 2297 | TestLoadTimingReused(load_timing_info2); |
| 2298 | // The load timing after restart should have the same socket ID, and times |
| 2299 | // those of the first load timing. |
| 2300 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2301 | load_timing_info2.send_start); |
| 2302 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2303 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2304 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2305 | ASSERT_TRUE(response != NULL); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2306 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2307 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2308 | |
| 2309 | std::string response_data; |
| 2310 | rv = ReadTransaction(trans.get(), &response_data); |
| 2311 | EXPECT_EQ(OK, rv); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2312 | |
| 2313 | int64_t writes_size1 = CountWriteBytes(data_writes1, arraysize(data_writes1)); |
| 2314 | EXPECT_EQ(writes_size1, trans->GetTotalSentBytes()); |
| 2315 | int64_t reads_size1 = CountReadBytes(data_reads1, arraysize(data_reads1)); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2316 | EXPECT_EQ(reads_size1, trans->GetTotalReceivedBytes()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2317 | } |
| 2318 | |
| 2319 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2320 | // connection and with no response body to drain. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2321 | TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAliveNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2322 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2323 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2324 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2325 | request.load_flags = 0; |
| 2326 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 2327 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2328 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2329 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2330 | MockWrite( |
| 2331 | "GET / HTTP/1.1\r\n" |
| 2332 | "Host: www.example.org\r\n" |
| 2333 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2334 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2335 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2336 | // be issuing -- the final header line contains the credentials. |
| 2337 | MockWrite( |
| 2338 | "GET / HTTP/1.1\r\n" |
| 2339 | "Host: www.example.org\r\n" |
| 2340 | "Connection: keep-alive\r\n" |
| 2341 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2342 | }; |
| 2343 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2344 | MockRead data_reads1[] = { |
| 2345 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2346 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2347 | MockRead("Content-Length: 0\r\n\r\n"), // No response body. |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2348 | |
| 2349 | // Lastly, the server responds with the actual content. |
| 2350 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2351 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2352 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2353 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2354 | }; |
| 2355 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2356 | // An incorrect reconnect would cause this to be read. |
| 2357 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2358 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2359 | }; |
| 2360 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2361 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2362 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2363 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2364 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2365 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2366 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2367 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2368 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2369 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2370 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2371 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2372 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2373 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2374 | |
| 2375 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2376 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2377 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2378 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2379 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2380 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2381 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2382 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2383 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2384 | rv = trans->RestartWithAuth( |
| 2385 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2386 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2387 | |
| 2388 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2389 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2390 | |
| 2391 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2392 | ASSERT_TRUE(response != NULL); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2393 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2394 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2395 | } |
| 2396 | |
| 2397 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2398 | // connection and with a large response body to drain. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2399 | TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAliveLargeBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2400 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2401 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2402 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2403 | request.load_flags = 0; |
| 2404 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 2405 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2406 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2407 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2408 | MockWrite( |
| 2409 | "GET / HTTP/1.1\r\n" |
| 2410 | "Host: www.example.org\r\n" |
| 2411 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2412 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2413 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2414 | // be issuing -- the final header line contains the credentials. |
| 2415 | MockWrite( |
| 2416 | "GET / HTTP/1.1\r\n" |
| 2417 | "Host: www.example.org\r\n" |
| 2418 | "Connection: keep-alive\r\n" |
| 2419 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2420 | }; |
| 2421 | |
| 2422 | // Respond with 5 kb of response body. |
| 2423 | std::string large_body_string("Unauthorized"); |
| 2424 | large_body_string.append(5 * 1024, ' '); |
| 2425 | large_body_string.append("\r\n"); |
| 2426 | |
| 2427 | MockRead data_reads1[] = { |
| 2428 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2429 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2430 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2431 | // 5134 = 12 + 5 * 1024 + 2 |
| 2432 | MockRead("Content-Length: 5134\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2433 | MockRead(ASYNC, large_body_string.data(), large_body_string.size()), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2434 | |
| 2435 | // Lastly, the server responds with the actual content. |
| 2436 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2437 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2438 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2439 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2440 | }; |
| 2441 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2442 | // An incorrect reconnect would cause this to be read. |
| 2443 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2444 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2445 | }; |
| 2446 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2447 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2448 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2449 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2450 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2451 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2452 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2453 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2454 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2455 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2456 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2457 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2458 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2459 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2460 | |
| 2461 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2462 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2463 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2464 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2465 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2466 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2467 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2468 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2469 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2470 | rv = trans->RestartWithAuth( |
| 2471 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2472 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2473 | |
| 2474 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2475 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2476 | |
| 2477 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2478 | ASSERT_TRUE(response != NULL); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2479 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2480 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2481 | } |
| 2482 | |
| 2483 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2484 | // connection, but the server gets impatient and closes the connection. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2485 | TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAliveImpatientServer) { |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2486 | HttpRequestInfo request; |
| 2487 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2488 | request.url = GURL("http://www.example.org/"); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2489 | request.load_flags = 0; |
| 2490 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 2491 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2492 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2493 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2494 | MockWrite( |
| 2495 | "GET / HTTP/1.1\r\n" |
| 2496 | "Host: www.example.org\r\n" |
| 2497 | "Connection: keep-alive\r\n\r\n"), |
| 2498 | // This simulates the seemingly successful write to a closed connection |
| 2499 | // if the bug is not fixed. |
| 2500 | MockWrite( |
| 2501 | "GET / HTTP/1.1\r\n" |
| 2502 | "Host: www.example.org\r\n" |
| 2503 | "Connection: keep-alive\r\n" |
| 2504 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2505 | }; |
| 2506 | |
| 2507 | MockRead data_reads1[] = { |
| 2508 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2509 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2510 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2511 | MockRead("Content-Length: 14\r\n\r\n"), |
| 2512 | // Tell MockTCPClientSocket to simulate the server closing the connection. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2513 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2514 | MockRead("Unauthorized\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2515 | MockRead(SYNCHRONOUS, OK), // The server closes the connection. |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2516 | }; |
| 2517 | |
| 2518 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2519 | // be issuing -- the final header line contains the credentials. |
| 2520 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 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 | // Lastly, the server responds with the actual content. |
| 2529 | MockRead data_reads2[] = { |
| 2530 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2531 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2532 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2533 | MockRead("hello"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2534 | }; |
| 2535 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2536 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2537 | data_writes1, arraysize(data_writes1)); |
| 2538 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2539 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2540 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2541 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2542 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2543 | TestCompletionCallback callback1; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2544 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2545 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2546 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2547 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2548 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2549 | |
| 2550 | rv = callback1.WaitForResult(); |
| 2551 | EXPECT_EQ(OK, rv); |
| 2552 | |
| 2553 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2554 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2555 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2556 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2557 | TestCompletionCallback callback2; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2558 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2559 | rv = trans->RestartWithAuth( |
| 2560 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2561 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2562 | |
| 2563 | rv = callback2.WaitForResult(); |
| 2564 | EXPECT_EQ(OK, rv); |
| 2565 | |
| 2566 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2567 | ASSERT_TRUE(response != NULL); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2568 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2569 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2570 | } |
| 2571 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2572 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 2573 | // that requires a restart when setting up an SSL tunnel. |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2574 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp10) { |
| 2575 | HttpRequestInfo request; |
| 2576 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2577 | request.url = GURL("https://www.example.org/"); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2578 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2579 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2580 | |
| 2581 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 2582 | session_deps_.proxy_service = |
| 2583 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2584 | BoundTestNetLog log; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2585 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 2586 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2587 | |
| 2588 | // Since we have proxy, should try to establish tunnel. |
| 2589 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2590 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 2591 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2592 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2593 | }; |
| 2594 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2595 | // The proxy responds to the connect with a 407, using a non-persistent |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2596 | // connection. |
| 2597 | MockRead data_reads1[] = { |
| 2598 | // No credentials. |
| 2599 | MockRead("HTTP/1.0 407 Proxy Authentication Required\r\n"), |
| 2600 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n\r\n"), |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2601 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2602 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2603 | // Since the first connection couldn't be reused, need to establish another |
| 2604 | // once given credentials. |
| 2605 | MockWrite data_writes2[] = { |
| 2606 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2607 | // be issuing -- the final header line contains the credentials. |
| 2608 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 2609 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2610 | "Proxy-Connection: keep-alive\r\n" |
| 2611 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2612 | |
| 2613 | MockWrite("GET / HTTP/1.1\r\n" |
| 2614 | "Host: www.example.org\r\n" |
| 2615 | "Connection: keep-alive\r\n\r\n"), |
| 2616 | }; |
| 2617 | |
| 2618 | MockRead data_reads2[] = { |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2619 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 2620 | |
| 2621 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2622 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2623 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2624 | MockRead(SYNCHRONOUS, "hello"), |
| 2625 | }; |
| 2626 | |
| 2627 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2628 | data_writes1, arraysize(data_writes1)); |
| 2629 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2630 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2631 | data_writes2, arraysize(data_writes2)); |
| 2632 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2633 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 2634 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 2635 | |
| 2636 | TestCompletionCallback callback1; |
| 2637 | |
| 2638 | scoped_ptr<HttpTransaction> trans( |
| 2639 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 2640 | |
| 2641 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 2642 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2643 | |
| 2644 | rv = callback1.WaitForResult(); |
| 2645 | EXPECT_EQ(OK, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 2646 | TestNetLogEntry::List entries; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2647 | log.GetEntries(&entries); |
| 2648 | size_t pos = ExpectLogContainsSomewhere( |
| 2649 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 2650 | NetLog::PHASE_NONE); |
| 2651 | ExpectLogContainsSomewhere( |
| 2652 | entries, pos, NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 2653 | NetLog::PHASE_NONE); |
| 2654 | |
| 2655 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 2656 | ASSERT_TRUE(response != NULL); |
| 2657 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
| 2658 | ASSERT_FALSE(response->headers.get() == NULL); |
| 2659 | EXPECT_EQ(407, response->headers->response_code()); |
| 2660 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 2661 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 2662 | |
| 2663 | LoadTimingInfo load_timing_info; |
| 2664 | // CONNECT requests and responses are handled at the connect job level, so |
| 2665 | // the transaction does not yet have a connection. |
| 2666 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2667 | |
| 2668 | TestCompletionCallback callback2; |
| 2669 | |
| 2670 | rv = |
| 2671 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
| 2672 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2673 | |
| 2674 | rv = callback2.WaitForResult(); |
| 2675 | EXPECT_EQ(OK, rv); |
| 2676 | |
| 2677 | response = trans->GetResponseInfo(); |
| 2678 | ASSERT_TRUE(response != NULL); |
| 2679 | |
| 2680 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2681 | EXPECT_EQ(200, response->headers->response_code()); |
| 2682 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 2683 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 2684 | |
| 2685 | // The password prompt info should not be set. |
| 2686 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 2687 | |
| 2688 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2689 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 2690 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 2691 | |
| 2692 | trans.reset(); |
| 2693 | session->CloseAllConnections(); |
| 2694 | } |
| 2695 | |
| 2696 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 2697 | // that requires a restart when setting up an SSL tunnel. |
| 2698 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp11) { |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2699 | HttpRequestInfo request; |
| 2700 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2701 | request.url = GURL("https://www.example.org/"); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2702 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2703 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2704 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2705 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 2706 | session_deps_.proxy_service = |
| 2707 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2708 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2709 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 2710 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2711 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2712 | // Since we have proxy, should try to establish tunnel. |
| 2713 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2714 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 2715 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2716 | "Proxy-Connection: keep-alive\r\n\r\n"), |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 2717 | }; |
| 2718 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2719 | // The proxy responds to the connect with a 407, using a non-persistent |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 2720 | // connection. |
| 2721 | MockRead data_reads1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2722 | // No credentials. |
| 2723 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 2724 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2725 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 2726 | }; |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 2727 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2728 | MockWrite data_writes2[] = { |
| 2729 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2730 | // be issuing -- the final header line contains the credentials. |
| 2731 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 2732 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2733 | "Proxy-Connection: keep-alive\r\n" |
| 2734 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 2735 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2736 | MockWrite("GET / HTTP/1.1\r\n" |
| 2737 | "Host: www.example.org\r\n" |
| 2738 | "Connection: keep-alive\r\n\r\n"), |
| 2739 | }; |
| 2740 | |
| 2741 | MockRead data_reads2[] = { |
| 2742 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 2743 | |
| 2744 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2745 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2746 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2747 | MockRead(SYNCHRONOUS, "hello"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2748 | }; |
| 2749 | |
| 2750 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2751 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2752 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2753 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2754 | data_writes2, arraysize(data_writes2)); |
| 2755 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2756 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2757 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2758 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2759 | TestCompletionCallback callback1; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2760 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2761 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2762 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2763 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2764 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2765 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2766 | |
| 2767 | rv = callback1.WaitForResult(); |
| 2768 | EXPECT_EQ(OK, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 2769 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2770 | log.GetEntries(&entries); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2771 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2772 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2773 | NetLog::PHASE_NONE); |
| 2774 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2775 | entries, pos, |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2776 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 2777 | NetLog::PHASE_NONE); |
| 2778 | |
| 2779 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2780 | ASSERT_TRUE(response != NULL); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2781 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2782 | ASSERT_FALSE(response->headers.get() == NULL); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2783 | EXPECT_EQ(407, response->headers->response_code()); |
| 2784 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2785 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2786 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2787 | LoadTimingInfo load_timing_info; |
| 2788 | // CONNECT requests and responses are handled at the connect job level, so |
| 2789 | // the transaction does not yet have a connection. |
| 2790 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2791 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2792 | TestCompletionCallback callback2; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2793 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2794 | rv = trans->RestartWithAuth( |
| 2795 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2796 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2797 | |
| 2798 | rv = callback2.WaitForResult(); |
| 2799 | EXPECT_EQ(OK, rv); |
| 2800 | |
| 2801 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2802 | ASSERT_TRUE(response != NULL); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2803 | |
| 2804 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2805 | EXPECT_EQ(200, response->headers->response_code()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2806 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2807 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 2808 | |
| 2809 | // The password prompt info should not be set. |
| 2810 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2811 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2812 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2813 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 2814 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 2815 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2816 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 2817 | session->CloseAllConnections(); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2818 | } |
| 2819 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2820 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2821 | // proxy connection with HTTP/1.0 responses, when setting up an SSL tunnel. |
| 2822 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp10) { |
| 2823 | HttpRequestInfo request; |
| 2824 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2825 | request.url = GURL("https://www.example.org/"); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2826 | // Ensure that proxy authentication is attempted even |
| 2827 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2828 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2829 | |
| 2830 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 2831 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2832 | BoundTestNetLog log; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2833 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 2834 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2835 | |
| 2836 | scoped_ptr<HttpTransaction> trans( |
| 2837 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 2838 | |
| 2839 | // Since we have proxy, should try to establish tunnel. |
| 2840 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 2841 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2842 | "Host: www.example.org:443\r\n" |
| 2843 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2844 | |
| 2845 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2846 | // be issuing -- the final header line contains the credentials. |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 2847 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2848 | "Host: www.example.org:443\r\n" |
| 2849 | "Proxy-Connection: keep-alive\r\n" |
| 2850 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2851 | }; |
| 2852 | |
| 2853 | // The proxy responds to the connect with a 407, using a persistent |
| 2854 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 2855 | MockRead data_reads1[] = { |
| 2856 | // No credentials. |
| 2857 | MockRead("HTTP/1.0 407 Proxy Authentication Required\r\n"), |
| 2858 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2859 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 2860 | MockRead("Content-Length: 10\r\n\r\n"), |
| 2861 | MockRead("0123456789"), |
| 2862 | |
| 2863 | // Wrong credentials (wrong password). |
| 2864 | MockRead("HTTP/1.0 407 Proxy Authentication Required\r\n"), |
| 2865 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2866 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 2867 | MockRead("Content-Length: 10\r\n\r\n"), |
| 2868 | // No response body because the test stops reading here. |
| 2869 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 2870 | }; |
| 2871 | |
| 2872 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2873 | data_writes1, arraysize(data_writes1)); |
| 2874 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2875 | |
| 2876 | TestCompletionCallback callback1; |
| 2877 | |
| 2878 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 2879 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2880 | |
| 2881 | rv = callback1.WaitForResult(); |
| 2882 | EXPECT_EQ(OK, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 2883 | TestNetLogEntry::List entries; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2884 | log.GetEntries(&entries); |
| 2885 | size_t pos = ExpectLogContainsSomewhere( |
| 2886 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 2887 | NetLog::PHASE_NONE); |
| 2888 | ExpectLogContainsSomewhere( |
| 2889 | entries, pos, NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 2890 | NetLog::PHASE_NONE); |
| 2891 | |
| 2892 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 2893 | ASSERT_TRUE(response); |
| 2894 | ASSERT_TRUE(response->headers); |
| 2895 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2896 | EXPECT_EQ(407, response->headers->response_code()); |
| 2897 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 2898 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 2899 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 2900 | |
| 2901 | TestCompletionCallback callback2; |
| 2902 | |
| 2903 | // Wrong password (should be "bar"). |
| 2904 | rv = |
| 2905 | trans->RestartWithAuth(AuthCredentials(kFoo, kBaz), callback2.callback()); |
| 2906 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2907 | |
| 2908 | rv = callback2.WaitForResult(); |
| 2909 | EXPECT_EQ(OK, rv); |
| 2910 | |
| 2911 | response = trans->GetResponseInfo(); |
| 2912 | ASSERT_TRUE(response); |
| 2913 | ASSERT_TRUE(response->headers); |
| 2914 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2915 | EXPECT_EQ(407, response->headers->response_code()); |
| 2916 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 2917 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 2918 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 2919 | |
| 2920 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 2921 | // out of scope. |
| 2922 | session->CloseAllConnections(); |
| 2923 | } |
| 2924 | |
| 2925 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2926 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel. |
| 2927 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp11) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2928 | HttpRequestInfo request; |
| 2929 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2930 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2931 | // Ensure that proxy authentication is attempted even |
| 2932 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2933 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2934 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2935 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 2936 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2937 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2938 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 2939 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2940 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2941 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2942 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2943 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2944 | // Since we have proxy, should try to establish tunnel. |
| 2945 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 2946 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2947 | "Host: www.example.org:443\r\n" |
| 2948 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2949 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2950 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2951 | // be issuing -- the final header line contains the credentials. |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 2952 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2953 | "Host: www.example.org:443\r\n" |
| 2954 | "Proxy-Connection: keep-alive\r\n" |
| 2955 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2956 | }; |
| 2957 | |
| 2958 | // The proxy responds to the connect with a 407, using a persistent |
| 2959 | // connection. |
| 2960 | MockRead data_reads1[] = { |
| 2961 | // No credentials. |
| 2962 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 2963 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2964 | MockRead("Content-Length: 10\r\n\r\n"), |
| 2965 | MockRead("0123456789"), |
| 2966 | |
| 2967 | // Wrong credentials (wrong password). |
| 2968 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 2969 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2970 | MockRead("Content-Length: 10\r\n\r\n"), |
| 2971 | // No response body because the test stops reading here. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2972 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2973 | }; |
| 2974 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2975 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2976 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2977 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2978 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2979 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2980 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2981 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2982 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2983 | |
| 2984 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2985 | EXPECT_EQ(OK, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 2986 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2987 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 2988 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2989 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 2990 | NetLog::PHASE_NONE); |
| 2991 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2992 | entries, pos, |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 2993 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 2994 | NetLog::PHASE_NONE); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2995 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2996 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 2997 | ASSERT_TRUE(response); |
| 2998 | ASSERT_TRUE(response->headers); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2999 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3000 | EXPECT_EQ(407, response->headers->response_code()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3001 | EXPECT_EQ(10, response->headers->GetContentLength()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3002 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3003 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3004 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3005 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3006 | |
| 3007 | // Wrong password (should be "bar"). |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3008 | rv = trans->RestartWithAuth( |
| 3009 | AuthCredentials(kFoo, kBaz), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3010 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3011 | |
| 3012 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3013 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3014 | |
| 3015 | response = trans->GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3016 | ASSERT_TRUE(response); |
| 3017 | ASSERT_TRUE(response->headers); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3018 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3019 | EXPECT_EQ(407, response->headers->response_code()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3020 | EXPECT_EQ(10, response->headers->GetContentLength()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3021 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3022 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 3023 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 3024 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 3025 | // out of scope. |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3026 | session->CloseAllConnections(); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3027 | } |
| 3028 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3029 | // Test the case a proxy closes a socket while the challenge body is being |
| 3030 | // drained. |
| 3031 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHangupDuringBody) { |
| 3032 | HttpRequestInfo request; |
| 3033 | request.method = "GET"; |
| 3034 | request.url = GURL("https://www.example.org/"); |
| 3035 | // Ensure that proxy authentication is attempted even |
| 3036 | // when the no authentication data flag is set. |
| 3037 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
| 3038 | |
| 3039 | // Configure against proxy server "myproxy:70". |
| 3040 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 3041 | scoped_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3042 | |
| 3043 | scoped_ptr<HttpTransaction> trans( |
| 3044 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 3045 | |
| 3046 | // Since we have proxy, should try to establish tunnel. |
| 3047 | MockWrite data_writes1[] = { |
| 3048 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3049 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3050 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3051 | }; |
| 3052 | |
| 3053 | // The proxy responds to the connect with a 407, using a persistent |
| 3054 | // connection. |
| 3055 | MockRead data_reads1[] = { |
| 3056 | // No credentials. |
| 3057 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3058 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3059 | MockRead("Content-Length: 10\r\n\r\n"), MockRead("spam!"), |
| 3060 | // Server hands up in the middle of the body. |
| 3061 | MockRead(ASYNC, ERR_CONNECTION_CLOSED), |
| 3062 | }; |
| 3063 | |
| 3064 | MockWrite data_writes2[] = { |
| 3065 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3066 | // be issuing -- the final header line contains the credentials. |
| 3067 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3068 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3069 | "Proxy-Connection: keep-alive\r\n" |
| 3070 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3071 | |
| 3072 | MockWrite("GET / HTTP/1.1\r\n" |
| 3073 | "Host: www.example.org\r\n" |
| 3074 | "Connection: keep-alive\r\n\r\n"), |
| 3075 | }; |
| 3076 | |
| 3077 | MockRead data_reads2[] = { |
| 3078 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3079 | |
| 3080 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3081 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3082 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3083 | MockRead(SYNCHRONOUS, "hello"), |
| 3084 | }; |
| 3085 | |
| 3086 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3087 | data_writes1, arraysize(data_writes1)); |
| 3088 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3089 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3090 | data_writes2, arraysize(data_writes2)); |
| 3091 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3092 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3093 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3094 | |
| 3095 | TestCompletionCallback callback; |
| 3096 | |
| 3097 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 3098 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 3099 | |
| 3100 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3101 | ASSERT_TRUE(response); |
| 3102 | ASSERT_TRUE(response->headers); |
| 3103 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3104 | EXPECT_EQ(407, response->headers->response_code()); |
| 3105 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3106 | |
| 3107 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
| 3108 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 3109 | |
| 3110 | response = trans->GetResponseInfo(); |
| 3111 | ASSERT_TRUE(response); |
| 3112 | ASSERT_TRUE(response->headers); |
| 3113 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3114 | EXPECT_EQ(200, response->headers->response_code()); |
| 3115 | std::string body; |
| 3116 | EXPECT_EQ(OK, ReadTransaction(trans.get(), &body)); |
| 3117 | EXPECT_EQ("hello", body); |
| 3118 | } |
| 3119 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3120 | // Test that we don't read the response body when we fail to establish a tunnel, |
| 3121 | // even if the user cancels the proxy's auth attempt. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3122 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyCancelTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3123 | HttpRequestInfo request; |
| 3124 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3125 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3126 | request.load_flags = 0; |
| 3127 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3128 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3129 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3130 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 3131 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3132 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3133 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3134 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3135 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3136 | // Since we have proxy, should try to establish tunnel. |
| 3137 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3138 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3139 | "Host: www.example.org:443\r\n" |
| 3140 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3141 | }; |
| 3142 | |
| 3143 | // The proxy responds to the connect with a 407. |
| 3144 | MockRead data_reads[] = { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3145 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3146 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3147 | MockRead("Content-Length: 10\r\n\r\n"), |
| 3148 | MockRead("0123456789"), // Should not be reached. |
| 3149 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3150 | }; |
| 3151 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 3152 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 3153 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3154 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3155 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3156 | TestCompletionCallback callback; |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3157 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3158 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3159 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3160 | |
| 3161 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3162 | EXPECT_EQ(OK, rv); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3163 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3164 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3165 | ASSERT_TRUE(response); |
| 3166 | ASSERT_TRUE(response->headers); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3167 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3168 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3169 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3170 | |
| 3171 | std::string response_data; |
| 3172 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3173 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 3174 | |
| 3175 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3176 | session->CloseAllConnections(); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3177 | } |
| 3178 | |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3179 | // Test that we don't pass extraneous headers from the proxy's response to the |
| 3180 | // caller when the proxy responds to CONNECT with 407. |
| 3181 | TEST_P(HttpNetworkTransactionTest, SanitizeProxyAuthHeaders) { |
| 3182 | HttpRequestInfo request; |
| 3183 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3184 | request.url = GURL("https://www.example.org/"); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3185 | request.load_flags = 0; |
| 3186 | |
| 3187 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3188 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3189 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 3190 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3191 | |
| 3192 | scoped_ptr<HttpTransaction> trans( |
| 3193 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 3194 | |
| 3195 | // Since we have proxy, should try to establish tunnel. |
| 3196 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3197 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3198 | "Host: www.example.org:443\r\n" |
| 3199 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3200 | }; |
| 3201 | |
| 3202 | // The proxy responds to the connect with a 407. |
| 3203 | MockRead data_reads[] = { |
| 3204 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3205 | MockRead("X-Foo: bar\r\n"), |
| 3206 | MockRead("Set-Cookie: foo=bar\r\n"), |
| 3207 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3208 | MockRead("Content-Length: 10\r\n\r\n"), |
| 3209 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 3210 | }; |
| 3211 | |
| 3212 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 3213 | arraysize(data_writes)); |
| 3214 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 3215 | |
| 3216 | TestCompletionCallback callback; |
| 3217 | |
| 3218 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 3219 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3220 | |
| 3221 | rv = callback.WaitForResult(); |
| 3222 | EXPECT_EQ(OK, rv); |
| 3223 | |
| 3224 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3225 | ASSERT_TRUE(response); |
| 3226 | ASSERT_TRUE(response->headers); |
| 3227 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3228 | EXPECT_EQ(407, response->headers->response_code()); |
| 3229 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3230 | EXPECT_FALSE(response->headers->HasHeader("X-Foo")); |
| 3231 | EXPECT_FALSE(response->headers->HasHeader("Set-Cookie")); |
| 3232 | |
| 3233 | std::string response_data; |
| 3234 | rv = ReadTransaction(trans.get(), &response_data); |
| 3235 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
| 3236 | |
| 3237 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
| 3238 | session->CloseAllConnections(); |
| 3239 | } |
| 3240 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3241 | // Test when a server (non-proxy) returns a 407 (proxy-authenticate). |
| 3242 | // The request should fail with ERR_UNEXPECTED_PROXY_AUTH. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3243 | TEST_P(HttpNetworkTransactionTest, UnexpectedProxyAuth) { |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3244 | HttpRequestInfo request; |
| 3245 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3246 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3247 | request.load_flags = 0; |
| 3248 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3249 | // We are using a DIRECT connection (i.e. no proxy) for this session. |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 3250 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3251 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 3252 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3253 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3254 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3255 | MockWrite( |
| 3256 | "GET / HTTP/1.1\r\n" |
| 3257 | "Host: www.example.org\r\n" |
| 3258 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3259 | }; |
| 3260 | |
| 3261 | MockRead data_reads1[] = { |
| 3262 | MockRead("HTTP/1.0 407 Proxy Auth required\r\n"), |
| 3263 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3264 | // Large content-length -- won't matter, as connection will be reset. |
| 3265 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3266 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3267 | }; |
| 3268 | |
| 3269 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3270 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3271 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3272 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3273 | TestCompletionCallback callback; |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3274 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3275 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3276 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3277 | |
| 3278 | rv = callback.WaitForResult(); |
| 3279 | EXPECT_EQ(ERR_UNEXPECTED_PROXY_AUTH, rv); |
| 3280 | } |
| 3281 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3282 | // Tests when an HTTPS server (non-proxy) returns a 407 (proxy-authentication) |
| 3283 | // through a non-authenticating proxy. The request should fail with |
| 3284 | // ERR_UNEXPECTED_PROXY_AUTH. |
| 3285 | // Note that it is impossible to detect if an HTTP server returns a 407 through |
| 3286 | // a non-authenticating proxy - there is nothing to indicate whether the |
| 3287 | // response came from the proxy or the server, so it is treated as if the proxy |
| 3288 | // issued the challenge. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3289 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 3290 | HttpsServerRequestsProxyAuthThroughProxy) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3291 | HttpRequestInfo request; |
| 3292 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3293 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3294 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3295 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3296 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3297 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 3298 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3299 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3300 | // Since we have proxy, should try to establish tunnel. |
| 3301 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3302 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3303 | "Host: www.example.org:443\r\n" |
| 3304 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3305 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3306 | MockWrite("GET / HTTP/1.1\r\n" |
| 3307 | "Host: www.example.org\r\n" |
| 3308 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3309 | }; |
| 3310 | |
| 3311 | MockRead data_reads1[] = { |
| 3312 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3313 | |
| 3314 | MockRead("HTTP/1.1 407 Unauthorized\r\n"), |
| 3315 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3316 | MockRead("\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3317 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3318 | }; |
| 3319 | |
| 3320 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3321 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3322 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3323 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3324 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3325 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3326 | TestCompletionCallback callback1; |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3327 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3328 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3329 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3330 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3331 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3332 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3333 | |
| 3334 | rv = callback1.WaitForResult(); |
| 3335 | EXPECT_EQ(ERR_UNEXPECTED_PROXY_AUTH, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3336 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3337 | log.GetEntries(&entries); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3338 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3339 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3340 | NetLog::PHASE_NONE); |
| 3341 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3342 | entries, pos, |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3343 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3344 | NetLog::PHASE_NONE); |
| 3345 | } |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3346 | |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3347 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 3348 | // that uses non-persistent connections. |
| 3349 | TEST_P(HttpNetworkTransactionTest, |
| 3350 | AuthAllowsDefaultCredentialsTunnelConnectionClose) { |
| 3351 | HttpRequestInfo request; |
| 3352 | request.method = "GET"; |
| 3353 | request.url = GURL("https://www.example.org/"); |
| 3354 | |
| 3355 | // Configure against proxy server "myproxy:70". |
| 3356 | session_deps_.proxy_service = |
| 3357 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 3358 | |
| 3359 | scoped_ptr<HttpAuthHandlerMock::Factory> auth_handler_factory( |
| 3360 | new HttpAuthHandlerMock::Factory()); |
| 3361 | auth_handler_factory->set_do_init_from_challenge(true); |
| 3362 | scoped_ptr<HttpAuthHandlerMock> mock_handler(new HttpAuthHandlerMock()); |
| 3363 | mock_handler->set_allows_default_credentials(true); |
| 3364 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 3365 | HttpAuth::AUTH_PROXY); |
| 3366 | session_deps_.http_auth_handler_factory = auth_handler_factory.Pass(); |
| 3367 | |
| 3368 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 3369 | NetLog net_log; |
| 3370 | session_deps_.net_log = &net_log; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 3371 | scoped_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3372 | |
| 3373 | // Since we have proxy, should try to establish tunnel. |
| 3374 | MockWrite data_writes1[] = { |
| 3375 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3376 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3377 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3378 | }; |
| 3379 | |
| 3380 | // The proxy responds to the connect with a 407, using a non-persistent |
| 3381 | // connection. |
| 3382 | MockRead data_reads1[] = { |
| 3383 | // No credentials. |
| 3384 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3385 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 3386 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 3387 | }; |
| 3388 | |
| 3389 | // Since the first connection couldn't be reused, need to establish another |
| 3390 | // once given credentials. |
| 3391 | MockWrite data_writes2[] = { |
| 3392 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3393 | // be issuing -- the final header line contains the credentials. |
| 3394 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3395 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3396 | "Proxy-Connection: keep-alive\r\n" |
| 3397 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 3398 | |
| 3399 | MockWrite("GET / HTTP/1.1\r\n" |
| 3400 | "Host: www.example.org\r\n" |
| 3401 | "Connection: keep-alive\r\n\r\n"), |
| 3402 | }; |
| 3403 | |
| 3404 | MockRead data_reads2[] = { |
| 3405 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 3406 | |
| 3407 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3408 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3409 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3410 | MockRead(SYNCHRONOUS, "hello"), |
| 3411 | }; |
| 3412 | |
| 3413 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3414 | data_writes1, arraysize(data_writes1)); |
| 3415 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3416 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3417 | data_writes2, arraysize(data_writes2)); |
| 3418 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3419 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3420 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3421 | |
| 3422 | scoped_ptr<HttpTransaction> trans( |
| 3423 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 3424 | |
| 3425 | TestCompletionCallback callback; |
| 3426 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 3427 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 3428 | |
| 3429 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3430 | ASSERT_TRUE(response); |
| 3431 | ASSERT_TRUE(response->headers); |
| 3432 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
| 3433 | EXPECT_EQ(407, response->headers->response_code()); |
| 3434 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3435 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 3436 | EXPECT_FALSE(response->auth_challenge.get()); |
| 3437 | |
| 3438 | LoadTimingInfo load_timing_info; |
| 3439 | // CONNECT requests and responses are handled at the connect job level, so |
| 3440 | // the transaction does not yet have a connection. |
| 3441 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3442 | |
| 3443 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 3444 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 3445 | response = trans->GetResponseInfo(); |
| 3446 | ASSERT_TRUE(response); |
| 3447 | ASSERT_TRUE(response->headers); |
| 3448 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3449 | EXPECT_EQ(200, response->headers->response_code()); |
| 3450 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 3451 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3452 | |
| 3453 | // The password prompt info should not be set. |
| 3454 | EXPECT_FALSE(response->auth_challenge); |
| 3455 | |
| 3456 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3457 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3458 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3459 | |
| 3460 | trans.reset(); |
| 3461 | session->CloseAllConnections(); |
| 3462 | } |
| 3463 | |
| 3464 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 3465 | // that hangs up when credentials are initially sent. |
| 3466 | TEST_P(HttpNetworkTransactionTest, |
| 3467 | AuthAllowsDefaultCredentialsTunnelServerClosesConnection) { |
| 3468 | HttpRequestInfo request; |
| 3469 | request.method = "GET"; |
| 3470 | request.url = GURL("https://www.example.org/"); |
| 3471 | |
| 3472 | // Configure against proxy server "myproxy:70". |
| 3473 | session_deps_.proxy_service = |
| 3474 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 3475 | |
| 3476 | scoped_ptr<HttpAuthHandlerMock::Factory> auth_handler_factory( |
| 3477 | new HttpAuthHandlerMock::Factory()); |
| 3478 | auth_handler_factory->set_do_init_from_challenge(true); |
| 3479 | scoped_ptr<HttpAuthHandlerMock> mock_handler(new HttpAuthHandlerMock()); |
| 3480 | mock_handler->set_allows_default_credentials(true); |
| 3481 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 3482 | HttpAuth::AUTH_PROXY); |
| 3483 | session_deps_.http_auth_handler_factory = auth_handler_factory.Pass(); |
| 3484 | |
| 3485 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 3486 | NetLog net_log; |
| 3487 | session_deps_.net_log = &net_log; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 3488 | scoped_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3489 | |
| 3490 | // Should try to establish tunnel. |
| 3491 | MockWrite data_writes1[] = { |
| 3492 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3493 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3494 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3495 | |
| 3496 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3497 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3498 | "Proxy-Connection: keep-alive\r\n" |
| 3499 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 3500 | }; |
| 3501 | |
| 3502 | // The proxy responds to the connect with a 407, using a non-persistent |
| 3503 | // connection. |
| 3504 | MockRead data_reads1[] = { |
| 3505 | // No credentials. |
| 3506 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3507 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 3508 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 3509 | }; |
| 3510 | |
| 3511 | // Since the first connection was closed, need to establish another once given |
| 3512 | // credentials. |
| 3513 | MockWrite data_writes2[] = { |
| 3514 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3515 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3516 | "Proxy-Connection: keep-alive\r\n" |
| 3517 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 3518 | |
| 3519 | MockWrite("GET / HTTP/1.1\r\n" |
| 3520 | "Host: www.example.org\r\n" |
| 3521 | "Connection: keep-alive\r\n\r\n"), |
| 3522 | }; |
| 3523 | |
| 3524 | MockRead data_reads2[] = { |
| 3525 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 3526 | |
| 3527 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3528 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3529 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3530 | MockRead(SYNCHRONOUS, "hello"), |
| 3531 | }; |
| 3532 | |
| 3533 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3534 | data_writes1, arraysize(data_writes1)); |
| 3535 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3536 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3537 | data_writes2, arraysize(data_writes2)); |
| 3538 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3539 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3540 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3541 | |
| 3542 | scoped_ptr<HttpTransaction> trans( |
| 3543 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 3544 | |
| 3545 | TestCompletionCallback callback; |
| 3546 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 3547 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 3548 | |
| 3549 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3550 | ASSERT_TRUE(response); |
| 3551 | ASSERT_TRUE(response->headers); |
| 3552 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3553 | EXPECT_EQ(407, response->headers->response_code()); |
| 3554 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3555 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 3556 | EXPECT_FALSE(response->auth_challenge); |
| 3557 | |
| 3558 | LoadTimingInfo load_timing_info; |
| 3559 | // CONNECT requests and responses are handled at the connect job level, so |
| 3560 | // the transaction does not yet have a connection. |
| 3561 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3562 | |
| 3563 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 3564 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 3565 | |
| 3566 | response = trans->GetResponseInfo(); |
| 3567 | ASSERT_TRUE(response); |
| 3568 | ASSERT_TRUE(response->headers); |
| 3569 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3570 | EXPECT_EQ(200, response->headers->response_code()); |
| 3571 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 3572 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3573 | |
| 3574 | // The password prompt info should not be set. |
| 3575 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 3576 | |
| 3577 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3578 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3579 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3580 | |
| 3581 | trans.reset(); |
| 3582 | session->CloseAllConnections(); |
| 3583 | } |
| 3584 | |
| 3585 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 3586 | // that hangs up when credentials are initially sent, and hangs up again when |
| 3587 | // they are retried. |
| 3588 | TEST_P(HttpNetworkTransactionTest, |
| 3589 | AuthAllowsDefaultCredentialsTunnelServerClosesConnectionTwice) { |
| 3590 | HttpRequestInfo request; |
| 3591 | request.method = "GET"; |
| 3592 | request.url = GURL("https://www.example.org/"); |
| 3593 | |
| 3594 | // Configure against proxy server "myproxy:70". |
| 3595 | session_deps_.proxy_service = |
| 3596 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 3597 | |
| 3598 | scoped_ptr<HttpAuthHandlerMock::Factory> auth_handler_factory( |
| 3599 | new HttpAuthHandlerMock::Factory()); |
| 3600 | auth_handler_factory->set_do_init_from_challenge(true); |
| 3601 | scoped_ptr<HttpAuthHandlerMock> mock_handler(new HttpAuthHandlerMock()); |
| 3602 | mock_handler->set_allows_default_credentials(true); |
| 3603 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 3604 | HttpAuth::AUTH_PROXY); |
| 3605 | session_deps_.http_auth_handler_factory = auth_handler_factory.Pass(); |
| 3606 | |
| 3607 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 3608 | NetLog net_log; |
| 3609 | session_deps_.net_log = &net_log; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 3610 | scoped_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3611 | |
| 3612 | // Should try to establish tunnel. |
| 3613 | MockWrite data_writes1[] = { |
| 3614 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3615 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3616 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3617 | |
| 3618 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3619 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3620 | "Proxy-Connection: keep-alive\r\n" |
| 3621 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 3622 | }; |
| 3623 | |
| 3624 | // The proxy responds to the connect with a 407, and then hangs up after the |
| 3625 | // second request is sent. |
| 3626 | MockRead data_reads1[] = { |
| 3627 | // No credentials. |
| 3628 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3629 | MockRead("Content-Length: 0\r\n"), |
| 3630 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 3631 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 3632 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 3633 | }; |
| 3634 | |
| 3635 | // HttpNetworkTransaction sees a reused connection that was closed with |
| 3636 | // ERR_CONNECTION_CLOSED, realized it might have been a race, so retries the |
| 3637 | // request. |
| 3638 | MockWrite data_writes2[] = { |
| 3639 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3640 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3641 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3642 | }; |
| 3643 | |
| 3644 | // The proxy, having had more than enough of us, just hangs up. |
| 3645 | MockRead data_reads2[] = { |
| 3646 | // No credentials. |
| 3647 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 3648 | }; |
| 3649 | |
| 3650 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3651 | data_writes1, arraysize(data_writes1)); |
| 3652 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3653 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3654 | data_writes2, arraysize(data_writes2)); |
| 3655 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3656 | |
| 3657 | scoped_ptr<HttpTransaction> trans( |
| 3658 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 3659 | |
| 3660 | TestCompletionCallback callback; |
| 3661 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 3662 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 3663 | |
| 3664 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3665 | ASSERT_TRUE(response); |
| 3666 | ASSERT_TRUE(response->headers); |
| 3667 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3668 | EXPECT_EQ(407, response->headers->response_code()); |
| 3669 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3670 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 3671 | EXPECT_FALSE(response->auth_challenge); |
| 3672 | |
| 3673 | LoadTimingInfo load_timing_info; |
| 3674 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3675 | |
| 3676 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 3677 | EXPECT_EQ(ERR_EMPTY_RESPONSE, callback.GetResult(rv)); |
| 3678 | |
| 3679 | trans.reset(); |
| 3680 | session->CloseAllConnections(); |
| 3681 | } |
| 3682 | |
| 3683 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 3684 | // that hangs up when credentials are initially sent, and sends a challenge |
| 3685 | // again they are retried. |
| 3686 | TEST_P(HttpNetworkTransactionTest, |
| 3687 | AuthAllowsDefaultCredentialsTunnelServerChallengesTwice) { |
| 3688 | HttpRequestInfo request; |
| 3689 | request.method = "GET"; |
| 3690 | request.url = GURL("https://www.example.org/"); |
| 3691 | |
| 3692 | // Configure against proxy server "myproxy:70". |
| 3693 | session_deps_.proxy_service = |
| 3694 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 3695 | |
| 3696 | scoped_ptr<HttpAuthHandlerMock::Factory> auth_handler_factory( |
| 3697 | new HttpAuthHandlerMock::Factory()); |
| 3698 | auth_handler_factory->set_do_init_from_challenge(true); |
| 3699 | scoped_ptr<HttpAuthHandlerMock> mock_handler(new HttpAuthHandlerMock()); |
| 3700 | mock_handler->set_allows_default_credentials(true); |
| 3701 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 3702 | HttpAuth::AUTH_PROXY); |
| 3703 | // Add another handler for the second challenge. It supports default |
| 3704 | // credentials, but they shouldn't be used, since they were already tried. |
| 3705 | mock_handler.reset(new HttpAuthHandlerMock()); |
| 3706 | mock_handler->set_allows_default_credentials(true); |
| 3707 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 3708 | HttpAuth::AUTH_PROXY); |
| 3709 | session_deps_.http_auth_handler_factory = auth_handler_factory.Pass(); |
| 3710 | |
| 3711 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 3712 | NetLog net_log; |
| 3713 | session_deps_.net_log = &net_log; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 3714 | scoped_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3715 | |
| 3716 | // Should try to establish tunnel. |
| 3717 | MockWrite data_writes1[] = { |
| 3718 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3719 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3720 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3721 | }; |
| 3722 | |
| 3723 | // The proxy responds to the connect with a 407, using a non-persistent |
| 3724 | // connection. |
| 3725 | MockRead data_reads1[] = { |
| 3726 | // No credentials. |
| 3727 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3728 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 3729 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 3730 | }; |
| 3731 | |
| 3732 | // Since the first connection was closed, need to establish another once given |
| 3733 | // credentials. |
| 3734 | MockWrite data_writes2[] = { |
| 3735 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3736 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3737 | "Proxy-Connection: keep-alive\r\n" |
| 3738 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 3739 | }; |
| 3740 | |
| 3741 | MockRead data_reads2[] = { |
| 3742 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3743 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 3744 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 3745 | }; |
| 3746 | |
| 3747 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3748 | data_writes1, arraysize(data_writes1)); |
| 3749 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3750 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3751 | data_writes2, arraysize(data_writes2)); |
| 3752 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3753 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3754 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3755 | |
| 3756 | scoped_ptr<HttpTransaction> trans( |
| 3757 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 3758 | |
| 3759 | TestCompletionCallback callback; |
| 3760 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 3761 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 3762 | |
| 3763 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3764 | ASSERT_TRUE(response); |
| 3765 | ASSERT_TRUE(response->headers); |
| 3766 | EXPECT_EQ(407, response->headers->response_code()); |
| 3767 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3768 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 3769 | EXPECT_FALSE(response->auth_challenge); |
| 3770 | |
| 3771 | LoadTimingInfo load_timing_info; |
| 3772 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3773 | |
| 3774 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 3775 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 3776 | response = trans->GetResponseInfo(); |
| 3777 | ASSERT_TRUE(response); |
| 3778 | ASSERT_TRUE(response->headers); |
| 3779 | EXPECT_EQ(407, response->headers->response_code()); |
| 3780 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 3781 | EXPECT_TRUE(response->auth_challenge); |
| 3782 | |
| 3783 | trans.reset(); |
| 3784 | session->CloseAllConnections(); |
| 3785 | } |
| 3786 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3787 | // Test the load timing for HTTPS requests with an HTTP proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3788 | TEST_P(HttpNetworkTransactionTest, HttpProxyLoadTimingNoPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3789 | HttpRequestInfo request1; |
| 3790 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3791 | request1.url = GURL("https://www.example.org/1"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3792 | |
| 3793 | HttpRequestInfo request2; |
| 3794 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3795 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3796 | |
| 3797 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3798 | session_deps_.proxy_service = ProxyService::CreateFixed("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3799 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3800 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 3801 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3802 | |
| 3803 | // Since we have proxy, should try to establish tunnel. |
| 3804 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3805 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3806 | "Host: www.example.org:443\r\n" |
| 3807 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3808 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3809 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 3810 | "Host: www.example.org\r\n" |
| 3811 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3812 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3813 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 3814 | "Host: www.example.org\r\n" |
| 3815 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3816 | }; |
| 3817 | |
| 3818 | // The proxy responds to the connect with a 407, using a persistent |
| 3819 | // connection. |
| 3820 | MockRead data_reads1[] = { |
| 3821 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3822 | |
| 3823 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3824 | MockRead("Content-Length: 1\r\n\r\n"), |
| 3825 | MockRead(SYNCHRONOUS, "1"), |
| 3826 | |
| 3827 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3828 | MockRead("Content-Length: 2\r\n\r\n"), |
| 3829 | MockRead(SYNCHRONOUS, "22"), |
| 3830 | }; |
| 3831 | |
| 3832 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3833 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3834 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3835 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3836 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3837 | |
| 3838 | TestCompletionCallback callback1; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3839 | scoped_ptr<HttpTransaction> trans1( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3840 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3841 | |
| 3842 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
| 3843 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3844 | |
| 3845 | rv = callback1.WaitForResult(); |
| 3846 | EXPECT_EQ(OK, rv); |
| 3847 | |
| 3848 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 3849 | ASSERT_TRUE(response1 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3850 | ASSERT_TRUE(response1->headers.get() != NULL); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3851 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 3852 | |
| 3853 | LoadTimingInfo load_timing_info1; |
| 3854 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 3855 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_SSL_TIMES); |
| 3856 | |
| 3857 | trans1.reset(); |
| 3858 | |
| 3859 | TestCompletionCallback callback2; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3860 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3861 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3862 | |
| 3863 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
| 3864 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3865 | |
| 3866 | rv = callback2.WaitForResult(); |
| 3867 | EXPECT_EQ(OK, rv); |
| 3868 | |
| 3869 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 3870 | ASSERT_TRUE(response2 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3871 | ASSERT_TRUE(response2->headers.get() != NULL); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3872 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 3873 | |
| 3874 | LoadTimingInfo load_timing_info2; |
| 3875 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 3876 | TestLoadTimingReused(load_timing_info2); |
| 3877 | |
| 3878 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 3879 | |
| 3880 | trans2.reset(); |
| 3881 | session->CloseAllConnections(); |
| 3882 | } |
| 3883 | |
| 3884 | // 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] | 3885 | TEST_P(HttpNetworkTransactionTest, HttpProxyLoadTimingWithPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3886 | HttpRequestInfo request1; |
| 3887 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3888 | request1.url = GURL("https://www.example.org/1"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3889 | |
| 3890 | HttpRequestInfo request2; |
| 3891 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3892 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3893 | |
| 3894 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3895 | session_deps_.proxy_service = |
| 3896 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3897 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3898 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 3899 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3900 | |
| 3901 | // Since we have proxy, should try to establish tunnel. |
| 3902 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3903 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3904 | "Host: www.example.org:443\r\n" |
| 3905 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3906 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3907 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 3908 | "Host: www.example.org\r\n" |
| 3909 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3910 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3911 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 3912 | "Host: www.example.org\r\n" |
| 3913 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3914 | }; |
| 3915 | |
| 3916 | // The proxy responds to the connect with a 407, using a persistent |
| 3917 | // connection. |
| 3918 | MockRead data_reads1[] = { |
| 3919 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3920 | |
| 3921 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3922 | MockRead("Content-Length: 1\r\n\r\n"), |
| 3923 | MockRead(SYNCHRONOUS, "1"), |
| 3924 | |
| 3925 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3926 | MockRead("Content-Length: 2\r\n\r\n"), |
| 3927 | MockRead(SYNCHRONOUS, "22"), |
| 3928 | }; |
| 3929 | |
| 3930 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3931 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3932 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3933 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3934 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3935 | |
| 3936 | TestCompletionCallback callback1; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3937 | scoped_ptr<HttpTransaction> trans1( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3938 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3939 | |
| 3940 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
| 3941 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3942 | |
| 3943 | rv = callback1.WaitForResult(); |
| 3944 | EXPECT_EQ(OK, rv); |
| 3945 | |
| 3946 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 3947 | ASSERT_TRUE(response1 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3948 | ASSERT_TRUE(response1->headers.get() != NULL); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3949 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 3950 | |
| 3951 | LoadTimingInfo load_timing_info1; |
| 3952 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 3953 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 3954 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3955 | |
| 3956 | trans1.reset(); |
| 3957 | |
| 3958 | TestCompletionCallback callback2; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3959 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3960 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3961 | |
| 3962 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
| 3963 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3964 | |
| 3965 | rv = callback2.WaitForResult(); |
| 3966 | EXPECT_EQ(OK, rv); |
| 3967 | |
| 3968 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 3969 | ASSERT_TRUE(response2 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3970 | ASSERT_TRUE(response2->headers.get() != NULL); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3971 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 3972 | |
| 3973 | LoadTimingInfo load_timing_info2; |
| 3974 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 3975 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 3976 | |
| 3977 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 3978 | |
| 3979 | trans2.reset(); |
| 3980 | session->CloseAllConnections(); |
| 3981 | } |
| 3982 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3983 | // Test a simple get through an HTTPS Proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3984 | TEST_P(HttpNetworkTransactionTest, HttpsProxyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3985 | HttpRequestInfo request; |
| 3986 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3987 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3988 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3989 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3990 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3991 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3992 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 3993 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3994 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3995 | // Since we have proxy, should use full url |
| 3996 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3997 | MockWrite( |
| 3998 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 3999 | "Host: www.example.org\r\n" |
| 4000 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4001 | }; |
| 4002 | |
| 4003 | MockRead data_reads1[] = { |
| 4004 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4005 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4006 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4007 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4008 | }; |
| 4009 | |
| 4010 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4011 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4012 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4013 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4014 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4015 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4016 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4017 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4018 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4019 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4020 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4021 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4022 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4023 | |
| 4024 | rv = callback1.WaitForResult(); |
| 4025 | EXPECT_EQ(OK, rv); |
| 4026 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4027 | LoadTimingInfo load_timing_info; |
| 4028 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4029 | TestLoadTimingNotReused(load_timing_info, |
| 4030 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 4031 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4032 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4033 | ASSERT_TRUE(response != NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4034 | |
| 4035 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4036 | EXPECT_EQ(200, response->headers->response_code()); |
| 4037 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 4038 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4039 | |
| 4040 | // The password prompt info should not be set. |
| 4041 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 4042 | } |
| 4043 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4044 | // Test a SPDY get through an HTTPS Proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4045 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4046 | HttpRequestInfo request; |
| 4047 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4048 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4049 | request.load_flags = 0; |
| 4050 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4051 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4052 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4053 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4054 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4055 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4056 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4057 | // fetch http://www.example.org/ via SPDY |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4058 | scoped_ptr<SpdyFrame> req( |
| 4059 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4060 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4061 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4062 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 4063 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4064 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4065 | CreateMockRead(*resp, 1), CreateMockRead(*data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4066 | }; |
| 4067 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4068 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4069 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4070 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4071 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4072 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4073 | ssl.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4074 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4075 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4076 | TestCompletionCallback callback1; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4077 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4078 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4079 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4080 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4081 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4082 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4083 | |
| 4084 | rv = callback1.WaitForResult(); |
| 4085 | EXPECT_EQ(OK, rv); |
| 4086 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4087 | LoadTimingInfo load_timing_info; |
| 4088 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4089 | TestLoadTimingNotReused(load_timing_info, |
| 4090 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 4091 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4092 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4093 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4094 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame^] | 4095 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4096 | |
| 4097 | std::string response_data; |
| 4098 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 4099 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4100 | } |
| 4101 | |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4102 | // Verifies that a session which races and wins against the owning transaction |
| 4103 | // (completing prior to host resolution), doesn't fail the transaction. |
| 4104 | // Regression test for crbug.com/334413. |
| 4105 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyGetWithSessionRace) { |
| 4106 | HttpRequestInfo request; |
| 4107 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4108 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4109 | request.load_flags = 0; |
| 4110 | |
| 4111 | // Configure SPDY proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4112 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4113 | BoundTestNetLog log; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4114 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4115 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4116 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4117 | // Fetch http://www.example.org/ through the SPDY proxy. |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4118 | scoped_ptr<SpdyFrame> req( |
| 4119 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4120 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4121 | |
| 4122 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 4123 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 4124 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4125 | CreateMockRead(*resp, 1), CreateMockRead(*data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4126 | }; |
| 4127 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4128 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4129 | arraysize(spdy_writes)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4130 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 4131 | |
| 4132 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4133 | ssl.SetNextProto(GetProtocol()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4134 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4135 | |
| 4136 | TestCompletionCallback callback1; |
| 4137 | |
| 4138 | scoped_ptr<HttpTransaction> trans( |
| 4139 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 4140 | |
| 4141 | // Stall the hostname resolution begun by the transaction. |
| 4142 | session_deps_.host_resolver->set_synchronous_mode(false); |
| 4143 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 4144 | |
| 4145 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 4146 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4147 | |
| 4148 | // Race a session to the proxy, which completes first. |
| 4149 | session_deps_.host_resolver->set_ondemand_mode(false); |
| 4150 | SpdySessionKey key( |
| 4151 | HostPortPair("proxy", 70), ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
| 4152 | base::WeakPtr<SpdySession> spdy_session = |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4153 | CreateSecureSpdySession(session.get(), key, log.bound()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4154 | |
| 4155 | // Unstall the resolution begun by the transaction. |
| 4156 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 4157 | session_deps_.host_resolver->ResolveAllPending(); |
| 4158 | |
| 4159 | EXPECT_FALSE(callback1.have_result()); |
| 4160 | rv = callback1.WaitForResult(); |
| 4161 | EXPECT_EQ(OK, rv); |
| 4162 | |
| 4163 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4164 | ASSERT_TRUE(response != NULL); |
| 4165 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame^] | 4166 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4167 | |
| 4168 | std::string response_data; |
| 4169 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 4170 | EXPECT_EQ(kUploadData, response_data); |
| 4171 | } |
| 4172 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4173 | // Test a SPDY get through an HTTPS Proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4174 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyGetWithProxyAuth) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4175 | HttpRequestInfo request; |
| 4176 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4177 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4178 | request.load_flags = 0; |
| 4179 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4180 | // Configure against https proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4181 | session_deps_.proxy_service = ProxyService::CreateFixed("https://myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4182 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4183 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4184 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4185 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4186 | // The first request will be a bare GET, the second request will be a |
| 4187 | // GET with a Proxy-Authorization header. |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4188 | scoped_ptr<SpdyFrame> req_get( |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4189 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4190 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4191 | const char* const kExtraAuthorizationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4192 | "proxy-authorization", "Basic Zm9vOmJhcg==" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4193 | }; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4194 | scoped_ptr<SpdyFrame> req_get_authorization( |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4195 | spdy_util_.ConstructSpdyGet(kExtraAuthorizationHeaders, |
| 4196 | arraysize(kExtraAuthorizationHeaders) / 2, |
| 4197 | false, |
| 4198 | 3, |
| 4199 | LOWEST, |
| 4200 | false)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4201 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4202 | CreateMockWrite(*req_get, 0), CreateMockWrite(*req_get_authorization, 3), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4203 | }; |
| 4204 | |
| 4205 | // The first response is a 407 proxy authentication challenge, and the second |
| 4206 | // response will be a 200 response since the second request includes a valid |
| 4207 | // Authorization header. |
| 4208 | const char* const kExtraAuthenticationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4209 | "proxy-authenticate", "Basic realm=\"MyRealm1\"" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4210 | }; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4211 | scoped_ptr<SpdyFrame> resp_authentication( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4212 | spdy_util_.ConstructSpdySynReplyError( |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4213 | "407 Proxy Authentication Required", |
| 4214 | kExtraAuthenticationHeaders, arraysize(kExtraAuthenticationHeaders)/2, |
| 4215 | 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4216 | scoped_ptr<SpdyFrame> body_authentication( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4217 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 4218 | scoped_ptr<SpdyFrame> resp_data( |
| 4219 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 4220 | scoped_ptr<SpdyFrame> body_data(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4221 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4222 | CreateMockRead(*resp_authentication, 1), |
| 4223 | CreateMockRead(*body_authentication, 2), |
| 4224 | CreateMockRead(*resp_data, 4), |
| 4225 | CreateMockRead(*body_data, 5), |
| 4226 | MockRead(ASYNC, 0, 6), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4227 | }; |
| 4228 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4229 | SequencedSocketData data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4230 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4231 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4232 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4233 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4234 | ssl.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4235 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4236 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4237 | TestCompletionCallback callback1; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4238 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4239 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4240 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4241 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4242 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4243 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4244 | |
| 4245 | rv = callback1.WaitForResult(); |
| 4246 | EXPECT_EQ(OK, rv); |
| 4247 | |
| 4248 | const HttpResponseInfo* const response = trans->GetResponseInfo(); |
| 4249 | |
| 4250 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4251 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4252 | EXPECT_EQ(407, response->headers->response_code()); |
| 4253 | EXPECT_TRUE(response->was_fetched_via_spdy); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4254 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4255 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4256 | TestCompletionCallback callback2; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4257 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4258 | rv = trans->RestartWithAuth( |
| 4259 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4260 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4261 | |
| 4262 | rv = callback2.WaitForResult(); |
| 4263 | EXPECT_EQ(OK, rv); |
| 4264 | |
| 4265 | const HttpResponseInfo* const response_restart = trans->GetResponseInfo(); |
| 4266 | |
| 4267 | ASSERT_TRUE(response_restart != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4268 | ASSERT_TRUE(response_restart->headers.get() != NULL); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4269 | EXPECT_EQ(200, response_restart->headers->response_code()); |
| 4270 | // The password prompt info should not be set. |
| 4271 | EXPECT_TRUE(response_restart->auth_challenge.get() == NULL); |
| 4272 | } |
| 4273 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4274 | // 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] | 4275 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyConnectHttps) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4276 | HttpRequestInfo request; |
| 4277 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4278 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4279 | request.load_flags = 0; |
| 4280 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4281 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4282 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4283 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4284 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4285 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4286 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4287 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4288 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4289 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4290 | // CONNECT to www.example.org:443 via SPDY |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 4291 | scoped_ptr<SpdyFrame> connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4292 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 4293 | // fetch https://www.example.org/ via HTTP |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4294 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4295 | const char get[] = |
| 4296 | "GET / HTTP/1.1\r\n" |
| 4297 | "Host: www.example.org\r\n" |
| 4298 | "Connection: keep-alive\r\n\r\n"; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4299 | scoped_ptr<SpdyFrame> wrapped_get( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4300 | spdy_util_.ConstructSpdyBodyFrame(1, get, strlen(get), false)); |
| 4301 | scoped_ptr<SpdyFrame> conn_resp( |
| 4302 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4303 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 4304 | "Content-Length: 10\r\n\r\n"; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4305 | scoped_ptr<SpdyFrame> wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4306 | spdy_util_.ConstructSpdyBodyFrame(1, resp, strlen(resp), false)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4307 | scoped_ptr<SpdyFrame> wrapped_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4308 | spdy_util_.ConstructSpdyBodyFrame(1, "1234567890", 10, false)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4309 | scoped_ptr<SpdyFrame> window_update( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 4310 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp->size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 4311 | |
| 4312 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4313 | CreateMockWrite(*connect, 0), |
| 4314 | CreateMockWrite(*wrapped_get, 2), |
| 4315 | CreateMockWrite(*window_update, 6), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 4316 | }; |
| 4317 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4318 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4319 | CreateMockRead(*conn_resp, 1, ASYNC), |
| 4320 | CreateMockRead(*wrapped_get_resp, 3, ASYNC), |
| 4321 | CreateMockRead(*wrapped_body, 4, ASYNC), |
| 4322 | CreateMockRead(*wrapped_body, 5, ASYNC), |
| 4323 | MockRead(ASYNC, 0, 7), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4324 | }; |
| 4325 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4326 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4327 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4328 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4329 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4330 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4331 | ssl.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4332 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4333 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4334 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4335 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4336 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4337 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4338 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4339 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4340 | |
| 4341 | rv = callback1.WaitForResult(); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4342 | ASSERT_EQ(OK, rv); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4343 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4344 | LoadTimingInfo load_timing_info; |
| 4345 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4346 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4347 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4348 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4349 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4350 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4351 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4352 | |
| 4353 | std::string response_data; |
| 4354 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 4355 | EXPECT_EQ("1234567890", response_data); |
| 4356 | } |
| 4357 | |
| 4358 | // Test a SPDY CONNECT through an HTTPS Proxy to a SPDY server. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4359 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyConnectSpdy) { |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4360 | SpdyTestUtil spdy_util_wrapped(GetProtocol(), GetDependenciesFromPriority()); |
| 4361 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4362 | HttpRequestInfo request; |
| 4363 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4364 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4365 | request.load_flags = 0; |
| 4366 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4367 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4368 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4369 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4370 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4371 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4372 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4373 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4374 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4375 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4376 | // CONNECT to www.example.org:443 via SPDY |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 4377 | scoped_ptr<SpdyFrame> connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4378 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 4379 | // fetch https://www.example.org/ via SPDY |
| 4380 | const char kMyUrl[] = "https://www.example.org/"; |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4381 | scoped_ptr<SpdyFrame> get( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4382 | spdy_util_wrapped.ConstructSpdyGet(kMyUrl, false, 1, LOWEST)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4383 | scoped_ptr<SpdyFrame> wrapped_get( |
| 4384 | spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
| 4385 | scoped_ptr<SpdyFrame> conn_resp( |
| 4386 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 4387 | scoped_ptr<SpdyFrame> get_resp( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4388 | spdy_util_wrapped.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4389 | scoped_ptr<SpdyFrame> wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4390 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4391 | scoped_ptr<SpdyFrame> body(spdy_util_wrapped.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4392 | scoped_ptr<SpdyFrame> wrapped_body( |
| 4393 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4394 | scoped_ptr<SpdyFrame> window_update_get_resp( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 4395 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp->size())); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4396 | scoped_ptr<SpdyFrame> window_update_body( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 4397 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body->size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 4398 | |
| 4399 | MockWrite spdy_writes[] = { |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4400 | CreateMockWrite(*connect, 0), |
| 4401 | CreateMockWrite(*wrapped_get, 2), |
| 4402 | CreateMockWrite(*window_update_get_resp, 6), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 4403 | CreateMockWrite(*window_update_body, 7), |
| 4404 | }; |
| 4405 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4406 | MockRead spdy_reads[] = { |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4407 | CreateMockRead(*conn_resp, 1, ASYNC), |
| 4408 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4409 | CreateMockRead(*wrapped_get_resp, 4, ASYNC), |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4410 | CreateMockRead(*wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4411 | MockRead(ASYNC, 0, 8), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4412 | }; |
| 4413 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4414 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4415 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4416 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4417 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4418 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4419 | ssl.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4420 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4421 | SSLSocketDataProvider ssl2(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4422 | ssl2.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4423 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4424 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4425 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4426 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4427 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4428 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4429 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4430 | // Allow the SpdyProxyClientSocket's write callback to complete. |
| 4431 | base::MessageLoop::current()->RunUntilIdle(); |
| 4432 | // Now allow the read of the response to complete. |
| 4433 | spdy_data.CompleteRead(); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4434 | rv = callback1.WaitForResult(); |
| 4435 | EXPECT_EQ(OK, rv); |
| 4436 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4437 | LoadTimingInfo load_timing_info; |
| 4438 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4439 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4440 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4441 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4442 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4443 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame^] | 4444 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4445 | |
| 4446 | std::string response_data; |
| 4447 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 4448 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4449 | } |
| 4450 | |
| 4451 | // Test a SPDY CONNECT failure through an HTTPS Proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4452 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyConnectFailure) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4453 | HttpRequestInfo request; |
| 4454 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4455 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4456 | request.load_flags = 0; |
| 4457 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4458 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4459 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4460 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4461 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4462 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4463 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4464 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4465 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4466 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4467 | // CONNECT to www.example.org:443 via SPDY |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 4468 | scoped_ptr<SpdyFrame> connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4469 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 4470 | scoped_ptr<SpdyFrame> get( |
| 4471 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4472 | |
| 4473 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4474 | CreateMockWrite(*connect, 0), CreateMockWrite(*get, 2), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4475 | }; |
| 4476 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4477 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdySynReplyError(1)); |
| 4478 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4479 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4480 | CreateMockRead(*resp, 1, ASYNC), MockRead(ASYNC, 0, 3), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4481 | }; |
| 4482 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4483 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4484 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4485 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4486 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4487 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4488 | ssl.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4489 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4490 | SSLSocketDataProvider ssl2(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4491 | ssl2.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4492 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4493 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4494 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4495 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4496 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4497 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4498 | |
| 4499 | rv = callback1.WaitForResult(); |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 4500 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4501 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 4502 | // TODO(ttuttle): Anything else to check here? |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4503 | } |
| 4504 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4505 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 4506 | // HTTPS Proxy to different servers. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4507 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4508 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsTwoServers) { |
| 4509 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4510 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4511 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4512 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4513 | scoped_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4514 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4515 | |
| 4516 | HttpRequestInfo request1; |
| 4517 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4518 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4519 | request1.load_flags = 0; |
| 4520 | |
| 4521 | HttpRequestInfo request2; |
| 4522 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4523 | request2.url = GURL("https://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4524 | request2.load_flags = 0; |
| 4525 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4526 | // CONNECT to www.example.org:443 via SPDY. |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 4527 | scoped_ptr<SpdyFrame> connect1(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4528 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4529 | scoped_ptr<SpdyFrame> conn_resp1( |
| 4530 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4531 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4532 | // Fetch https://www.example.org/ via HTTP. |
| 4533 | const char get1[] = |
| 4534 | "GET / HTTP/1.1\r\n" |
| 4535 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4536 | "Connection: keep-alive\r\n\r\n"; |
| 4537 | scoped_ptr<SpdyFrame> wrapped_get1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4538 | spdy_util_.ConstructSpdyBodyFrame(1, get1, strlen(get1), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4539 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 4540 | "Content-Length: 1\r\n\r\n"; |
| 4541 | scoped_ptr<SpdyFrame> wrapped_get_resp1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4542 | spdy_util_.ConstructSpdyBodyFrame(1, resp1, strlen(resp1), false)); |
| 4543 | scoped_ptr<SpdyFrame> wrapped_body1( |
| 4544 | spdy_util_.ConstructSpdyBodyFrame(1, "1", 1, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4545 | scoped_ptr<SpdyFrame> window_update( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 4546 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1->size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4547 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4548 | // CONNECT to mail.example.org:443 via SPDY. |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 4549 | SpdyHeaderBlock connect2_block; |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 4550 | spdy_util_.MaybeAddVersionHeader(&connect2_block); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 4551 | connect2_block[spdy_util_.GetMethodKey()] = "CONNECT"; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4552 | if (GetProtocol() == kProtoHTTP2) { |
bnc | 6b996d53 | 2015-07-29 10:51:32 | [diff] [blame] | 4553 | connect2_block[spdy_util_.GetHostKey()] = "mail.example.org:443"; |
| 4554 | } else { |
bnc | 6b996d53 | 2015-07-29 10:51:32 | [diff] [blame] | 4555 | connect2_block[spdy_util_.GetHostKey()] = "mail.example.org"; |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 4556 | connect2_block[spdy_util_.GetPathKey()] = "mail.example.org:443"; |
bnc | 6b996d53 | 2015-07-29 10:51:32 | [diff] [blame] | 4557 | } |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4558 | scoped_ptr<SpdyFrame> connect2( |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 4559 | spdy_util_.ConstructSpdySyn(3, connect2_block, LOWEST, false, false)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 4560 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4561 | scoped_ptr<SpdyFrame> conn_resp2( |
| 4562 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4563 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4564 | // Fetch https://mail.example.org/ via HTTP. |
| 4565 | const char get2[] = |
| 4566 | "GET / HTTP/1.1\r\n" |
| 4567 | "Host: mail.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4568 | "Connection: keep-alive\r\n\r\n"; |
| 4569 | scoped_ptr<SpdyFrame> wrapped_get2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4570 | spdy_util_.ConstructSpdyBodyFrame(3, get2, strlen(get2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4571 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 4572 | "Content-Length: 2\r\n\r\n"; |
| 4573 | scoped_ptr<SpdyFrame> wrapped_get_resp2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4574 | spdy_util_.ConstructSpdyBodyFrame(3, resp2, strlen(resp2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4575 | scoped_ptr<SpdyFrame> wrapped_body2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4576 | spdy_util_.ConstructSpdyBodyFrame(3, "22", 2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4577 | |
| 4578 | MockWrite spdy_writes[] = { |
| 4579 | CreateMockWrite(*connect1, 0), |
| 4580 | CreateMockWrite(*wrapped_get1, 2), |
| 4581 | CreateMockWrite(*connect2, 5), |
| 4582 | CreateMockWrite(*wrapped_get2, 7), |
| 4583 | }; |
| 4584 | |
| 4585 | MockRead spdy_reads[] = { |
| 4586 | CreateMockRead(*conn_resp1, 1, ASYNC), |
| 4587 | CreateMockRead(*wrapped_get_resp1, 3, ASYNC), |
| 4588 | CreateMockRead(*wrapped_body1, 4, ASYNC), |
| 4589 | CreateMockRead(*conn_resp2, 6, ASYNC), |
| 4590 | CreateMockRead(*wrapped_get_resp2, 8, ASYNC), |
| 4591 | CreateMockRead(*wrapped_body2, 9, ASYNC), |
| 4592 | MockRead(ASYNC, 0, 10), |
| 4593 | }; |
| 4594 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4595 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4596 | arraysize(spdy_writes)); |
| 4597 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4598 | |
| 4599 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4600 | ssl.SetNextProto(GetProtocol()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4601 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4602 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4603 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4604 | SSLSocketDataProvider ssl3(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4605 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4606 | |
| 4607 | TestCompletionCallback callback; |
| 4608 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4609 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4610 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4611 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4612 | EXPECT_EQ(OK, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4613 | |
| 4614 | LoadTimingInfo load_timing_info; |
| 4615 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4616 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4617 | |
| 4618 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4619 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4620 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4621 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4622 | |
| 4623 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 4624 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4625 | rv = trans->Read(buf.get(), 256, callback.callback()); |
| 4626 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4627 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4628 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4629 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4630 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4631 | EXPECT_EQ(OK, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4632 | |
| 4633 | LoadTimingInfo load_timing_info2; |
| 4634 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4635 | // Even though the SPDY connection is reused, a new tunnelled connection has |
| 4636 | // to be created, so the socket's load timing looks like a fresh connection. |
| 4637 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4638 | |
| 4639 | // The requests should have different IDs, since they each are using their own |
| 4640 | // separate stream. |
| 4641 | EXPECT_NE(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 4642 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4643 | rv = trans2->Read(buf.get(), 256, callback.callback()); |
| 4644 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4645 | } |
| 4646 | |
| 4647 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 4648 | // HTTPS Proxy to the same server. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4649 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4650 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsSameServer) { |
| 4651 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4652 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4653 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4654 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4655 | scoped_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4656 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4657 | |
| 4658 | HttpRequestInfo request1; |
| 4659 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4660 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4661 | request1.load_flags = 0; |
| 4662 | |
| 4663 | HttpRequestInfo request2; |
| 4664 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4665 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4666 | request2.load_flags = 0; |
| 4667 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4668 | // CONNECT to www.example.org:443 via SPDY. |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 4669 | scoped_ptr<SpdyFrame> connect1(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4670 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4671 | scoped_ptr<SpdyFrame> conn_resp1( |
| 4672 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4673 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4674 | // Fetch https://www.example.org/ via HTTP. |
| 4675 | const char get1[] = |
| 4676 | "GET / HTTP/1.1\r\n" |
| 4677 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4678 | "Connection: keep-alive\r\n\r\n"; |
| 4679 | scoped_ptr<SpdyFrame> wrapped_get1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4680 | spdy_util_.ConstructSpdyBodyFrame(1, get1, strlen(get1), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4681 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 4682 | "Content-Length: 1\r\n\r\n"; |
| 4683 | scoped_ptr<SpdyFrame> wrapped_get_resp1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4684 | spdy_util_.ConstructSpdyBodyFrame(1, resp1, strlen(resp1), false)); |
| 4685 | scoped_ptr<SpdyFrame> wrapped_body1( |
| 4686 | spdy_util_.ConstructSpdyBodyFrame(1, "1", 1, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4687 | scoped_ptr<SpdyFrame> window_update( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 4688 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1->size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4689 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4690 | // Fetch https://www.example.org/2 via HTTP. |
| 4691 | const char get2[] = |
| 4692 | "GET /2 HTTP/1.1\r\n" |
| 4693 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4694 | "Connection: keep-alive\r\n\r\n"; |
| 4695 | scoped_ptr<SpdyFrame> wrapped_get2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4696 | spdy_util_.ConstructSpdyBodyFrame(1, get2, strlen(get2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4697 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 4698 | "Content-Length: 2\r\n\r\n"; |
| 4699 | scoped_ptr<SpdyFrame> wrapped_get_resp2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4700 | spdy_util_.ConstructSpdyBodyFrame(1, resp2, strlen(resp2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4701 | scoped_ptr<SpdyFrame> wrapped_body2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4702 | spdy_util_.ConstructSpdyBodyFrame(1, "22", 2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4703 | |
| 4704 | MockWrite spdy_writes[] = { |
| 4705 | CreateMockWrite(*connect1, 0), |
| 4706 | CreateMockWrite(*wrapped_get1, 2), |
| 4707 | CreateMockWrite(*wrapped_get2, 5), |
| 4708 | }; |
| 4709 | |
| 4710 | MockRead spdy_reads[] = { |
| 4711 | CreateMockRead(*conn_resp1, 1, ASYNC), |
| 4712 | CreateMockRead(*wrapped_get_resp1, 3, ASYNC), |
| 4713 | CreateMockRead(*wrapped_body1, 4, ASYNC), |
| 4714 | CreateMockRead(*wrapped_get_resp2, 6, ASYNC), |
| 4715 | CreateMockRead(*wrapped_body2, 7, ASYNC), |
| 4716 | MockRead(ASYNC, 0, 8), |
| 4717 | }; |
| 4718 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4719 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4720 | arraysize(spdy_writes)); |
| 4721 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4722 | |
| 4723 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4724 | ssl.SetNextProto(GetProtocol()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4725 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4726 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4727 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4728 | |
| 4729 | TestCompletionCallback callback; |
| 4730 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4731 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4732 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4733 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
| 4734 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4735 | |
| 4736 | rv = callback.WaitForResult(); |
| 4737 | EXPECT_EQ(OK, rv); |
| 4738 | |
| 4739 | LoadTimingInfo load_timing_info; |
| 4740 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4741 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4742 | |
| 4743 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4744 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4745 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4746 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4747 | |
| 4748 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 4749 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4750 | EXPECT_EQ(1, trans->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4751 | trans.reset(); |
| 4752 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4753 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4754 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4755 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
| 4756 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4757 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4758 | rv = callback.WaitForResult(); |
| 4759 | EXPECT_EQ(OK, rv); |
| 4760 | |
| 4761 | LoadTimingInfo load_timing_info2; |
| 4762 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4763 | TestLoadTimingReused(load_timing_info2); |
| 4764 | |
| 4765 | // The requests should have the same ID. |
| 4766 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 4767 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4768 | EXPECT_EQ(2, trans2->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4769 | } |
| 4770 | |
| 4771 | // Test load timing in the case of of two HTTP requests through a SPDY HTTPS |
| 4772 | // Proxy to different servers. |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4773 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyLoadTimingTwoHttpRequests) { |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4774 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4775 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4776 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4777 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4778 | scoped_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4779 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4780 | |
| 4781 | HttpRequestInfo request1; |
| 4782 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4783 | request1.url = GURL("http://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4784 | request1.load_flags = 0; |
| 4785 | |
| 4786 | HttpRequestInfo request2; |
| 4787 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4788 | request2.url = GURL("http://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4789 | request2.load_flags = 0; |
| 4790 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4791 | // http://www.example.org/ |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4792 | scoped_ptr<SpdyHeaderBlock> headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4793 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 4794 | scoped_ptr<SpdyFrame> get1( |
| 4795 | spdy_util_.ConstructSpdySyn(1, *headers, LOWEST, false, true)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4796 | scoped_ptr<SpdyFrame> get_resp1( |
| 4797 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 4798 | scoped_ptr<SpdyFrame> body1( |
| 4799 | spdy_util_.ConstructSpdyBodyFrame(1, "1", 1, true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4800 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4801 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4802 | // http://mail.example.org/ |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4803 | scoped_ptr<SpdyHeaderBlock> headers2( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4804 | spdy_util_.ConstructGetHeaderBlockForProxy("http://mail.example.org/")); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 4805 | scoped_ptr<SpdyFrame> get2( |
| 4806 | spdy_util_.ConstructSpdySyn(3, *headers2, LOWEST, false, true)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4807 | scoped_ptr<SpdyFrame> get_resp2( |
| 4808 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 4809 | scoped_ptr<SpdyFrame> body2( |
| 4810 | spdy_util_.ConstructSpdyBodyFrame(3, "22", 2, true)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4811 | |
| 4812 | MockWrite spdy_writes[] = { |
| 4813 | CreateMockWrite(*get1, 0), |
| 4814 | CreateMockWrite(*get2, 3), |
| 4815 | }; |
| 4816 | |
| 4817 | MockRead spdy_reads[] = { |
| 4818 | CreateMockRead(*get_resp1, 1, ASYNC), |
| 4819 | CreateMockRead(*body1, 2, ASYNC), |
| 4820 | CreateMockRead(*get_resp2, 4, ASYNC), |
| 4821 | CreateMockRead(*body2, 5, ASYNC), |
| 4822 | MockRead(ASYNC, 0, 6), |
| 4823 | }; |
| 4824 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4825 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4826 | arraysize(spdy_writes)); |
| 4827 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4828 | |
| 4829 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4830 | ssl.SetNextProto(GetProtocol()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4831 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4832 | |
| 4833 | TestCompletionCallback callback; |
| 4834 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4835 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4836 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4837 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4838 | EXPECT_EQ(OK, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4839 | |
| 4840 | LoadTimingInfo load_timing_info; |
| 4841 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4842 | TestLoadTimingNotReused(load_timing_info, |
| 4843 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 4844 | |
| 4845 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4846 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4847 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame^] | 4848 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4849 | |
| 4850 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 4851 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4852 | rv = trans->Read(buf.get(), 256, callback.callback()); |
| 4853 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4854 | // Delete the first request, so the second one can reuse the socket. |
| 4855 | trans.reset(); |
| 4856 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4857 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4858 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4859 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4860 | EXPECT_EQ(OK, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4861 | |
| 4862 | LoadTimingInfo load_timing_info2; |
| 4863 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4864 | TestLoadTimingReused(load_timing_info2); |
| 4865 | |
| 4866 | // The requests should have the same ID. |
| 4867 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 4868 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4869 | rv = trans2->Read(buf.get(), 256, callback.callback()); |
| 4870 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4871 | } |
| 4872 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4873 | // Test the challenge-response-retry sequence through an HTTPS Proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4874 | TEST_P(HttpNetworkTransactionTest, HttpsProxyAuthRetry) { |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4875 | HttpRequestInfo request; |
| 4876 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4877 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4878 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 4879 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4880 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4881 | // Configure against https proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4882 | session_deps_.proxy_service = ProxyService::CreateFixed("https://myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4883 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4884 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4885 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4886 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4887 | // Since we have proxy, should use full url |
| 4888 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4889 | MockWrite( |
| 4890 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 4891 | "Host: www.example.org\r\n" |
| 4892 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4893 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4894 | // After calling trans->RestartWithAuth(), this is the request we should |
| 4895 | // be issuing -- the final header line contains the credentials. |
| 4896 | MockWrite( |
| 4897 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 4898 | "Host: www.example.org\r\n" |
| 4899 | "Proxy-Connection: keep-alive\r\n" |
| 4900 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4901 | }; |
| 4902 | |
| 4903 | // The proxy responds to the GET with a 407, using a persistent |
| 4904 | // connection. |
| 4905 | MockRead data_reads1[] = { |
| 4906 | // No credentials. |
| 4907 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4908 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4909 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 4910 | MockRead("Content-Length: 0\r\n\r\n"), |
| 4911 | |
| 4912 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4913 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4914 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4915 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4916 | }; |
| 4917 | |
| 4918 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4919 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4920 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4921 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4922 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4923 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4924 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4925 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4926 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4927 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4928 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4929 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4930 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4931 | |
| 4932 | rv = callback1.WaitForResult(); |
| 4933 | EXPECT_EQ(OK, rv); |
| 4934 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4935 | LoadTimingInfo load_timing_info; |
| 4936 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4937 | TestLoadTimingNotReused(load_timing_info, |
| 4938 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 4939 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4940 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4941 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4942 | ASSERT_FALSE(response->headers.get() == NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4943 | EXPECT_EQ(407, response->headers->response_code()); |
| 4944 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4945 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4946 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4947 | TestCompletionCallback callback2; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4948 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4949 | rv = trans->RestartWithAuth( |
| 4950 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4951 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4952 | |
| 4953 | rv = callback2.WaitForResult(); |
| 4954 | EXPECT_EQ(OK, rv); |
| 4955 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4956 | load_timing_info = LoadTimingInfo(); |
| 4957 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4958 | // Retrying with HTTP AUTH is considered to be reusing a socket. |
| 4959 | TestLoadTimingReused(load_timing_info); |
| 4960 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4961 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4962 | ASSERT_TRUE(response != NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4963 | |
| 4964 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4965 | EXPECT_EQ(200, response->headers->response_code()); |
| 4966 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 4967 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4968 | |
| 4969 | // The password prompt info should not be set. |
| 4970 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 4971 | } |
| 4972 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4973 | void HttpNetworkTransactionTest::ConnectStatusHelperWithExpectedStatus( |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4974 | const MockRead& status, int expected_status) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4975 | HttpRequestInfo request; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4976 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4977 | request.url = GURL("https://www.example.org/"); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4978 | request.load_flags = 0; |
| 4979 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4980 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4981 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4982 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4983 | |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4984 | // Since we have proxy, should try to establish tunnel. |
| 4985 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4986 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4987 | "Host: www.example.org:443\r\n" |
| 4988 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4989 | }; |
| 4990 | |
| 4991 | MockRead data_reads[] = { |
| 4992 | status, |
| 4993 | MockRead("Content-Length: 10\r\n\r\n"), |
| 4994 | // No response body because the test stops reading here. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4995 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4996 | }; |
| 4997 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 4998 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 4999 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5000 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5001 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5002 | TestCompletionCallback callback; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5003 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5004 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5005 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5006 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5007 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5008 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5009 | |
| 5010 | rv = callback.WaitForResult(); |
| 5011 | EXPECT_EQ(expected_status, rv); |
| 5012 | } |
| 5013 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5014 | void HttpNetworkTransactionTest::ConnectStatusHelper( |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5015 | const MockRead& status) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5016 | ConnectStatusHelperWithExpectedStatus( |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5017 | status, ERR_TUNNEL_CONNECTION_FAILED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5018 | } |
| 5019 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5020 | TEST_P(HttpNetworkTransactionTest, ConnectStatus100) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5021 | ConnectStatusHelper(MockRead("HTTP/1.1 100 Continue\r\n")); |
| 5022 | } |
| 5023 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5024 | TEST_P(HttpNetworkTransactionTest, ConnectStatus101) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5025 | ConnectStatusHelper(MockRead("HTTP/1.1 101 Switching Protocols\r\n")); |
| 5026 | } |
| 5027 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5028 | TEST_P(HttpNetworkTransactionTest, ConnectStatus201) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5029 | ConnectStatusHelper(MockRead("HTTP/1.1 201 Created\r\n")); |
| 5030 | } |
| 5031 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5032 | TEST_P(HttpNetworkTransactionTest, ConnectStatus202) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5033 | ConnectStatusHelper(MockRead("HTTP/1.1 202 Accepted\r\n")); |
| 5034 | } |
| 5035 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5036 | TEST_P(HttpNetworkTransactionTest, ConnectStatus203) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5037 | ConnectStatusHelper( |
| 5038 | MockRead("HTTP/1.1 203 Non-Authoritative Information\r\n")); |
| 5039 | } |
| 5040 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5041 | TEST_P(HttpNetworkTransactionTest, ConnectStatus204) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5042 | ConnectStatusHelper(MockRead("HTTP/1.1 204 No Content\r\n")); |
| 5043 | } |
| 5044 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5045 | TEST_P(HttpNetworkTransactionTest, ConnectStatus205) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5046 | ConnectStatusHelper(MockRead("HTTP/1.1 205 Reset Content\r\n")); |
| 5047 | } |
| 5048 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5049 | TEST_P(HttpNetworkTransactionTest, ConnectStatus206) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5050 | ConnectStatusHelper(MockRead("HTTP/1.1 206 Partial Content\r\n")); |
| 5051 | } |
| 5052 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5053 | TEST_P(HttpNetworkTransactionTest, ConnectStatus300) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5054 | ConnectStatusHelper(MockRead("HTTP/1.1 300 Multiple Choices\r\n")); |
| 5055 | } |
| 5056 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5057 | TEST_P(HttpNetworkTransactionTest, ConnectStatus301) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5058 | ConnectStatusHelper(MockRead("HTTP/1.1 301 Moved Permanently\r\n")); |
| 5059 | } |
| 5060 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5061 | TEST_P(HttpNetworkTransactionTest, ConnectStatus302) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5062 | ConnectStatusHelper(MockRead("HTTP/1.1 302 Found\r\n")); |
| 5063 | } |
| 5064 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5065 | TEST_P(HttpNetworkTransactionTest, ConnectStatus303) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5066 | ConnectStatusHelper(MockRead("HTTP/1.1 303 See Other\r\n")); |
| 5067 | } |
| 5068 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5069 | TEST_P(HttpNetworkTransactionTest, ConnectStatus304) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5070 | ConnectStatusHelper(MockRead("HTTP/1.1 304 Not Modified\r\n")); |
| 5071 | } |
| 5072 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5073 | TEST_P(HttpNetworkTransactionTest, ConnectStatus305) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5074 | ConnectStatusHelper(MockRead("HTTP/1.1 305 Use Proxy\r\n")); |
| 5075 | } |
| 5076 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5077 | TEST_P(HttpNetworkTransactionTest, ConnectStatus306) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5078 | ConnectStatusHelper(MockRead("HTTP/1.1 306\r\n")); |
| 5079 | } |
| 5080 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5081 | TEST_P(HttpNetworkTransactionTest, ConnectStatus307) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5082 | ConnectStatusHelper(MockRead("HTTP/1.1 307 Temporary Redirect\r\n")); |
| 5083 | } |
| 5084 | |
[email protected] | 0a17aab3 | 2014-04-24 03:32:37 | [diff] [blame] | 5085 | TEST_P(HttpNetworkTransactionTest, ConnectStatus308) { |
| 5086 | ConnectStatusHelper(MockRead("HTTP/1.1 308 Permanent Redirect\r\n")); |
| 5087 | } |
| 5088 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5089 | TEST_P(HttpNetworkTransactionTest, ConnectStatus400) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5090 | ConnectStatusHelper(MockRead("HTTP/1.1 400 Bad Request\r\n")); |
| 5091 | } |
| 5092 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5093 | TEST_P(HttpNetworkTransactionTest, ConnectStatus401) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5094 | ConnectStatusHelper(MockRead("HTTP/1.1 401 Unauthorized\r\n")); |
| 5095 | } |
| 5096 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5097 | TEST_P(HttpNetworkTransactionTest, ConnectStatus402) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5098 | ConnectStatusHelper(MockRead("HTTP/1.1 402 Payment Required\r\n")); |
| 5099 | } |
| 5100 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5101 | TEST_P(HttpNetworkTransactionTest, ConnectStatus403) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5102 | ConnectStatusHelper(MockRead("HTTP/1.1 403 Forbidden\r\n")); |
| 5103 | } |
| 5104 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5105 | TEST_P(HttpNetworkTransactionTest, ConnectStatus404) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5106 | ConnectStatusHelper(MockRead("HTTP/1.1 404 Not Found\r\n")); |
| 5107 | } |
| 5108 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5109 | TEST_P(HttpNetworkTransactionTest, ConnectStatus405) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5110 | ConnectStatusHelper(MockRead("HTTP/1.1 405 Method Not Allowed\r\n")); |
| 5111 | } |
| 5112 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5113 | TEST_P(HttpNetworkTransactionTest, ConnectStatus406) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5114 | ConnectStatusHelper(MockRead("HTTP/1.1 406 Not Acceptable\r\n")); |
| 5115 | } |
| 5116 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5117 | TEST_P(HttpNetworkTransactionTest, ConnectStatus407) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5118 | ConnectStatusHelperWithExpectedStatus( |
| 5119 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
[email protected] | a7ea883 | 2010-07-12 17:54:54 | [diff] [blame] | 5120 | ERR_PROXY_AUTH_UNSUPPORTED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5121 | } |
| 5122 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5123 | TEST_P(HttpNetworkTransactionTest, ConnectStatus408) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5124 | ConnectStatusHelper(MockRead("HTTP/1.1 408 Request Timeout\r\n")); |
| 5125 | } |
| 5126 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5127 | TEST_P(HttpNetworkTransactionTest, ConnectStatus409) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5128 | ConnectStatusHelper(MockRead("HTTP/1.1 409 Conflict\r\n")); |
| 5129 | } |
| 5130 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5131 | TEST_P(HttpNetworkTransactionTest, ConnectStatus410) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5132 | ConnectStatusHelper(MockRead("HTTP/1.1 410 Gone\r\n")); |
| 5133 | } |
| 5134 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5135 | TEST_P(HttpNetworkTransactionTest, ConnectStatus411) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5136 | ConnectStatusHelper(MockRead("HTTP/1.1 411 Length Required\r\n")); |
| 5137 | } |
| 5138 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5139 | TEST_P(HttpNetworkTransactionTest, ConnectStatus412) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5140 | ConnectStatusHelper(MockRead("HTTP/1.1 412 Precondition Failed\r\n")); |
| 5141 | } |
| 5142 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5143 | TEST_P(HttpNetworkTransactionTest, ConnectStatus413) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5144 | ConnectStatusHelper(MockRead("HTTP/1.1 413 Request Entity Too Large\r\n")); |
| 5145 | } |
| 5146 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5147 | TEST_P(HttpNetworkTransactionTest, ConnectStatus414) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5148 | ConnectStatusHelper(MockRead("HTTP/1.1 414 Request-URI Too Long\r\n")); |
| 5149 | } |
| 5150 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5151 | TEST_P(HttpNetworkTransactionTest, ConnectStatus415) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5152 | ConnectStatusHelper(MockRead("HTTP/1.1 415 Unsupported Media Type\r\n")); |
| 5153 | } |
| 5154 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5155 | TEST_P(HttpNetworkTransactionTest, ConnectStatus416) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5156 | ConnectStatusHelper( |
| 5157 | MockRead("HTTP/1.1 416 Requested Range Not Satisfiable\r\n")); |
| 5158 | } |
| 5159 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5160 | TEST_P(HttpNetworkTransactionTest, ConnectStatus417) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5161 | ConnectStatusHelper(MockRead("HTTP/1.1 417 Expectation Failed\r\n")); |
| 5162 | } |
| 5163 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5164 | TEST_P(HttpNetworkTransactionTest, ConnectStatus500) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5165 | ConnectStatusHelper(MockRead("HTTP/1.1 500 Internal Server Error\r\n")); |
| 5166 | } |
| 5167 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5168 | TEST_P(HttpNetworkTransactionTest, ConnectStatus501) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5169 | ConnectStatusHelper(MockRead("HTTP/1.1 501 Not Implemented\r\n")); |
| 5170 | } |
| 5171 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5172 | TEST_P(HttpNetworkTransactionTest, ConnectStatus502) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5173 | ConnectStatusHelper(MockRead("HTTP/1.1 502 Bad Gateway\r\n")); |
| 5174 | } |
| 5175 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5176 | TEST_P(HttpNetworkTransactionTest, ConnectStatus503) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5177 | ConnectStatusHelper(MockRead("HTTP/1.1 503 Service Unavailable\r\n")); |
| 5178 | } |
| 5179 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5180 | TEST_P(HttpNetworkTransactionTest, ConnectStatus504) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5181 | ConnectStatusHelper(MockRead("HTTP/1.1 504 Gateway Timeout\r\n")); |
| 5182 | } |
| 5183 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5184 | TEST_P(HttpNetworkTransactionTest, ConnectStatus505) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5185 | ConnectStatusHelper(MockRead("HTTP/1.1 505 HTTP Version Not Supported\r\n")); |
| 5186 | } |
| 5187 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5188 | // Test the flow when both the proxy server AND origin server require |
| 5189 | // authentication. Again, this uses basic auth for both since that is |
| 5190 | // the simplest to mock. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5191 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyThenServer) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5192 | HttpRequestInfo request; |
| 5193 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5194 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5195 | request.load_flags = 0; |
| 5196 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5197 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5198 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 5199 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 5200 | |
| 5201 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 5202 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5203 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5204 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5205 | MockWrite( |
| 5206 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5207 | "Host: www.example.org\r\n" |
| 5208 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5209 | }; |
| 5210 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5211 | MockRead data_reads1[] = { |
| 5212 | MockRead("HTTP/1.0 407 Unauthorized\r\n"), |
| 5213 | // Give a couple authenticate options (only the middle one is actually |
| 5214 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 5215 | MockRead("Proxy-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5216 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5217 | MockRead("Proxy-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 5218 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5219 | // Large content-length -- won't matter, as connection will be reset. |
| 5220 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5221 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5222 | }; |
| 5223 | |
| 5224 | // After calling trans->RestartWithAuth() the first time, this is the |
| 5225 | // request we should be issuing -- the final header line contains the |
| 5226 | // proxy's credentials. |
| 5227 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5228 | MockWrite( |
| 5229 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5230 | "Host: www.example.org\r\n" |
| 5231 | "Proxy-Connection: keep-alive\r\n" |
| 5232 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5233 | }; |
| 5234 | |
| 5235 | // Now the proxy server lets the request pass through to origin server. |
| 5236 | // The origin server responds with a 401. |
| 5237 | MockRead data_reads2[] = { |
| 5238 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5239 | // Note: We are using the same realm-name as the proxy server. This is |
| 5240 | // completely valid, as realms are unique across hosts. |
| 5241 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5242 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5243 | MockRead("Content-Length: 2000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5244 | MockRead(SYNCHRONOUS, ERR_FAILED), // Won't be reached. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5245 | }; |
| 5246 | |
| 5247 | // After calling trans->RestartWithAuth() the second time, we should send |
| 5248 | // the credentials for both the proxy and origin server. |
| 5249 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5250 | MockWrite( |
| 5251 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5252 | "Host: www.example.org\r\n" |
| 5253 | "Proxy-Connection: keep-alive\r\n" |
| 5254 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n" |
| 5255 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5256 | }; |
| 5257 | |
| 5258 | // Lastly we get the desired content. |
| 5259 | MockRead data_reads3[] = { |
| 5260 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5261 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5262 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5263 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5264 | }; |
| 5265 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5266 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5267 | data_writes1, arraysize(data_writes1)); |
| 5268 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5269 | data_writes2, arraysize(data_writes2)); |
| 5270 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 5271 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5272 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5273 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 5274 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5275 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5276 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5277 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5278 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5279 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5280 | |
| 5281 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5282 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5283 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5284 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5285 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5286 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5287 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5288 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5289 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5290 | rv = trans->RestartWithAuth( |
| 5291 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5292 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5293 | |
| 5294 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5295 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5296 | |
| 5297 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5298 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5299 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5300 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5301 | TestCompletionCallback callback3; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5302 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5303 | rv = trans->RestartWithAuth( |
| 5304 | AuthCredentials(kFoo2, kBar2), callback3.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5305 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5306 | |
| 5307 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5308 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5309 | |
| 5310 | response = trans->GetResponseInfo(); |
| 5311 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5312 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5313 | } |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5314 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 5315 | // For the NTLM implementation using SSPI, we skip the NTLM tests since we |
| 5316 | // can't hook into its internals to cause it to generate predictable NTLM |
| 5317 | // authorization headers. |
| 5318 | #if defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5319 | // The NTLM authentication unit tests were generated by capturing the HTTP |
| 5320 | // requests and responses using Fiddler 2 and inspecting the generated random |
| 5321 | // bytes in the debugger. |
| 5322 | |
| 5323 | // Enter the correct password and authenticate successfully. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5324 | TEST_P(HttpNetworkTransactionTest, NTLMAuth1) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5325 | HttpRequestInfo request; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5326 | request.method = "GET"; |
| 5327 | request.url = GURL("http://172.22.68.17/kids/login.aspx"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 5328 | |
| 5329 | // Ensure load is not disrupted by flags which suppress behaviour specific |
| 5330 | // to other auth schemes. |
| 5331 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5332 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5333 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom1, |
| 5334 | MockGetHostName); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 5335 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5336 | |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5337 | MockWrite data_writes1[] = { |
| 5338 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5339 | "Host: 172.22.68.17\r\n" |
| 5340 | "Connection: keep-alive\r\n\r\n"), |
| 5341 | }; |
| 5342 | |
| 5343 | MockRead data_reads1[] = { |
| 5344 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 5345 | // Negotiate and NTLM are often requested together. However, we only want |
| 5346 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 5347 | // the header that requests Negotiate for this test. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5348 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 5349 | MockRead("Connection: close\r\n"), |
| 5350 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 5351 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5352 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5353 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5354 | }; |
| 5355 | |
| 5356 | MockWrite data_writes2[] = { |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5357 | // After restarting with a null identity, this is the |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5358 | // request we should be issuing -- the final header line contains a Type |
| 5359 | // 1 message. |
| 5360 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5361 | "Host: 172.22.68.17\r\n" |
| 5362 | "Connection: keep-alive\r\n" |
| 5363 | "Authorization: NTLM " |
| 5364 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
| 5365 | |
| 5366 | // After calling trans->RestartWithAuth(), we should send a Type 3 message |
| 5367 | // (the credentials for the origin server). The second request continues |
| 5368 | // on the same connection. |
| 5369 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5370 | "Host: 172.22.68.17\r\n" |
| 5371 | "Connection: keep-alive\r\n" |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5372 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 5373 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 5374 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwBVKW" |
| 5375 | "Yma5xzVAAAAAAAAAAAAAAAAAAAAACH+gWcm+YsP9Tqb9zCR3WAeZZX" |
| 5376 | "ahlhx5I=\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5377 | }; |
| 5378 | |
| 5379 | MockRead data_reads2[] = { |
| 5380 | // The origin server responds with a Type 2 message. |
| 5381 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 5382 | MockRead("WWW-Authenticate: NTLM " |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5383 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCjGpMpPGlYKkAAAAAAAAAALo" |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5384 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 5385 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 5386 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 5387 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 5388 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 5389 | "BtAAAAAAA=\r\n"), |
| 5390 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 5391 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5392 | MockRead("You are not authorized to view this page\r\n"), |
| 5393 | |
| 5394 | // Lastly we get the desired content. |
| 5395 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5396 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 5397 | MockRead("Content-Length: 13\r\n\r\n"), |
| 5398 | MockRead("Please Login\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5399 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5400 | }; |
| 5401 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5402 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5403 | data_writes1, arraysize(data_writes1)); |
| 5404 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5405 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5406 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5407 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5408 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5409 | TestCompletionCallback callback1; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5410 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5411 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5412 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5413 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5414 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5415 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5416 | |
| 5417 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5418 | EXPECT_EQ(OK, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5419 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5420 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5421 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5422 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5423 | ASSERT_FALSE(response == NULL); |
| 5424 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5425 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5426 | TestCompletionCallback callback2; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5427 | |
[email protected] | f3cf980 | 2011-10-28 18:44:58 | [diff] [blame] | 5428 | rv = trans->RestartWithAuth(AuthCredentials(kTestingNTLM, kTestingNTLM), |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5429 | callback2.callback()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5430 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5431 | |
| 5432 | rv = callback2.WaitForResult(); |
| 5433 | EXPECT_EQ(OK, rv); |
| 5434 | |
| 5435 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 5436 | |
| 5437 | response = trans->GetResponseInfo(); |
| 5438 | ASSERT_TRUE(response != NULL); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5439 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5440 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5441 | TestCompletionCallback callback3; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5442 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5443 | rv = trans->RestartWithAuth(AuthCredentials(), callback3.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5444 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5445 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5446 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5447 | EXPECT_EQ(OK, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5448 | |
| 5449 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5450 | ASSERT_TRUE(response != NULL); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5451 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5452 | EXPECT_EQ(13, response->headers->GetContentLength()); |
| 5453 | } |
| 5454 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5455 | // Enter a wrong password, and then the correct one. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5456 | TEST_P(HttpNetworkTransactionTest, NTLMAuth2) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5457 | HttpRequestInfo request; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5458 | request.method = "GET"; |
| 5459 | request.url = GURL("http://172.22.68.17/kids/login.aspx"); |
| 5460 | request.load_flags = 0; |
| 5461 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5462 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom2, |
| 5463 | MockGetHostName); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 5464 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5465 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5466 | MockWrite data_writes1[] = { |
| 5467 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5468 | "Host: 172.22.68.17\r\n" |
| 5469 | "Connection: keep-alive\r\n\r\n"), |
| 5470 | }; |
| 5471 | |
| 5472 | MockRead data_reads1[] = { |
| 5473 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 5474 | // Negotiate and NTLM are often requested together. However, we only want |
| 5475 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 5476 | // the header that requests Negotiate for this test. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5477 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 5478 | MockRead("Connection: close\r\n"), |
| 5479 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 5480 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5481 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5482 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5483 | }; |
| 5484 | |
| 5485 | MockWrite data_writes2[] = { |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5486 | // After restarting with a null identity, this is the |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5487 | // request we should be issuing -- the final header line contains a Type |
| 5488 | // 1 message. |
| 5489 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5490 | "Host: 172.22.68.17\r\n" |
| 5491 | "Connection: keep-alive\r\n" |
| 5492 | "Authorization: NTLM " |
| 5493 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
| 5494 | |
| 5495 | // After calling trans->RestartWithAuth(), we should send a Type 3 message |
| 5496 | // (the credentials for the origin server). The second request continues |
| 5497 | // on the same connection. |
| 5498 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5499 | "Host: 172.22.68.17\r\n" |
| 5500 | "Connection: keep-alive\r\n" |
| 5501 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 5502 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 5503 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwCWeY" |
| 5504 | "XnSZNwoQAAAAAAAAAAAAAAAAAAAADLa34/phTTKzNTWdub+uyFleOj" |
| 5505 | "4Ww7b7E=\r\n\r\n"), |
| 5506 | }; |
| 5507 | |
| 5508 | MockRead data_reads2[] = { |
| 5509 | // The origin server responds with a Type 2 message. |
| 5510 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 5511 | MockRead("WWW-Authenticate: NTLM " |
| 5512 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCbVWUZezVGpAAAAAAAAAAALo" |
| 5513 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 5514 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 5515 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 5516 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 5517 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 5518 | "BtAAAAAAA=\r\n"), |
| 5519 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 5520 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5521 | MockRead("You are not authorized to view this page\r\n"), |
| 5522 | |
| 5523 | // Wrong password. |
| 5524 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5525 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 5526 | MockRead("Connection: close\r\n"), |
| 5527 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 5528 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5529 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5530 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5531 | }; |
| 5532 | |
| 5533 | MockWrite data_writes3[] = { |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5534 | // After restarting with a null identity, this is the |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5535 | // request we should be issuing -- the final header line contains a Type |
| 5536 | // 1 message. |
| 5537 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5538 | "Host: 172.22.68.17\r\n" |
| 5539 | "Connection: keep-alive\r\n" |
| 5540 | "Authorization: NTLM " |
| 5541 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
| 5542 | |
| 5543 | // After calling trans->RestartWithAuth(), we should send a Type 3 message |
| 5544 | // (the credentials for the origin server). The second request continues |
| 5545 | // on the same connection. |
| 5546 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5547 | "Host: 172.22.68.17\r\n" |
| 5548 | "Connection: keep-alive\r\n" |
| 5549 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 5550 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 5551 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwBO54" |
| 5552 | "dFMVvTHwAAAAAAAAAAAAAAAAAAAACS7sT6Uzw7L0L//WUqlIaVWpbI" |
| 5553 | "+4MUm7c=\r\n\r\n"), |
| 5554 | }; |
| 5555 | |
| 5556 | MockRead data_reads3[] = { |
| 5557 | // The origin server responds with a Type 2 message. |
| 5558 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 5559 | MockRead("WWW-Authenticate: NTLM " |
| 5560 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCL24VN8dgOR8AAAAAAAAAALo" |
| 5561 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 5562 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 5563 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 5564 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 5565 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 5566 | "BtAAAAAAA=\r\n"), |
| 5567 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 5568 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5569 | MockRead("You are not authorized to view this page\r\n"), |
| 5570 | |
| 5571 | // Lastly we get the desired content. |
| 5572 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5573 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 5574 | MockRead("Content-Length: 13\r\n\r\n"), |
| 5575 | MockRead("Please Login\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5576 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5577 | }; |
| 5578 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5579 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5580 | data_writes1, arraysize(data_writes1)); |
| 5581 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5582 | data_writes2, arraysize(data_writes2)); |
| 5583 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 5584 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5585 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5586 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 5587 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5588 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5589 | TestCompletionCallback callback1; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5590 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5591 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5592 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5593 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5594 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5595 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5596 | |
| 5597 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5598 | EXPECT_EQ(OK, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5599 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5600 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5601 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5602 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5603 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5604 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5605 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5606 | TestCompletionCallback callback2; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5607 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5608 | // Enter the wrong password. |
[email protected] | f3cf980 | 2011-10-28 18:44:58 | [diff] [blame] | 5609 | rv = trans->RestartWithAuth(AuthCredentials(kTestingNTLM, kWrongPassword), |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5610 | callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5611 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5612 | |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5613 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5614 | EXPECT_EQ(OK, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5615 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5616 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5617 | TestCompletionCallback callback3; |
| 5618 | rv = trans->RestartWithAuth(AuthCredentials(), callback3.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5619 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5620 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5621 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5622 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5623 | |
| 5624 | response = trans->GetResponseInfo(); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5625 | ASSERT_FALSE(response == NULL); |
| 5626 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5627 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5628 | TestCompletionCallback callback4; |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5629 | |
| 5630 | // Now enter the right password. |
[email protected] | f3cf980 | 2011-10-28 18:44:58 | [diff] [blame] | 5631 | rv = trans->RestartWithAuth(AuthCredentials(kTestingNTLM, kTestingNTLM), |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5632 | callback4.callback()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5633 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5634 | |
| 5635 | rv = callback4.WaitForResult(); |
| 5636 | EXPECT_EQ(OK, rv); |
| 5637 | |
| 5638 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 5639 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5640 | TestCompletionCallback callback5; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5641 | |
| 5642 | // One more roundtrip |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5643 | rv = trans->RestartWithAuth(AuthCredentials(), callback5.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5644 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5645 | |
| 5646 | rv = callback5.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5647 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5648 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5649 | response = trans->GetResponseInfo(); |
| 5650 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5651 | EXPECT_EQ(13, response->headers->GetContentLength()); |
| 5652 | } |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 5653 | #endif // NTLM_PORTABLE |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5654 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5655 | // Test reading a server response which has only headers, and no body. |
| 5656 | // After some maximum number of bytes is consumed, the transaction should |
| 5657 | // fail with ERR_RESPONSE_HEADERS_TOO_BIG. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5658 | TEST_P(HttpNetworkTransactionTest, LargeHeadersNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5659 | HttpRequestInfo request; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5660 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5661 | request.url = GURL("http://www.example.org/"); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5662 | request.load_flags = 0; |
| 5663 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 5664 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5665 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 5666 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5667 | |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 5668 | // Respond with 300 kb of headers (we should fail after 256 kb). |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 5669 | std::string large_headers_string; |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 5670 | FillLargeHeadersString(&large_headers_string, 300 * 1024); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5671 | |
| 5672 | MockRead data_reads[] = { |
| 5673 | MockRead("HTTP/1.0 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5674 | MockRead(ASYNC, large_headers_string.data(), large_headers_string.size()), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5675 | MockRead("\r\nBODY"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5676 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5677 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5678 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5679 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5680 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5681 | TestCompletionCallback callback; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5682 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5683 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5684 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5685 | |
| 5686 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5687 | EXPECT_EQ(ERR_RESPONSE_HEADERS_TOO_BIG, rv); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5688 | } |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5689 | |
| 5690 | // Make sure that we don't try to reuse a TCPClientSocket when failing to |
| 5691 | // establish tunnel. |
| 5692 | // http://code.google.com/p/chromium/issues/detail?id=3772 |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5693 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5694 | DontRecycleTransportSocketForSSLTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5695 | HttpRequestInfo request; |
| 5696 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5697 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5698 | request.load_flags = 0; |
| 5699 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5700 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5701 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | db8f44c | 2008-12-13 04:52:01 | [diff] [blame] | 5702 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 5703 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5704 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5705 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5706 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5707 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5708 | // Since we have proxy, should try to establish tunnel. |
| 5709 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5710 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5711 | "Host: www.example.org:443\r\n" |
| 5712 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5713 | }; |
| 5714 | |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 5715 | // The proxy responds to the connect with a 404, using a persistent |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5716 | // connection. Usually a proxy would return 501 (not implemented), |
| 5717 | // or 200 (tunnel established). |
| 5718 | MockRead data_reads1[] = { |
| 5719 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 5720 | MockRead("Content-Length: 10\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5721 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5722 | }; |
| 5723 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5724 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5725 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5726 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5727 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5728 | TestCompletionCallback callback1; |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5729 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5730 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5731 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5732 | |
| 5733 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5734 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5735 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5736 | // Empty the current queue. This is necessary because idle sockets are |
| 5737 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5738 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5739 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5740 | // We now check to make sure the TCPClientSocket was not added back to |
| 5741 | // the pool. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5742 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5743 | trans.reset(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5744 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5745 | // Make sure that the socket didn't get recycled after calling the destructor. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5746 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5747 | } |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5748 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5749 | // 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] | 5750 | TEST_P(HttpNetworkTransactionTest, RecycleSocket) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5751 | HttpRequestInfo request; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5752 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5753 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5754 | request.load_flags = 0; |
| 5755 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 5756 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5757 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5758 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5759 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5760 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5761 | MockRead data_reads[] = { |
| 5762 | // A part of the response body is received with the response headers. |
| 5763 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 5764 | // The rest of the response body is received in two parts. |
| 5765 | MockRead("lo"), |
| 5766 | MockRead(" world"), |
| 5767 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5768 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5769 | }; |
| 5770 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5771 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5772 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5773 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5774 | TestCompletionCallback callback; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5775 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5776 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5777 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5778 | |
| 5779 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5780 | EXPECT_EQ(OK, rv); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5781 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5782 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5783 | ASSERT_TRUE(response != NULL); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5784 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5785 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5786 | std::string status_line = response->headers->GetStatusLine(); |
| 5787 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 5788 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5789 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5790 | |
| 5791 | std::string response_data; |
| 5792 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5793 | EXPECT_EQ(OK, rv); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5794 | EXPECT_EQ("hello world", response_data); |
| 5795 | |
| 5796 | // Empty the current queue. This is necessary because idle sockets are |
| 5797 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5798 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5799 | |
| 5800 | // 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] | 5801 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5802 | } |
| 5803 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5804 | // Make sure that we recycle a SSL socket after reading all of the response |
| 5805 | // body. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5806 | TEST_P(HttpNetworkTransactionTest, RecycleSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5807 | HttpRequestInfo request; |
| 5808 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5809 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5810 | request.load_flags = 0; |
| 5811 | |
| 5812 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5813 | MockWrite( |
| 5814 | "GET / HTTP/1.1\r\n" |
| 5815 | "Host: www.example.org\r\n" |
| 5816 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5817 | }; |
| 5818 | |
| 5819 | MockRead data_reads[] = { |
| 5820 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5821 | MockRead("Content-Length: 11\r\n\r\n"), |
| 5822 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5823 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5824 | }; |
| 5825 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5826 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5827 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5828 | |
| 5829 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 5830 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5831 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5832 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5833 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5834 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 5835 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5836 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5837 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5838 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5839 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5840 | |
| 5841 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5842 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 5843 | |
| 5844 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5845 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5846 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5847 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5848 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5849 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5850 | |
| 5851 | std::string response_data; |
| 5852 | rv = ReadTransaction(trans.get(), &response_data); |
| 5853 | EXPECT_EQ(OK, rv); |
| 5854 | EXPECT_EQ("hello world", response_data); |
| 5855 | |
| 5856 | // Empty the current queue. This is necessary because idle sockets are |
| 5857 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5858 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5859 | |
| 5860 | // 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] | 5861 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5862 | } |
| 5863 | |
| 5864 | // Grab a SSL socket, use it, and put it back into the pool. Then, reuse it |
| 5865 | // from the pool and make sure that we recover okay. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5866 | TEST_P(HttpNetworkTransactionTest, RecycleDeadSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5867 | HttpRequestInfo request; |
| 5868 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5869 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5870 | request.load_flags = 0; |
| 5871 | |
| 5872 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5873 | MockWrite( |
| 5874 | "GET / HTTP/1.1\r\n" |
| 5875 | "Host: www.example.org\r\n" |
| 5876 | "Connection: keep-alive\r\n\r\n"), |
| 5877 | MockWrite( |
| 5878 | "GET / HTTP/1.1\r\n" |
| 5879 | "Host: www.example.org\r\n" |
| 5880 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5881 | }; |
| 5882 | |
| 5883 | MockRead data_reads[] = { |
| 5884 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5885 | MockRead("Content-Length: 11\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5886 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5887 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5888 | MockRead(ASYNC, 0, 0) // EOF |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5889 | }; |
| 5890 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5891 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 5892 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5893 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 5894 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5895 | |
| 5896 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 5897 | data_writes, arraysize(data_writes)); |
| 5898 | StaticSocketDataProvider data2(data_reads, arraysize(data_reads), |
| 5899 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5900 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 5901 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5902 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5903 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5904 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 5905 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5906 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5907 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5908 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5909 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5910 | |
| 5911 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5912 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 5913 | |
| 5914 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5915 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5916 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5917 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5918 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5919 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5920 | |
| 5921 | std::string response_data; |
| 5922 | rv = ReadTransaction(trans.get(), &response_data); |
| 5923 | EXPECT_EQ(OK, rv); |
| 5924 | EXPECT_EQ("hello world", response_data); |
| 5925 | |
| 5926 | // Empty the current queue. This is necessary because idle sockets are |
| 5927 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5928 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5929 | |
| 5930 | // 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] | 5931 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5932 | |
| 5933 | // Now start the second transaction, which should reuse the previous socket. |
| 5934 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5935 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5936 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5937 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5938 | |
| 5939 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5940 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 5941 | |
| 5942 | response = trans->GetResponseInfo(); |
| 5943 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5944 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5945 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5946 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5947 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5948 | |
| 5949 | rv = ReadTransaction(trans.get(), &response_data); |
| 5950 | EXPECT_EQ(OK, rv); |
| 5951 | EXPECT_EQ("hello world", response_data); |
| 5952 | |
| 5953 | // Empty the current queue. This is necessary because idle sockets are |
| 5954 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5955 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5956 | |
| 5957 | // 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] | 5958 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5959 | } |
| 5960 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5961 | // Make sure that we recycle a socket after a zero-length response. |
| 5962 | // http://crbug.com/9880 |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5963 | TEST_P(HttpNetworkTransactionTest, RecycleSocketAfterZeroContentLength) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5964 | HttpRequestInfo request; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5965 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5966 | request.url = GURL( |
| 5967 | "http://www.example.org/csi?v=3&s=web&action=&" |
| 5968 | "tran=undefined&ei=mAXcSeegAo-SMurloeUN&" |
| 5969 | "e=17259,18167,19592,19773,19981,20133,20173,20233&" |
| 5970 | "rt=prt.2642,ol.2649,xjs.2951"); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5971 | request.load_flags = 0; |
| 5972 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 5973 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5974 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5975 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5976 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5977 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5978 | MockRead data_reads[] = { |
| 5979 | MockRead("HTTP/1.1 204 No Content\r\n" |
| 5980 | "Content-Length: 0\r\n" |
| 5981 | "Content-Type: text/html\r\n\r\n"), |
| 5982 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5983 | MockRead(SYNCHRONOUS, OK), |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5984 | }; |
| 5985 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5986 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5987 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5988 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5989 | TestCompletionCallback callback; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5990 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5991 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5992 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5993 | |
| 5994 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5995 | EXPECT_EQ(OK, rv); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5996 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5997 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5998 | ASSERT_TRUE(response != NULL); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5999 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6000 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6001 | std::string status_line = response->headers->GetStatusLine(); |
| 6002 | EXPECT_EQ("HTTP/1.1 204 No Content", status_line); |
| 6003 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6004 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6005 | |
| 6006 | std::string response_data; |
| 6007 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6008 | EXPECT_EQ(OK, rv); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6009 | EXPECT_EQ("", response_data); |
| 6010 | |
| 6011 | // Empty the current queue. This is necessary because idle sockets are |
| 6012 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 6013 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6014 | |
| 6015 | // 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] | 6016 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6017 | } |
| 6018 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6019 | TEST_P(HttpNetworkTransactionTest, ResendRequestOnWriteBodyError) { |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 6020 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 6021 | element_readers.push_back( |
| 6022 | make_scoped_ptr(new UploadBytesElementReader("foo", 3))); |
| 6023 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 6024 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6025 | HttpRequestInfo request[2]; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6026 | // Transaction 1: a GET request that succeeds. The socket is recycled |
| 6027 | // after use. |
| 6028 | request[0].method = "GET"; |
| 6029 | request[0].url = GURL("http://www.google.com/"); |
| 6030 | request[0].load_flags = 0; |
| 6031 | // Transaction 2: a POST request. Reuses the socket kept alive from |
| 6032 | // transaction 1. The first attempts fails when writing the POST data. |
| 6033 | // This causes the transaction to retry with a new socket. The second |
| 6034 | // attempt succeeds. |
| 6035 | request[1].method = "POST"; |
| 6036 | request[1].url = GURL("http://www.google.com/login.cgi"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 6037 | request[1].upload_data_stream = &upload_data_stream; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6038 | request[1].load_flags = 0; |
| 6039 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 6040 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6041 | |
| 6042 | // The first socket is used for transaction 1 and the first attempt of |
| 6043 | // transaction 2. |
| 6044 | |
| 6045 | // The response of transaction 1. |
| 6046 | MockRead data_reads1[] = { |
| 6047 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\n"), |
| 6048 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6049 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6050 | }; |
| 6051 | // The mock write results of transaction 1 and the first attempt of |
| 6052 | // transaction 2. |
| 6053 | MockWrite data_writes1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6054 | MockWrite(SYNCHRONOUS, 64), // GET |
| 6055 | MockWrite(SYNCHRONOUS, 93), // POST |
| 6056 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_ABORTED), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6057 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6058 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6059 | data_writes1, arraysize(data_writes1)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6060 | |
| 6061 | // The second socket is used for the second attempt of transaction 2. |
| 6062 | |
| 6063 | // The response of transaction 2. |
| 6064 | MockRead data_reads2[] = { |
| 6065 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 7\r\n\r\n"), |
| 6066 | MockRead("welcome"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6067 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6068 | }; |
| 6069 | // The mock write results of the second attempt of transaction 2. |
| 6070 | MockWrite data_writes2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6071 | MockWrite(SYNCHRONOUS, 93), // POST |
| 6072 | MockWrite(SYNCHRONOUS, 3), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6073 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6074 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6075 | data_writes2, arraysize(data_writes2)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6076 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6077 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6078 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6079 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 6080 | const char* const kExpectedResponseData[] = { |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6081 | "hello world", "welcome" |
| 6082 | }; |
| 6083 | |
| 6084 | for (int i = 0; i < 2; ++i) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6085 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6086 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6087 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6088 | TestCompletionCallback callback; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6089 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6090 | int rv = trans->Start(&request[i], callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6091 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6092 | |
| 6093 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6094 | EXPECT_EQ(OK, rv); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6095 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6096 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6097 | ASSERT_TRUE(response != NULL); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6098 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6099 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6100 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6101 | |
| 6102 | std::string response_data; |
| 6103 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6104 | EXPECT_EQ(OK, rv); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6105 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
| 6106 | } |
| 6107 | } |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6108 | |
| 6109 | // Test the request-challenge-retry sequence for basic auth when there is |
| 6110 | // 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] | 6111 | // it fails the identity from the URL is used to answer the challenge. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6112 | TEST_P(HttpNetworkTransactionTest, AuthIdentityInURL) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6113 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6114 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6115 | request.url = GURL("http://foo:b@[email protected]/"); |
[email protected] | 7b08ba6 | 2012-02-10 20:19:41 | [diff] [blame] | 6116 | request.load_flags = LOAD_NORMAL; |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 6117 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 6118 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6119 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6120 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6121 | |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 6122 | // The password contains an escaped character -- for this test to pass it |
| 6123 | // will need to be unescaped by HttpNetworkTransaction. |
| 6124 | EXPECT_EQ("b%40r", request.url.password()); |
| 6125 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6126 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6127 | MockWrite( |
| 6128 | "GET / HTTP/1.1\r\n" |
| 6129 | "Host: www.example.org\r\n" |
| 6130 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6131 | }; |
| 6132 | |
| 6133 | MockRead data_reads1[] = { |
| 6134 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6135 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6136 | MockRead("Content-Length: 10\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6137 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6138 | }; |
| 6139 | |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6140 | // After the challenge above, the transaction will be restarted using the |
| 6141 | // identity from the url (foo, b@r) to answer the challenge. |
| 6142 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6143 | MockWrite( |
| 6144 | "GET / HTTP/1.1\r\n" |
| 6145 | "Host: www.example.org\r\n" |
| 6146 | "Connection: keep-alive\r\n" |
| 6147 | "Authorization: Basic Zm9vOmJAcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6148 | }; |
| 6149 | |
| 6150 | MockRead data_reads2[] = { |
| 6151 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6152 | MockRead("Content-Length: 100\r\n\r\n"), |
| 6153 | MockRead(SYNCHRONOUS, OK), |
| 6154 | }; |
| 6155 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6156 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6157 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6158 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6159 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6160 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6161 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6162 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6163 | TestCompletionCallback callback1; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6164 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6165 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6166 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6167 | EXPECT_EQ(OK, rv); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6168 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 6169 | |
| 6170 | TestCompletionCallback callback2; |
| 6171 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
| 6172 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6173 | rv = callback2.WaitForResult(); |
| 6174 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6175 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 6176 | |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6177 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6178 | ASSERT_TRUE(response != NULL); |
| 6179 | |
| 6180 | // There is no challenge info, since the identity in URL worked. |
| 6181 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6182 | |
| 6183 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6184 | |
| 6185 | // Empty the current queue. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 6186 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6187 | } |
| 6188 | |
| 6189 | // Test the request-challenge-retry sequence for basic auth when there is an |
| 6190 | // incorrect identity in the URL. The identity from the URL should be used only |
| 6191 | // once. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6192 | TEST_P(HttpNetworkTransactionTest, WrongAuthIdentityInURL) { |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6193 | HttpRequestInfo request; |
| 6194 | request.method = "GET"; |
| 6195 | // Note: the URL has a username:password in it. The password "baz" is |
| 6196 | // wrong (should be "bar"). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6197 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6198 | |
| 6199 | request.load_flags = LOAD_NORMAL; |
| 6200 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 6201 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6202 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6203 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6204 | |
| 6205 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6206 | MockWrite( |
| 6207 | "GET / HTTP/1.1\r\n" |
| 6208 | "Host: www.example.org\r\n" |
| 6209 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6210 | }; |
| 6211 | |
| 6212 | MockRead data_reads1[] = { |
| 6213 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6214 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6215 | MockRead("Content-Length: 10\r\n\r\n"), |
| 6216 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 6217 | }; |
| 6218 | |
| 6219 | // After the challenge above, the transaction will be restarted using the |
| 6220 | // identity from the url (foo, baz) to answer the challenge. |
| 6221 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6222 | MockWrite( |
| 6223 | "GET / HTTP/1.1\r\n" |
| 6224 | "Host: www.example.org\r\n" |
| 6225 | "Connection: keep-alive\r\n" |
| 6226 | "Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6227 | }; |
| 6228 | |
| 6229 | MockRead data_reads2[] = { |
| 6230 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6231 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6232 | MockRead("Content-Length: 10\r\n\r\n"), |
| 6233 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 6234 | }; |
| 6235 | |
| 6236 | // After the challenge above, the transaction will be restarted using the |
| 6237 | // identity supplied by the user (foo, bar) to answer the challenge. |
| 6238 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6239 | MockWrite( |
| 6240 | "GET / HTTP/1.1\r\n" |
| 6241 | "Host: www.example.org\r\n" |
| 6242 | "Connection: keep-alive\r\n" |
| 6243 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6244 | }; |
| 6245 | |
| 6246 | MockRead data_reads3[] = { |
| 6247 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6248 | MockRead("Content-Length: 100\r\n\r\n"), |
| 6249 | MockRead(SYNCHRONOUS, OK), |
| 6250 | }; |
| 6251 | |
| 6252 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6253 | data_writes1, arraysize(data_writes1)); |
| 6254 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6255 | data_writes2, arraysize(data_writes2)); |
| 6256 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 6257 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6258 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6259 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 6260 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6261 | |
| 6262 | TestCompletionCallback callback1; |
| 6263 | |
| 6264 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
| 6265 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6266 | |
| 6267 | rv = callback1.WaitForResult(); |
| 6268 | EXPECT_EQ(OK, rv); |
| 6269 | |
| 6270 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 6271 | TestCompletionCallback callback2; |
| 6272 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
| 6273 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6274 | rv = callback2.WaitForResult(); |
| 6275 | EXPECT_EQ(OK, rv); |
| 6276 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 6277 | |
| 6278 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6279 | ASSERT_TRUE(response != NULL); |
| 6280 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 6281 | |
| 6282 | TestCompletionCallback callback3; |
| 6283 | rv = trans->RestartWithAuth( |
| 6284 | AuthCredentials(kFoo, kBar), callback3.callback()); |
| 6285 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6286 | rv = callback3.WaitForResult(); |
| 6287 | EXPECT_EQ(OK, rv); |
| 6288 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 6289 | |
| 6290 | response = trans->GetResponseInfo(); |
| 6291 | ASSERT_TRUE(response != NULL); |
| 6292 | |
| 6293 | // There is no challenge info, since the identity worked. |
| 6294 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6295 | |
| 6296 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6297 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 6298 | // Empty the current queue. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 6299 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 6300 | } |
| 6301 | |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6302 | |
| 6303 | // Test the request-challenge-retry sequence for basic auth when there is a |
| 6304 | // correct identity in the URL, but its use is being suppressed. The identity |
| 6305 | // from the URL should never be used. |
| 6306 | TEST_P(HttpNetworkTransactionTest, AuthIdentityInURLSuppressed) { |
| 6307 | HttpRequestInfo request; |
| 6308 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6309 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6310 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
| 6311 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 6312 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6313 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6314 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6315 | |
| 6316 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6317 | MockWrite( |
| 6318 | "GET / HTTP/1.1\r\n" |
| 6319 | "Host: www.example.org\r\n" |
| 6320 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6321 | }; |
| 6322 | |
| 6323 | MockRead data_reads1[] = { |
| 6324 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6325 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6326 | MockRead("Content-Length: 10\r\n\r\n"), |
| 6327 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 6328 | }; |
| 6329 | |
| 6330 | // After the challenge above, the transaction will be restarted using the |
| 6331 | // identity supplied by the user, not the one in the URL, to answer the |
| 6332 | // challenge. |
| 6333 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6334 | MockWrite( |
| 6335 | "GET / HTTP/1.1\r\n" |
| 6336 | "Host: www.example.org\r\n" |
| 6337 | "Connection: keep-alive\r\n" |
| 6338 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6339 | }; |
| 6340 | |
| 6341 | MockRead data_reads3[] = { |
| 6342 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6343 | MockRead("Content-Length: 100\r\n\r\n"), |
| 6344 | MockRead(SYNCHRONOUS, OK), |
| 6345 | }; |
| 6346 | |
| 6347 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6348 | data_writes1, arraysize(data_writes1)); |
| 6349 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 6350 | data_writes3, arraysize(data_writes3)); |
| 6351 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6352 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 6353 | |
| 6354 | TestCompletionCallback callback1; |
| 6355 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
| 6356 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6357 | rv = callback1.WaitForResult(); |
| 6358 | EXPECT_EQ(OK, rv); |
| 6359 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 6360 | |
| 6361 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6362 | ASSERT_TRUE(response != NULL); |
| 6363 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 6364 | |
| 6365 | TestCompletionCallback callback3; |
| 6366 | rv = trans->RestartWithAuth( |
| 6367 | AuthCredentials(kFoo, kBar), callback3.callback()); |
| 6368 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6369 | rv = callback3.WaitForResult(); |
| 6370 | EXPECT_EQ(OK, rv); |
| 6371 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 6372 | |
| 6373 | response = trans->GetResponseInfo(); |
| 6374 | ASSERT_TRUE(response != NULL); |
| 6375 | |
| 6376 | // There is no challenge info, since the identity worked. |
| 6377 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6378 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6379 | |
| 6380 | // Empty the current queue. |
| 6381 | base::MessageLoop::current()->RunUntilIdle(); |
| 6382 | } |
| 6383 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6384 | // Test that previously tried username/passwords for a realm get re-used. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6385 | TEST_P(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) { |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 6386 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6387 | |
| 6388 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 6389 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6390 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6391 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6392 | request.url = GURL("http://www.example.org/x/y/z"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6393 | request.load_flags = 0; |
| 6394 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6395 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6396 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6397 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6398 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6399 | MockWrite( |
| 6400 | "GET /x/y/z HTTP/1.1\r\n" |
| 6401 | "Host: www.example.org\r\n" |
| 6402 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6403 | }; |
| 6404 | |
| 6405 | MockRead data_reads1[] = { |
| 6406 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6407 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6408 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6409 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6410 | }; |
| 6411 | |
| 6412 | // Resend with authorization (username=foo, password=bar) |
| 6413 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6414 | MockWrite( |
| 6415 | "GET /x/y/z HTTP/1.1\r\n" |
| 6416 | "Host: www.example.org\r\n" |
| 6417 | "Connection: keep-alive\r\n" |
| 6418 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6419 | }; |
| 6420 | |
| 6421 | // Sever accepts the authorization. |
| 6422 | MockRead data_reads2[] = { |
| 6423 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6424 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6425 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6426 | }; |
| 6427 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6428 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6429 | data_writes1, arraysize(data_writes1)); |
| 6430 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6431 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6432 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6433 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6434 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6435 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6436 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6437 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6438 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6439 | |
| 6440 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6441 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6442 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6443 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6444 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6445 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6446 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6447 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6448 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6449 | rv = trans->RestartWithAuth( |
| 6450 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6451 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6452 | |
| 6453 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6454 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6455 | |
| 6456 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6457 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6458 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6459 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6460 | } |
| 6461 | |
| 6462 | // ------------------------------------------------------------------------ |
| 6463 | |
| 6464 | // Transaction 2: authenticate (foo2, bar2) on MyRealm2 |
| 6465 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6466 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6467 | request.method = "GET"; |
| 6468 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 6469 | // protection space as MyRealm1. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6470 | request.url = GURL("http://www.example.org/x/y/a/b"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6471 | request.load_flags = 0; |
| 6472 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6473 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6474 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6475 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6476 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6477 | MockWrite( |
| 6478 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 6479 | "Host: www.example.org\r\n" |
| 6480 | "Connection: keep-alive\r\n" |
| 6481 | // Send preemptive authorization for MyRealm1 |
| 6482 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6483 | }; |
| 6484 | |
| 6485 | // The server didn't like the preemptive authorization, and |
| 6486 | // challenges us for a different realm (MyRealm2). |
| 6487 | MockRead data_reads1[] = { |
| 6488 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6489 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm2\"\r\n"), |
| 6490 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6491 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6492 | }; |
| 6493 | |
| 6494 | // Resend with authorization for MyRealm2 (username=foo2, password=bar2) |
| 6495 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6496 | MockWrite( |
| 6497 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 6498 | "Host: www.example.org\r\n" |
| 6499 | "Connection: keep-alive\r\n" |
| 6500 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6501 | }; |
| 6502 | |
| 6503 | // Sever accepts the authorization. |
| 6504 | MockRead data_reads2[] = { |
| 6505 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6506 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6507 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6508 | }; |
| 6509 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6510 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6511 | data_writes1, arraysize(data_writes1)); |
| 6512 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6513 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6514 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6515 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6516 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6517 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6518 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6519 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6520 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6521 | |
| 6522 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6523 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6524 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6525 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6526 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6527 | ASSERT_TRUE(response->auth_challenge.get()); |
| 6528 | EXPECT_FALSE(response->auth_challenge->is_proxy); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6529 | EXPECT_EQ("www.example.org:80", |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6530 | response->auth_challenge->challenger.ToString()); |
| 6531 | EXPECT_EQ("MyRealm2", response->auth_challenge->realm); |
| 6532 | EXPECT_EQ("basic", response->auth_challenge->scheme); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6533 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6534 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6535 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6536 | rv = trans->RestartWithAuth( |
| 6537 | AuthCredentials(kFoo2, kBar2), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6538 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6539 | |
| 6540 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6541 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6542 | |
| 6543 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6544 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6545 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6546 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6547 | } |
| 6548 | |
| 6549 | // ------------------------------------------------------------------------ |
| 6550 | |
| 6551 | // Transaction 3: Resend a request in MyRealm's protection space -- |
| 6552 | // succeed with preemptive authorization. |
| 6553 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6554 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6555 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6556 | request.url = GURL("http://www.example.org/x/y/z2"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6557 | request.load_flags = 0; |
| 6558 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6559 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6560 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6561 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6562 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6563 | MockWrite( |
| 6564 | "GET /x/y/z2 HTTP/1.1\r\n" |
| 6565 | "Host: www.example.org\r\n" |
| 6566 | "Connection: keep-alive\r\n" |
| 6567 | // The authorization for MyRealm1 gets sent preemptively |
| 6568 | // (since the url is in the same protection space) |
| 6569 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6570 | }; |
| 6571 | |
| 6572 | // Sever accepts the preemptive authorization |
| 6573 | MockRead data_reads1[] = { |
| 6574 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6575 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6576 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6577 | }; |
| 6578 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6579 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6580 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6581 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6582 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6583 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6584 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6585 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6586 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6587 | |
| 6588 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6589 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6590 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6591 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6592 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6593 | |
| 6594 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6595 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6596 | } |
| 6597 | |
| 6598 | // ------------------------------------------------------------------------ |
| 6599 | |
| 6600 | // Transaction 4: request another URL in MyRealm (however the |
| 6601 | // url is not known to belong to the protection space, so no pre-auth). |
| 6602 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6603 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6604 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6605 | request.url = GURL("http://www.example.org/x/1"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6606 | request.load_flags = 0; |
| 6607 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6608 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6609 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6610 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6611 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6612 | MockWrite( |
| 6613 | "GET /x/1 HTTP/1.1\r\n" |
| 6614 | "Host: www.example.org\r\n" |
| 6615 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6616 | }; |
| 6617 | |
| 6618 | MockRead data_reads1[] = { |
| 6619 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6620 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6621 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6622 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6623 | }; |
| 6624 | |
| 6625 | // Resend with authorization from MyRealm's cache. |
| 6626 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6627 | MockWrite( |
| 6628 | "GET /x/1 HTTP/1.1\r\n" |
| 6629 | "Host: www.example.org\r\n" |
| 6630 | "Connection: keep-alive\r\n" |
| 6631 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6632 | }; |
| 6633 | |
| 6634 | // Sever accepts the authorization. |
| 6635 | MockRead data_reads2[] = { |
| 6636 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6637 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6638 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6639 | }; |
| 6640 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6641 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6642 | data_writes1, arraysize(data_writes1)); |
| 6643 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6644 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6645 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6646 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6647 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6648 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6649 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6650 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6651 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6652 | |
| 6653 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6654 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6655 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6656 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6657 | TestCompletionCallback callback2; |
| 6658 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6659 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6660 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6661 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6662 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 6663 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6664 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6665 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6666 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6667 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6668 | } |
| 6669 | |
| 6670 | // ------------------------------------------------------------------------ |
| 6671 | |
| 6672 | // Transaction 5: request a URL in MyRealm, but the server rejects the |
| 6673 | // cached identity. Should invalidate and re-prompt. |
| 6674 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6675 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6676 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6677 | request.url = GURL("http://www.example.org/p/q/t"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6678 | request.load_flags = 0; |
| 6679 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6680 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6681 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6682 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6683 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6684 | MockWrite( |
| 6685 | "GET /p/q/t HTTP/1.1\r\n" |
| 6686 | "Host: www.example.org\r\n" |
| 6687 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6688 | }; |
| 6689 | |
| 6690 | MockRead data_reads1[] = { |
| 6691 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6692 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6693 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6694 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6695 | }; |
| 6696 | |
| 6697 | // Resend with authorization from cache for MyRealm. |
| 6698 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6699 | MockWrite( |
| 6700 | "GET /p/q/t HTTP/1.1\r\n" |
| 6701 | "Host: www.example.org\r\n" |
| 6702 | "Connection: keep-alive\r\n" |
| 6703 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6704 | }; |
| 6705 | |
| 6706 | // Sever rejects the authorization. |
| 6707 | MockRead data_reads2[] = { |
| 6708 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6709 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6710 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6711 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6712 | }; |
| 6713 | |
| 6714 | // At this point we should prompt for new credentials for MyRealm. |
| 6715 | // Restart with username=foo3, password=foo4. |
| 6716 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6717 | MockWrite( |
| 6718 | "GET /p/q/t HTTP/1.1\r\n" |
| 6719 | "Host: www.example.org\r\n" |
| 6720 | "Connection: keep-alive\r\n" |
| 6721 | "Authorization: Basic Zm9vMzpiYXIz\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6722 | }; |
| 6723 | |
| 6724 | // Sever accepts the authorization. |
| 6725 | MockRead data_reads3[] = { |
| 6726 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6727 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6728 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6729 | }; |
| 6730 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6731 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6732 | data_writes1, arraysize(data_writes1)); |
| 6733 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6734 | data_writes2, arraysize(data_writes2)); |
| 6735 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 6736 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6737 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6738 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 6739 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6740 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6741 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6742 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6743 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6744 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6745 | |
| 6746 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6747 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6748 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6749 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6750 | TestCompletionCallback callback2; |
| 6751 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6752 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6753 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6754 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6755 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 6756 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6757 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6758 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6759 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6760 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6761 | TestCompletionCallback callback3; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6762 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6763 | rv = trans->RestartWithAuth( |
| 6764 | AuthCredentials(kFoo3, kBar3), callback3.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6765 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6766 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6767 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6768 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6769 | |
| 6770 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6771 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6772 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6773 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6774 | } |
| 6775 | } |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6776 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6777 | // Tests that nonce count increments when multiple auth attempts |
| 6778 | // are started with the same nonce. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6779 | TEST_P(HttpNetworkTransactionTest, DigestPreAuthNonceCount) { |
[email protected] | 54fea256 | 2010-11-17 14:40:44 | [diff] [blame] | 6780 | HttpAuthHandlerDigest::Factory* digest_factory = |
| 6781 | new HttpAuthHandlerDigest::Factory(); |
| 6782 | HttpAuthHandlerDigest::FixedNonceGenerator* nonce_generator = |
| 6783 | new HttpAuthHandlerDigest::FixedNonceGenerator("0123456789abcdef"); |
| 6784 | digest_factory->set_nonce_generator(nonce_generator); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6785 | session_deps_.http_auth_handler_factory.reset(digest_factory); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 6786 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6787 | |
| 6788 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 6789 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6790 | HttpRequestInfo request; |
| 6791 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6792 | request.url = GURL("http://www.example.org/x/y/z"); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6793 | request.load_flags = 0; |
| 6794 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6795 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6796 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6797 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6798 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6799 | MockWrite( |
| 6800 | "GET /x/y/z HTTP/1.1\r\n" |
| 6801 | "Host: www.example.org\r\n" |
| 6802 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6803 | }; |
| 6804 | |
| 6805 | MockRead data_reads1[] = { |
| 6806 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6807 | MockRead("WWW-Authenticate: Digest realm=\"digestive\", nonce=\"OU812\", " |
| 6808 | "algorithm=MD5, qop=\"auth\"\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6809 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6810 | }; |
| 6811 | |
| 6812 | // Resend with authorization (username=foo, password=bar) |
| 6813 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6814 | MockWrite( |
| 6815 | "GET /x/y/z HTTP/1.1\r\n" |
| 6816 | "Host: www.example.org\r\n" |
| 6817 | "Connection: keep-alive\r\n" |
| 6818 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 6819 | "nonce=\"OU812\", uri=\"/x/y/z\", algorithm=MD5, " |
| 6820 | "response=\"03ffbcd30add722589c1de345d7a927f\", qop=auth, " |
| 6821 | "nc=00000001, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6822 | }; |
| 6823 | |
| 6824 | // Sever accepts the authorization. |
| 6825 | MockRead data_reads2[] = { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 6826 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6827 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6828 | }; |
| 6829 | |
| 6830 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6831 | data_writes1, arraysize(data_writes1)); |
| 6832 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6833 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6834 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6835 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6836 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6837 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6838 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6839 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6840 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6841 | |
| 6842 | rv = callback1.WaitForResult(); |
| 6843 | EXPECT_EQ(OK, rv); |
| 6844 | |
| 6845 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6846 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6847 | EXPECT_TRUE(CheckDigestServerAuth(response->auth_challenge.get())); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6848 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6849 | TestCompletionCallback callback2; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6850 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6851 | rv = trans->RestartWithAuth( |
| 6852 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6853 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6854 | |
| 6855 | rv = callback2.WaitForResult(); |
| 6856 | EXPECT_EQ(OK, rv); |
| 6857 | |
| 6858 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6859 | ASSERT_TRUE(response != NULL); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6860 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6861 | } |
| 6862 | |
| 6863 | // ------------------------------------------------------------------------ |
| 6864 | |
| 6865 | // Transaction 2: Request another resource in digestive's protection space. |
| 6866 | // This will preemptively add an Authorization header which should have an |
| 6867 | // "nc" value of 2 (as compared to 1 in the first use. |
| 6868 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6869 | HttpRequestInfo request; |
| 6870 | request.method = "GET"; |
| 6871 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 6872 | // protection space as digest. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6873 | request.url = GURL("http://www.example.org/x/y/a/b"); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6874 | request.load_flags = 0; |
| 6875 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6876 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6877 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6878 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6879 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6880 | MockWrite( |
| 6881 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 6882 | "Host: www.example.org\r\n" |
| 6883 | "Connection: keep-alive\r\n" |
| 6884 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 6885 | "nonce=\"OU812\", uri=\"/x/y/a/b\", algorithm=MD5, " |
| 6886 | "response=\"d6f9a2c07d1c5df7b89379dca1269b35\", qop=auth, " |
| 6887 | "nc=00000002, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6888 | }; |
| 6889 | |
| 6890 | // Sever accepts the authorization. |
| 6891 | MockRead data_reads1[] = { |
| 6892 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6893 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6894 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6895 | }; |
| 6896 | |
| 6897 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6898 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6899 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6900 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6901 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6902 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6903 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6904 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6905 | |
| 6906 | rv = callback1.WaitForResult(); |
| 6907 | EXPECT_EQ(OK, rv); |
| 6908 | |
| 6909 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6910 | ASSERT_TRUE(response != NULL); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6911 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6912 | } |
| 6913 | } |
| 6914 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6915 | // Test the ResetStateForRestart() private method. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6916 | TEST_P(HttpNetworkTransactionTest, ResetStateForRestart) { |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6917 | // Create a transaction (the dependencies aren't important). |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 6918 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 6919 | scoped_ptr<HttpNetworkTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6920 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6921 | |
| 6922 | // Setup some state (which we expect ResetStateForRestart() will clear). |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6923 | trans->read_buf_ = new IOBuffer(15); |
| 6924 | trans->read_buf_len_ = 15; |
[email protected] | b94f92d | 2010-10-27 16:45:20 | [diff] [blame] | 6925 | trans->request_headers_.SetHeader("Authorization", "NTLM"); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6926 | |
| 6927 | // Setup state in response_ |
[email protected] | a7e4131 | 2009-12-16 23:18:14 | [diff] [blame] | 6928 | HttpResponseInfo* response = &trans->response_; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 6929 | response->auth_challenge = new AuthChallengeInfo(); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 6930 | response->ssl_info.cert_status = static_cast<CertStatus>(-1); // Nonsensical. |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 6931 | response->response_time = base::Time::Now(); |
| 6932 | response->was_cached = true; // (Wouldn't ever actually be true...) |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6933 | |
| 6934 | { // Setup state for response_.vary_data |
| 6935 | HttpRequestInfo request; |
| 6936 | std::string temp("HTTP/1.1 200 OK\nVary: foo, bar\n\n"); |
| 6937 | std::replace(temp.begin(), temp.end(), '\n', '\0'); |
[email protected] | ad8e04a | 2010-11-01 04:16:27 | [diff] [blame] | 6938 | scoped_refptr<HttpResponseHeaders> headers(new HttpResponseHeaders(temp)); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 6939 | request.extra_headers.SetHeader("Foo", "1"); |
| 6940 | request.extra_headers.SetHeader("bar", "23"); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6941 | EXPECT_TRUE(response->vary_data.Init(request, *headers.get())); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6942 | } |
| 6943 | |
| 6944 | // Cause the above state to be reset. |
| 6945 | trans->ResetStateForRestart(); |
| 6946 | |
| 6947 | // Verify that the state that needed to be reset, has been reset. |
[email protected] | 9b6fee1 | 2009-09-29 18:13:07 | [diff] [blame] | 6948 | EXPECT_TRUE(trans->read_buf_.get() == NULL); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6949 | EXPECT_EQ(0, trans->read_buf_len_); |
[email protected] | b94f92d | 2010-10-27 16:45:20 | [diff] [blame] | 6950 | EXPECT_TRUE(trans->request_headers_.IsEmpty()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 6951 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6952 | EXPECT_TRUE(response->headers.get() == NULL); |
[email protected] | 34f4094 | 2010-10-04 00:34:04 | [diff] [blame] | 6953 | EXPECT_FALSE(response->was_cached); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 6954 | EXPECT_EQ(0U, response->ssl_info.cert_status); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 6955 | EXPECT_FALSE(response->vary_data.is_valid()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6956 | } |
| 6957 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6958 | // Test HTTPS connections to a site with a bad certificate |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6959 | TEST_P(HttpNetworkTransactionTest, HTTPSBadCertificate) { |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6960 | HttpRequestInfo request; |
| 6961 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6962 | request.url = GURL("https://www.example.org/"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6963 | request.load_flags = 0; |
| 6964 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 6965 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6966 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6967 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6968 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6969 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6970 | MockWrite( |
| 6971 | "GET / HTTP/1.1\r\n" |
| 6972 | "Host: www.example.org\r\n" |
| 6973 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6974 | }; |
| 6975 | |
| 6976 | MockRead data_reads[] = { |
| 6977 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6978 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6979 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6980 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6981 | }; |
| 6982 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 6983 | StaticSocketDataProvider ssl_bad_certificate; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6984 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6985 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6986 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 6987 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6988 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6989 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 6990 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6991 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 6992 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6993 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6994 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6995 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6996 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6997 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6998 | |
| 6999 | rv = callback.WaitForResult(); |
| 7000 | EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, rv); |
| 7001 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7002 | rv = trans->RestartIgnoringLastError(callback.callback()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7003 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7004 | |
| 7005 | rv = callback.WaitForResult(); |
| 7006 | EXPECT_EQ(OK, rv); |
| 7007 | |
| 7008 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7009 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7010 | ASSERT_TRUE(response != NULL); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7011 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7012 | } |
| 7013 | |
| 7014 | // Test HTTPS connections to a site with a bad certificate, going through a |
| 7015 | // proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7016 | TEST_P(HttpNetworkTransactionTest, HTTPSBadCertificateViaProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7017 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7018 | |
| 7019 | HttpRequestInfo request; |
| 7020 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7021 | request.url = GURL("https://www.example.org/"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7022 | request.load_flags = 0; |
| 7023 | |
| 7024 | MockWrite proxy_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7025 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7026 | "Host: www.example.org:443\r\n" |
| 7027 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7028 | }; |
| 7029 | |
| 7030 | MockRead proxy_reads[] = { |
| 7031 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7032 | MockRead(SYNCHRONOUS, OK) |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7033 | }; |
| 7034 | |
| 7035 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7036 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7037 | "Host: www.example.org:443\r\n" |
| 7038 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 7039 | MockWrite("GET / HTTP/1.1\r\n" |
| 7040 | "Host: www.example.org\r\n" |
| 7041 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7042 | }; |
| 7043 | |
| 7044 | MockRead data_reads[] = { |
| 7045 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 7046 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7047 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7048 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7049 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7050 | }; |
| 7051 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7052 | StaticSocketDataProvider ssl_bad_certificate( |
| 7053 | proxy_reads, arraysize(proxy_reads), |
| 7054 | proxy_writes, arraysize(proxy_writes)); |
| 7055 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7056 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7057 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 7058 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7059 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7060 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 7061 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7062 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 7063 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7064 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7065 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7066 | |
| 7067 | for (int i = 0; i < 2; i++) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7068 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7069 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7070 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 7071 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7072 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7073 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7074 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7075 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7076 | |
| 7077 | rv = callback.WaitForResult(); |
| 7078 | EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, rv); |
| 7079 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7080 | rv = trans->RestartIgnoringLastError(callback.callback()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7081 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7082 | |
| 7083 | rv = callback.WaitForResult(); |
| 7084 | EXPECT_EQ(OK, rv); |
| 7085 | |
| 7086 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7087 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7088 | ASSERT_TRUE(response != NULL); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7089 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7090 | } |
| 7091 | } |
| 7092 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7093 | |
| 7094 | // Test HTTPS connections to a site, going through an HTTPS proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7095 | TEST_P(HttpNetworkTransactionTest, HTTPSViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7096 | session_deps_.proxy_service = |
| 7097 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7098 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7099 | session_deps_.net_log = &net_log; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7100 | |
| 7101 | HttpRequestInfo request; |
| 7102 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7103 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7104 | request.load_flags = 0; |
| 7105 | |
| 7106 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7107 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7108 | "Host: www.example.org:443\r\n" |
| 7109 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 7110 | MockWrite("GET / HTTP/1.1\r\n" |
| 7111 | "Host: www.example.org\r\n" |
| 7112 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7113 | }; |
| 7114 | |
| 7115 | MockRead data_reads[] = { |
| 7116 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 7117 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 7118 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7119 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7120 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7121 | }; |
| 7122 | |
| 7123 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7124 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7125 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
| 7126 | SSLSocketDataProvider tunnel_ssl(ASYNC, OK); // SSL through the tunnel |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7127 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7128 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7129 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
| 7130 | session_deps_.socket_factory->AddSSLSocketDataProvider(&tunnel_ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7131 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7132 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7133 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7134 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7135 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7136 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7137 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7138 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7139 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7140 | |
| 7141 | rv = callback.WaitForResult(); |
| 7142 | EXPECT_EQ(OK, rv); |
| 7143 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7144 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7145 | ASSERT_TRUE(response != NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7146 | |
| 7147 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 7148 | EXPECT_EQ(200, response->headers->response_code()); |
| 7149 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7150 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7151 | |
| 7152 | LoadTimingInfo load_timing_info; |
| 7153 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7154 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 7155 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7156 | } |
| 7157 | |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7158 | // Test an HTTPS Proxy's ability to redirect a CONNECT request |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7159 | TEST_P(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7160 | session_deps_.proxy_service = |
| 7161 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7162 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7163 | session_deps_.net_log = &net_log; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7164 | |
| 7165 | HttpRequestInfo request; |
| 7166 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7167 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7168 | request.load_flags = 0; |
| 7169 | |
| 7170 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7171 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7172 | "Host: www.example.org:443\r\n" |
| 7173 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7174 | }; |
| 7175 | |
| 7176 | MockRead data_reads[] = { |
| 7177 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 7178 | MockRead("Location: http://login.example.com/\r\n"), |
| 7179 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7180 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7181 | }; |
| 7182 | |
| 7183 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7184 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7185 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7186 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7187 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7188 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7189 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7190 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7191 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7192 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7193 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7194 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7195 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7196 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7197 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7198 | |
| 7199 | rv = callback.WaitForResult(); |
| 7200 | EXPECT_EQ(OK, rv); |
| 7201 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7202 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7203 | ASSERT_TRUE(response != NULL); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7204 | |
| 7205 | EXPECT_EQ(302, response->headers->response_code()); |
| 7206 | std::string url; |
| 7207 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 7208 | EXPECT_EQ("http://login.example.com/", url); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7209 | |
| 7210 | // In the case of redirects from proxies, HttpNetworkTransaction returns |
| 7211 | // timing for the proxy connection instead of the connection to the host, |
| 7212 | // and no send / receive times. |
| 7213 | // See HttpNetworkTransaction::OnHttpsProxyTunnelResponse. |
| 7214 | LoadTimingInfo load_timing_info; |
| 7215 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7216 | |
| 7217 | EXPECT_FALSE(load_timing_info.socket_reused); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 7218 | EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7219 | |
| 7220 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 7221 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 7222 | load_timing_info.proxy_resolve_end); |
| 7223 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 7224 | load_timing_info.connect_timing.connect_start); |
| 7225 | ExpectConnectTimingHasTimes( |
| 7226 | load_timing_info.connect_timing, |
| 7227 | CONNECT_TIMING_HAS_DNS_TIMES | CONNECT_TIMING_HAS_SSL_TIMES); |
| 7228 | |
| 7229 | EXPECT_TRUE(load_timing_info.send_start.is_null()); |
| 7230 | EXPECT_TRUE(load_timing_info.send_end.is_null()); |
| 7231 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7232 | } |
| 7233 | |
| 7234 | // Test an HTTPS (SPDY) Proxy's ability to redirect a CONNECT request |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7235 | TEST_P(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaSpdyProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7236 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7237 | |
| 7238 | HttpRequestInfo request; |
| 7239 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7240 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7241 | request.load_flags = 0; |
| 7242 | |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 7243 | scoped_ptr<SpdyFrame> conn(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7244 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 7245 | scoped_ptr<SpdyFrame> goaway( |
| 7246 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7247 | MockWrite data_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7248 | CreateMockWrite(*conn.get(), 0, SYNCHRONOUS), |
| 7249 | CreateMockWrite(*goaway.get(), 2, SYNCHRONOUS), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7250 | }; |
| 7251 | |
| 7252 | static const char* const kExtraHeaders[] = { |
| 7253 | "location", |
| 7254 | "http://login.example.com/", |
| 7255 | }; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 7256 | scoped_ptr<SpdyFrame> resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7257 | spdy_util_.ConstructSpdySynReplyError("302 Redirect", kExtraHeaders, |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7258 | arraysize(kExtraHeaders)/2, 1)); |
| 7259 | MockRead data_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7260 | CreateMockRead(*resp.get(), 1), MockRead(ASYNC, 0, 3), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7261 | }; |
| 7262 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7263 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 7264 | arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7265 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 7266 | proxy_ssl.SetNextProto(GetProtocol()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7267 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7268 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7269 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7270 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7271 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7272 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7273 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7274 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7275 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7276 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7277 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7278 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7279 | |
| 7280 | rv = callback.WaitForResult(); |
| 7281 | EXPECT_EQ(OK, rv); |
| 7282 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7283 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7284 | ASSERT_TRUE(response != NULL); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7285 | |
| 7286 | EXPECT_EQ(302, response->headers->response_code()); |
| 7287 | std::string url; |
| 7288 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 7289 | EXPECT_EQ("http://login.example.com/", url); |
| 7290 | } |
| 7291 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 7292 | // Test that an HTTPS proxy's response to a CONNECT request is filtered. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7293 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 7294 | ErrorResponseToHttpsConnectViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7295 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7296 | |
| 7297 | HttpRequestInfo request; |
| 7298 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7299 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7300 | request.load_flags = 0; |
| 7301 | |
| 7302 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7303 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7304 | "Host: www.example.org:443\r\n" |
| 7305 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7306 | }; |
| 7307 | |
| 7308 | MockRead data_reads[] = { |
| 7309 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 7310 | MockRead("Content-Length: 23\r\n\r\n"), |
| 7311 | MockRead("The host does not exist"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7312 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7313 | }; |
| 7314 | |
| 7315 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7316 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7317 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7318 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7319 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7320 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7321 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7322 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7323 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7324 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7325 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7326 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7327 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7328 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7329 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7330 | |
| 7331 | rv = callback.WaitForResult(); |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 7332 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7333 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 7334 | // TODO(ttuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7335 | } |
| 7336 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 7337 | // Test that a SPDY proxy's response to a CONNECT request is filtered. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7338 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 7339 | ErrorResponseToHttpsConnectViaSpdyProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7340 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7341 | |
| 7342 | HttpRequestInfo request; |
| 7343 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7344 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7345 | request.load_flags = 0; |
| 7346 | |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 7347 | scoped_ptr<SpdyFrame> conn(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7348 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 7349 | scoped_ptr<SpdyFrame> rst( |
| 7350 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7351 | MockWrite data_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7352 | CreateMockWrite(*conn.get(), 0), CreateMockWrite(*rst.get(), 3), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7353 | }; |
| 7354 | |
| 7355 | static const char* const kExtraHeaders[] = { |
| 7356 | "location", |
| 7357 | "http://login.example.com/", |
| 7358 | }; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 7359 | scoped_ptr<SpdyFrame> resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7360 | spdy_util_.ConstructSpdySynReplyError("404 Not Found", kExtraHeaders, |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7361 | arraysize(kExtraHeaders)/2, 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 7362 | scoped_ptr<SpdyFrame> body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7363 | spdy_util_.ConstructSpdyBodyFrame( |
| 7364 | 1, "The host does not exist", 23, true)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7365 | MockRead data_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7366 | CreateMockRead(*resp.get(), 1), |
| 7367 | CreateMockRead(*body.get(), 2), |
| 7368 | MockRead(ASYNC, 0, 4), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7369 | }; |
| 7370 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7371 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 7372 | arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7373 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 7374 | proxy_ssl.SetNextProto(GetProtocol()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7375 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7376 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7377 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7378 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7379 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7380 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7381 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7382 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7383 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7384 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7385 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7386 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7387 | |
| 7388 | rv = callback.WaitForResult(); |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 7389 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7390 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 7391 | // TODO(ttuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7392 | } |
| 7393 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7394 | // Test the request-challenge-retry sequence for basic auth, through |
| 7395 | // a SPDY proxy over a single SPDY session. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7396 | TEST_P(HttpNetworkTransactionTest, BasicAuthSpdyProxy) { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7397 | HttpRequestInfo request; |
| 7398 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7399 | request.url = GURL("https://www.example.org/"); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7400 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 7401 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7402 | |
| 7403 | // Configure against https proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7404 | session_deps_.proxy_service = |
| 7405 | ProxyService::CreateFixedFromPacResult("HTTPS myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7406 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7407 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7408 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7409 | |
| 7410 | // Since we have proxy, should try to establish tunnel. |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 7411 | scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7412 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 7413 | scoped_ptr<SpdyFrame> rst( |
| 7414 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 7415 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7416 | |
| 7417 | // After calling trans->RestartWithAuth(), this is the request we should |
| 7418 | // be issuing -- the final header line contains the credentials. |
| 7419 | const char* const kAuthCredentials[] = { |
| 7420 | "proxy-authorization", "Basic Zm9vOmJhcg==", |
| 7421 | }; |
[email protected] | fba2dbde | 2013-05-24 16:09:01 | [diff] [blame] | 7422 | scoped_ptr<SpdyFrame> connect2(spdy_util_.ConstructSpdyConnect( |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 7423 | kAuthCredentials, arraysize(kAuthCredentials) / 2, 3, LOWEST, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7424 | HostPortPair("www.example.org", 443))); |
| 7425 | // fetch https://www.example.org/ via HTTP |
| 7426 | const char get[] = |
| 7427 | "GET / HTTP/1.1\r\n" |
| 7428 | "Host: www.example.org\r\n" |
| 7429 | "Connection: keep-alive\r\n\r\n"; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 7430 | scoped_ptr<SpdyFrame> wrapped_get( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7431 | spdy_util_.ConstructSpdyBodyFrame(3, get, strlen(get), false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7432 | |
| 7433 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7434 | CreateMockWrite(*req, 0, ASYNC), |
| 7435 | CreateMockWrite(*rst, 2, ASYNC), |
| 7436 | CreateMockWrite(*connect2, 3), |
| 7437 | CreateMockWrite(*wrapped_get, 5), |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7438 | }; |
| 7439 | |
| 7440 | // The proxy responds to the connect with a 407, using a persistent |
| 7441 | // connection. |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 7442 | const char kAuthStatus[] = "407"; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7443 | const char* const kAuthChallenge[] = { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7444 | "proxy-authenticate", "Basic realm=\"MyRealm1\"", |
| 7445 | }; |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 7446 | scoped_ptr<SpdyFrame> conn_auth_resp(spdy_util_.ConstructSpdySynReplyError( |
| 7447 | kAuthStatus, kAuthChallenge, arraysize(kAuthChallenge) / 2, 1)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7448 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7449 | scoped_ptr<SpdyFrame> conn_resp( |
| 7450 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7451 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 7452 | "Content-Length: 5\r\n\r\n"; |
| 7453 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 7454 | scoped_ptr<SpdyFrame> wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7455 | spdy_util_.ConstructSpdyBodyFrame(3, resp, strlen(resp), false)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 7456 | scoped_ptr<SpdyFrame> wrapped_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7457 | spdy_util_.ConstructSpdyBodyFrame(3, "hello", 5, false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7458 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7459 | CreateMockRead(*conn_auth_resp, 1, ASYNC), |
| 7460 | CreateMockRead(*conn_resp, 4, ASYNC), |
| 7461 | CreateMockRead(*wrapped_get_resp, 6, ASYNC), |
| 7462 | CreateMockRead(*wrapped_body, 7, ASYNC), |
| 7463 | MockRead(ASYNC, OK, 8), // EOF. May or may not be read. |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7464 | }; |
| 7465 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7466 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 7467 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7468 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7469 | // Negotiate SPDY to the proxy |
| 7470 | SSLSocketDataProvider proxy(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 7471 | proxy.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7472 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7473 | // Vanilla SSL to the server |
| 7474 | SSLSocketDataProvider server(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7475 | session_deps_.socket_factory->AddSSLSocketDataProvider(&server); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7476 | |
| 7477 | TestCompletionCallback callback1; |
| 7478 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7479 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7480 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7481 | |
| 7482 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 7483 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7484 | |
| 7485 | rv = callback1.WaitForResult(); |
| 7486 | EXPECT_EQ(OK, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 7487 | TestNetLogEntry::List entries; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7488 | log.GetEntries(&entries); |
| 7489 | size_t pos = ExpectLogContainsSomewhere( |
| 7490 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 7491 | NetLog::PHASE_NONE); |
| 7492 | ExpectLogContainsSomewhere( |
| 7493 | entries, pos, |
| 7494 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 7495 | NetLog::PHASE_NONE); |
| 7496 | |
| 7497 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7498 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7499 | ASSERT_FALSE(response->headers.get() == NULL); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7500 | EXPECT_EQ(407, response->headers->response_code()); |
| 7501 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 7502 | EXPECT_TRUE(response->auth_challenge.get() != NULL); |
| 7503 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 7504 | |
| 7505 | TestCompletionCallback callback2; |
| 7506 | |
| 7507 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 7508 | callback2.callback()); |
| 7509 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7510 | |
| 7511 | rv = callback2.WaitForResult(); |
| 7512 | EXPECT_EQ(OK, rv); |
| 7513 | |
| 7514 | response = trans->GetResponseInfo(); |
| 7515 | ASSERT_TRUE(response != NULL); |
| 7516 | |
| 7517 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 7518 | EXPECT_EQ(200, response->headers->response_code()); |
| 7519 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 7520 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 7521 | |
| 7522 | // The password prompt info should not be set. |
| 7523 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 7524 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7525 | LoadTimingInfo load_timing_info; |
| 7526 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7527 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 7528 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 7529 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7530 | trans.reset(); |
| 7531 | session->CloseAllConnections(); |
| 7532 | } |
| 7533 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7534 | // Test that an explicitly trusted SPDY proxy can push a resource from an |
| 7535 | // origin that is different from that of its associated resource. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7536 | TEST_P(HttpNetworkTransactionTest, CrossOriginProxyPush) { |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7537 | HttpRequestInfo request; |
| 7538 | HttpRequestInfo push_request; |
| 7539 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7540 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7541 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7542 | push_request.method = "GET"; |
| 7543 | push_request.url = GURL("http://www.another-origin.com/foo.dat"); |
| 7544 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7545 | // Configure against https proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7546 | session_deps_.proxy_service = |
| 7547 | ProxyService::CreateFixedFromPacResult("HTTPS myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7548 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7549 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 7550 | |
| 7551 | // Enable cross-origin push. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7552 | session_deps_.trusted_spdy_proxy = "myproxy:70"; |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 7553 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7554 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7555 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 7556 | scoped_ptr<SpdyFrame> stream1_syn( |
| 7557 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7558 | |
| 7559 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7560 | CreateMockWrite(*stream1_syn, 0, ASYNC), |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7561 | }; |
| 7562 | |
| 7563 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7564 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7565 | |
| 7566 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7567 | stream1_body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7568 | |
| 7569 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7570 | stream2_syn(spdy_util_.ConstructSpdyPush(NULL, |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7571 | 0, |
| 7572 | 2, |
| 7573 | 1, |
| 7574 | "http://www.another-origin.com/foo.dat")); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 7575 | const char kPushedData[] = "pushed"; |
| 7576 | scoped_ptr<SpdyFrame> stream2_body( |
| 7577 | spdy_util_.ConstructSpdyBodyFrame( |
| 7578 | 2, kPushedData, strlen(kPushedData), true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7579 | |
| 7580 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7581 | CreateMockRead(*stream1_reply, 1, ASYNC), |
| 7582 | CreateMockRead(*stream2_syn, 2, ASYNC), |
| 7583 | CreateMockRead(*stream1_body, 3, ASYNC), |
| 7584 | CreateMockRead(*stream2_body, 4, ASYNC), |
| 7585 | MockRead(ASYNC, ERR_IO_PENDING, 5), // Force a pause |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7586 | }; |
| 7587 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7588 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 7589 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7590 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7591 | // Negotiate SPDY to the proxy |
| 7592 | SSLSocketDataProvider proxy(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 7593 | proxy.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7594 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7595 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7596 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7597 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7598 | TestCompletionCallback callback; |
| 7599 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
| 7600 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7601 | |
| 7602 | rv = callback.WaitForResult(); |
| 7603 | EXPECT_EQ(OK, rv); |
| 7604 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7605 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7606 | scoped_ptr<HttpTransaction> push_trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7607 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 7608 | rv = push_trans->Start(&push_request, callback.callback(), log.bound()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7609 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7610 | |
| 7611 | rv = callback.WaitForResult(); |
| 7612 | EXPECT_EQ(OK, rv); |
| 7613 | const HttpResponseInfo* push_response = push_trans->GetResponseInfo(); |
| 7614 | |
| 7615 | ASSERT_TRUE(response != NULL); |
| 7616 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 7617 | |
| 7618 | EXPECT_EQ(200, response->headers->response_code()); |
| 7619 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 7620 | |
| 7621 | std::string response_data; |
| 7622 | rv = ReadTransaction(trans.get(), &response_data); |
| 7623 | EXPECT_EQ(OK, rv); |
| 7624 | EXPECT_EQ("hello!", response_data); |
| 7625 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7626 | LoadTimingInfo load_timing_info; |
| 7627 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7628 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 7629 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 7630 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7631 | // Verify the pushed stream. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7632 | EXPECT_TRUE(push_response->headers.get() != NULL); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7633 | EXPECT_EQ(200, push_response->headers->response_code()); |
| 7634 | |
| 7635 | rv = ReadTransaction(push_trans.get(), &response_data); |
| 7636 | EXPECT_EQ(OK, rv); |
| 7637 | EXPECT_EQ("pushed", response_data); |
| 7638 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7639 | LoadTimingInfo push_load_timing_info; |
| 7640 | EXPECT_TRUE(push_trans->GetLoadTimingInfo(&push_load_timing_info)); |
| 7641 | TestLoadTimingReusedWithPac(push_load_timing_info); |
| 7642 | // The transactions should share a socket ID, despite being for different |
| 7643 | // origins. |
| 7644 | EXPECT_EQ(load_timing_info.socket_log_id, |
| 7645 | push_load_timing_info.socket_log_id); |
| 7646 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7647 | trans.reset(); |
| 7648 | push_trans.reset(); |
| 7649 | session->CloseAllConnections(); |
| 7650 | } |
| 7651 | |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7652 | // Test that an explicitly trusted SPDY proxy cannot push HTTPS content. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7653 | TEST_P(HttpNetworkTransactionTest, CrossOriginProxyPushCorrectness) { |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7654 | HttpRequestInfo request; |
| 7655 | |
| 7656 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7657 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7658 | |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7659 | // Configure against https proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7660 | session_deps_.proxy_service = ProxyService::CreateFixed("https://myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7661 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7662 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 7663 | |
| 7664 | // Enable cross-origin push. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7665 | session_deps_.trusted_spdy_proxy = "myproxy:70"; |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 7666 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7667 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7668 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 7669 | scoped_ptr<SpdyFrame> stream1_syn( |
| 7670 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7671 | |
| 7672 | scoped_ptr<SpdyFrame> push_rst( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 7673 | spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_REFUSED_STREAM)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7674 | |
| 7675 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7676 | CreateMockWrite(*stream1_syn, 0, ASYNC), CreateMockWrite(*push_rst, 3), |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7677 | }; |
| 7678 | |
| 7679 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7680 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7681 | |
| 7682 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7683 | stream1_body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7684 | |
| 7685 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7686 | stream2_syn(spdy_util_.ConstructSpdyPush(NULL, |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7687 | 0, |
| 7688 | 2, |
| 7689 | 1, |
| 7690 | "https://www.another-origin.com/foo.dat")); |
| 7691 | |
| 7692 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7693 | CreateMockRead(*stream1_reply, 1, ASYNC), |
| 7694 | CreateMockRead(*stream2_syn, 2, ASYNC), |
| 7695 | CreateMockRead(*stream1_body, 4, ASYNC), |
| 7696 | MockRead(ASYNC, ERR_IO_PENDING, 5), // Force a pause |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7697 | }; |
| 7698 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7699 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 7700 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7701 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7702 | // Negotiate SPDY to the proxy |
| 7703 | SSLSocketDataProvider proxy(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 7704 | proxy.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7705 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7706 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7707 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7708 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7709 | TestCompletionCallback callback; |
| 7710 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
| 7711 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7712 | |
| 7713 | rv = callback.WaitForResult(); |
| 7714 | EXPECT_EQ(OK, rv); |
| 7715 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7716 | |
| 7717 | ASSERT_TRUE(response != NULL); |
| 7718 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 7719 | |
| 7720 | EXPECT_EQ(200, response->headers->response_code()); |
| 7721 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 7722 | |
| 7723 | std::string response_data; |
| 7724 | rv = ReadTransaction(trans.get(), &response_data); |
| 7725 | EXPECT_EQ(OK, rv); |
| 7726 | EXPECT_EQ("hello!", response_data); |
| 7727 | |
| 7728 | trans.reset(); |
| 7729 | session->CloseAllConnections(); |
| 7730 | } |
| 7731 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7732 | // Test HTTPS connections to a site with a bad certificate, going through an |
| 7733 | // HTTPS proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7734 | TEST_P(HttpNetworkTransactionTest, HTTPSBadCertificateViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7735 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7736 | |
| 7737 | HttpRequestInfo request; |
| 7738 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7739 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7740 | request.load_flags = 0; |
| 7741 | |
| 7742 | // Attempt to fetch the URL from a server with a bad cert |
| 7743 | MockWrite bad_cert_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7744 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7745 | "Host: www.example.org:443\r\n" |
| 7746 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7747 | }; |
| 7748 | |
| 7749 | MockRead bad_cert_reads[] = { |
| 7750 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7751 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7752 | }; |
| 7753 | |
| 7754 | // Attempt to fetch the URL with a good cert |
| 7755 | MockWrite good_data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7756 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7757 | "Host: www.example.org:443\r\n" |
| 7758 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 7759 | MockWrite("GET / HTTP/1.1\r\n" |
| 7760 | "Host: www.example.org\r\n" |
| 7761 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7762 | }; |
| 7763 | |
| 7764 | MockRead good_cert_reads[] = { |
| 7765 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 7766 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7767 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7768 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7769 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7770 | }; |
| 7771 | |
| 7772 | StaticSocketDataProvider ssl_bad_certificate( |
| 7773 | bad_cert_reads, arraysize(bad_cert_reads), |
| 7774 | bad_cert_writes, arraysize(bad_cert_writes)); |
| 7775 | StaticSocketDataProvider data(good_cert_reads, arraysize(good_cert_reads), |
| 7776 | good_data_writes, arraysize(good_data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7777 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 7778 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7779 | |
| 7780 | // SSL to the proxy, then CONNECT request, then SSL with bad certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7781 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 7782 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 7783 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7784 | |
| 7785 | // SSL to the proxy, then CONNECT request, then valid SSL certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7786 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 7787 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7788 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7789 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7790 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7791 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7792 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7793 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7794 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7795 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7796 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7797 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7798 | |
| 7799 | rv = callback.WaitForResult(); |
| 7800 | EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, rv); |
| 7801 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7802 | rv = trans->RestartIgnoringLastError(callback.callback()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7803 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7804 | |
| 7805 | rv = callback.WaitForResult(); |
| 7806 | EXPECT_EQ(OK, rv); |
| 7807 | |
| 7808 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7809 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7810 | ASSERT_TRUE(response != NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7811 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7812 | } |
| 7813 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7814 | TEST_P(HttpNetworkTransactionTest, BuildRequest_UserAgent) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7815 | HttpRequestInfo request; |
| 7816 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7817 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 7818 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 7819 | "Chromium Ultra Awesome X Edition"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7820 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7821 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7822 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7823 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7824 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7825 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7826 | MockWrite( |
| 7827 | "GET / HTTP/1.1\r\n" |
| 7828 | "Host: www.example.org\r\n" |
| 7829 | "Connection: keep-alive\r\n" |
| 7830 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7831 | }; |
| 7832 | |
| 7833 | // Lastly, the server responds with the actual content. |
| 7834 | MockRead data_reads[] = { |
| 7835 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7836 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7837 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7838 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7839 | }; |
| 7840 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7841 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7842 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7843 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7844 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7845 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7846 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7847 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7848 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7849 | |
| 7850 | rv = callback.WaitForResult(); |
| 7851 | EXPECT_EQ(OK, rv); |
| 7852 | } |
| 7853 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7854 | TEST_P(HttpNetworkTransactionTest, BuildRequest_UserAgentOverTunnel) { |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 7855 | HttpRequestInfo request; |
| 7856 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7857 | request.url = GURL("https://www.example.org/"); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 7858 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 7859 | "Chromium Ultra Awesome X Edition"); |
| 7860 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7861 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7862 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7863 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7864 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7865 | |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 7866 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7867 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7868 | "Host: www.example.org:443\r\n" |
| 7869 | "Proxy-Connection: keep-alive\r\n" |
| 7870 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 7871 | }; |
| 7872 | MockRead data_reads[] = { |
| 7873 | // Return an error, so the transaction stops here (this test isn't |
| 7874 | // interested in the rest). |
| 7875 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 7876 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7877 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 7878 | }; |
| 7879 | |
| 7880 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7881 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7882 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 7883 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7884 | TestCompletionCallback callback; |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 7885 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7886 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 7887 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7888 | |
| 7889 | rv = callback.WaitForResult(); |
| 7890 | EXPECT_EQ(OK, rv); |
| 7891 | } |
| 7892 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7893 | TEST_P(HttpNetworkTransactionTest, BuildRequest_Referer) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7894 | HttpRequestInfo request; |
| 7895 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7896 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7897 | request.load_flags = 0; |
[email protected] | c1045010 | 2011-06-27 09:06:16 | [diff] [blame] | 7898 | request.extra_headers.SetHeader(HttpRequestHeaders::kReferer, |
| 7899 | "http://the.previous.site.com/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7900 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7901 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7902 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7903 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7904 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7905 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7906 | MockWrite( |
| 7907 | "GET / HTTP/1.1\r\n" |
| 7908 | "Host: www.example.org\r\n" |
| 7909 | "Connection: keep-alive\r\n" |
| 7910 | "Referer: http://the.previous.site.com/\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7911 | }; |
| 7912 | |
| 7913 | // Lastly, the server responds with the actual content. |
| 7914 | MockRead data_reads[] = { |
| 7915 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7916 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7917 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7918 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7919 | }; |
| 7920 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7921 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7922 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7923 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7924 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7925 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7926 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7927 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7928 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7929 | |
| 7930 | rv = callback.WaitForResult(); |
| 7931 | EXPECT_EQ(OK, rv); |
| 7932 | } |
| 7933 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7934 | TEST_P(HttpNetworkTransactionTest, BuildRequest_PostContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7935 | HttpRequestInfo request; |
| 7936 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7937 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7938 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7939 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7940 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7941 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7942 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7943 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7944 | MockWrite( |
| 7945 | "POST / HTTP/1.1\r\n" |
| 7946 | "Host: www.example.org\r\n" |
| 7947 | "Connection: keep-alive\r\n" |
| 7948 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7949 | }; |
| 7950 | |
| 7951 | // Lastly, the server responds with the actual content. |
| 7952 | MockRead data_reads[] = { |
| 7953 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7954 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7955 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7956 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7957 | }; |
| 7958 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7959 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7960 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7961 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7962 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7963 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7964 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7965 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7966 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7967 | |
| 7968 | rv = callback.WaitForResult(); |
| 7969 | EXPECT_EQ(OK, rv); |
| 7970 | } |
| 7971 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7972 | TEST_P(HttpNetworkTransactionTest, BuildRequest_PutContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7973 | HttpRequestInfo request; |
| 7974 | request.method = "PUT"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7975 | request.url = GURL("http://www.example.org/"); |
[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 | "PUT / HTTP/1.1\r\n" |
| 7984 | "Host: www.example.org\r\n" |
| 7985 | "Connection: keep-alive\r\n" |
| 7986 | "Content-Length: 0\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_HeadContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8011 | HttpRequestInfo request; |
| 8012 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8013 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8014 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8015 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8016 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8017 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8018 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8019 | MockWrite data_writes[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 8020 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 8021 | "Host: www.example.org\r\n" |
| 8022 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8023 | }; |
| 8024 | |
| 8025 | // Lastly, the server responds with the actual content. |
| 8026 | MockRead data_reads[] = { |
| 8027 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8028 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8029 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8030 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8031 | }; |
| 8032 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8033 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8034 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8035 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8036 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8037 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8038 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8039 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8040 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8041 | |
| 8042 | rv = callback.WaitForResult(); |
| 8043 | EXPECT_EQ(OK, rv); |
| 8044 | } |
| 8045 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8046 | TEST_P(HttpNetworkTransactionTest, BuildRequest_CacheControlNoCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8047 | HttpRequestInfo request; |
| 8048 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8049 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8050 | request.load_flags = LOAD_BYPASS_CACHE; |
| 8051 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8052 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8053 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8054 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8055 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8056 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8057 | MockWrite( |
| 8058 | "GET / HTTP/1.1\r\n" |
| 8059 | "Host: www.example.org\r\n" |
| 8060 | "Connection: keep-alive\r\n" |
| 8061 | "Pragma: no-cache\r\n" |
| 8062 | "Cache-Control: no-cache\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8063 | }; |
| 8064 | |
| 8065 | // Lastly, the server responds with the actual content. |
| 8066 | MockRead data_reads[] = { |
| 8067 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8068 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8069 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8070 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8071 | }; |
| 8072 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8073 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8074 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8075 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8076 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8077 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8078 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8079 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8080 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8081 | |
| 8082 | rv = callback.WaitForResult(); |
| 8083 | EXPECT_EQ(OK, rv); |
| 8084 | } |
| 8085 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8086 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8087 | BuildRequest_CacheControlValidateCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8088 | HttpRequestInfo request; |
| 8089 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8090 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8091 | request.load_flags = LOAD_VALIDATE_CACHE; |
| 8092 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8093 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8094 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8095 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8096 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8097 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8098 | MockWrite( |
| 8099 | "GET / HTTP/1.1\r\n" |
| 8100 | "Host: www.example.org\r\n" |
| 8101 | "Connection: keep-alive\r\n" |
| 8102 | "Cache-Control: max-age=0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8103 | }; |
| 8104 | |
| 8105 | // Lastly, the server responds with the actual content. |
| 8106 | MockRead data_reads[] = { |
| 8107 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8108 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8109 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8110 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8111 | }; |
| 8112 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8113 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8114 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8115 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8116 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8117 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8118 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8119 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8120 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8121 | |
| 8122 | rv = callback.WaitForResult(); |
| 8123 | EXPECT_EQ(OK, rv); |
| 8124 | } |
| 8125 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8126 | TEST_P(HttpNetworkTransactionTest, BuildRequest_ExtraHeaders) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8127 | HttpRequestInfo request; |
| 8128 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8129 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 8130 | request.extra_headers.SetHeader("FooHeader", "Bar"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8131 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8132 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8133 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8134 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8135 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8136 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8137 | MockWrite( |
| 8138 | "GET / HTTP/1.1\r\n" |
| 8139 | "Host: www.example.org\r\n" |
| 8140 | "Connection: keep-alive\r\n" |
| 8141 | "FooHeader: Bar\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8142 | }; |
| 8143 | |
| 8144 | // Lastly, the server responds with the actual content. |
| 8145 | MockRead data_reads[] = { |
| 8146 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8147 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8148 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8149 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8150 | }; |
| 8151 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8152 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8153 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8154 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8155 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8156 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8157 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8158 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8159 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8160 | |
| 8161 | rv = callback.WaitForResult(); |
| 8162 | EXPECT_EQ(OK, rv); |
| 8163 | } |
| 8164 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8165 | TEST_P(HttpNetworkTransactionTest, BuildRequest_ExtraHeadersStripped) { |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8166 | HttpRequestInfo request; |
| 8167 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8168 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 8169 | request.extra_headers.SetHeader("referer", "www.foo.com"); |
| 8170 | request.extra_headers.SetHeader("hEllo", "Kitty"); |
| 8171 | request.extra_headers.SetHeader("FoO", "bar"); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8172 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8173 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8174 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8175 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8176 | |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8177 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8178 | MockWrite( |
| 8179 | "GET / HTTP/1.1\r\n" |
| 8180 | "Host: www.example.org\r\n" |
| 8181 | "Connection: keep-alive\r\n" |
| 8182 | "referer: www.foo.com\r\n" |
| 8183 | "hEllo: Kitty\r\n" |
| 8184 | "FoO: bar\r\n\r\n"), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8185 | }; |
| 8186 | |
| 8187 | // Lastly, the server responds with the actual content. |
| 8188 | MockRead data_reads[] = { |
| 8189 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8190 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8191 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8192 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8193 | }; |
| 8194 | |
| 8195 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8196 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8197 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8198 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8199 | TestCompletionCallback callback; |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8200 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8201 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8202 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8203 | |
| 8204 | rv = callback.WaitForResult(); |
| 8205 | EXPECT_EQ(OK, rv); |
| 8206 | } |
| 8207 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8208 | TEST_P(HttpNetworkTransactionTest, SOCKS4_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8209 | HttpRequestInfo request; |
| 8210 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8211 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8212 | request.load_flags = 0; |
| 8213 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8214 | session_deps_.proxy_service = |
| 8215 | ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8216 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8217 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8218 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8219 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8220 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8221 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8222 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8223 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 8224 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 8225 | |
| 8226 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8227 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
| 8228 | MockWrite( |
| 8229 | "GET / HTTP/1.1\r\n" |
| 8230 | "Host: www.example.org\r\n" |
| 8231 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8232 | |
| 8233 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8234 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8235 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8236 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 8237 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8238 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8239 | }; |
| 8240 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8241 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8242 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8243 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8244 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8245 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8246 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8247 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8248 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8249 | |
| 8250 | rv = callback.WaitForResult(); |
| 8251 | EXPECT_EQ(OK, rv); |
| 8252 | |
| 8253 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8254 | ASSERT_TRUE(response != NULL); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8255 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8256 | LoadTimingInfo load_timing_info; |
| 8257 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 8258 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8259 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 8260 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8261 | std::string response_text; |
| 8262 | rv = ReadTransaction(trans.get(), &response_text); |
| 8263 | EXPECT_EQ(OK, rv); |
| 8264 | EXPECT_EQ("Payload", response_text); |
| 8265 | } |
| 8266 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8267 | TEST_P(HttpNetworkTransactionTest, SOCKS4_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8268 | HttpRequestInfo request; |
| 8269 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8270 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8271 | request.load_flags = 0; |
| 8272 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8273 | session_deps_.proxy_service = |
| 8274 | ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8275 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8276 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8277 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8278 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8279 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8280 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8281 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8282 | unsigned char write_buffer[] = { 0x04, 0x01, 0x01, 0xBB, 127, 0, 0, 1, 0 }; |
| 8283 | unsigned char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 8284 | |
| 8285 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8286 | MockWrite(ASYNC, reinterpret_cast<char*>(write_buffer), |
| 8287 | arraysize(write_buffer)), |
| 8288 | MockWrite( |
| 8289 | "GET / HTTP/1.1\r\n" |
| 8290 | "Host: www.example.org\r\n" |
| 8291 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8292 | |
| 8293 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 8294 | MockRead(ASYNC, reinterpret_cast<char*>(read_buffer), |
| 8295 | arraysize(read_buffer)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8296 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8297 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 8298 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8299 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8300 | }; |
| 8301 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8302 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8303 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8304 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8305 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8306 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8307 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8308 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8309 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8310 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8311 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8312 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8313 | |
| 8314 | rv = callback.WaitForResult(); |
| 8315 | EXPECT_EQ(OK, rv); |
| 8316 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8317 | LoadTimingInfo load_timing_info; |
| 8318 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 8319 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8320 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 8321 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8322 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8323 | ASSERT_TRUE(response != NULL); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8324 | |
| 8325 | std::string response_text; |
| 8326 | rv = ReadTransaction(trans.get(), &response_text); |
| 8327 | EXPECT_EQ(OK, rv); |
| 8328 | EXPECT_EQ("Payload", response_text); |
| 8329 | } |
| 8330 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8331 | TEST_P(HttpNetworkTransactionTest, SOCKS4_HTTP_GET_no_PAC) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8332 | HttpRequestInfo request; |
| 8333 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8334 | request.url = GURL("http://www.example.org/"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8335 | request.load_flags = 0; |
| 8336 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8337 | session_deps_.proxy_service = |
| 8338 | ProxyService::CreateFixed("socks4://myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8339 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8340 | session_deps_.net_log = &net_log; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8341 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8342 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8343 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8344 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8345 | |
| 8346 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 8347 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 8348 | |
| 8349 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8350 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
| 8351 | MockWrite( |
| 8352 | "GET / HTTP/1.1\r\n" |
| 8353 | "Host: www.example.org\r\n" |
| 8354 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8355 | |
| 8356 | MockRead data_reads[] = { |
| 8357 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
| 8358 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8359 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 8360 | MockRead("Payload"), |
| 8361 | MockRead(SYNCHRONOUS, OK) |
| 8362 | }; |
| 8363 | |
| 8364 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8365 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8366 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8367 | |
| 8368 | TestCompletionCallback callback; |
| 8369 | |
| 8370 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 8371 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8372 | |
| 8373 | rv = callback.WaitForResult(); |
| 8374 | EXPECT_EQ(OK, rv); |
| 8375 | |
| 8376 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8377 | ASSERT_TRUE(response != NULL); |
| 8378 | |
| 8379 | LoadTimingInfo load_timing_info; |
| 8380 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 8381 | TestLoadTimingNotReused(load_timing_info, |
| 8382 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 8383 | |
| 8384 | std::string response_text; |
| 8385 | rv = ReadTransaction(trans.get(), &response_text); |
| 8386 | EXPECT_EQ(OK, rv); |
| 8387 | EXPECT_EQ("Payload", response_text); |
| 8388 | } |
| 8389 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8390 | TEST_P(HttpNetworkTransactionTest, SOCKS5_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8391 | HttpRequestInfo request; |
| 8392 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8393 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8394 | request.load_flags = 0; |
| 8395 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8396 | session_deps_.proxy_service = |
| 8397 | ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8398 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8399 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8400 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8401 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8402 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8403 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8404 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8405 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 8406 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 8407 | const char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8408 | 0x05, // Version |
| 8409 | 0x01, // Command (CONNECT) |
| 8410 | 0x00, // Reserved. |
| 8411 | 0x03, // Address type (DOMAINNAME). |
| 8412 | 0x0F, // Length of domain (15) |
| 8413 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 8414 | '.', 'o', 'r', 'g', 0x00, 0x50, // 16-bit port (80) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 8415 | }; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8416 | const char kSOCKS5OkResponse[] = |
| 8417 | { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; |
| 8418 | |
| 8419 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8420 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 8421 | MockWrite(ASYNC, kSOCKS5OkRequest, arraysize(kSOCKS5OkRequest)), |
| 8422 | MockWrite( |
| 8423 | "GET / HTTP/1.1\r\n" |
| 8424 | "Host: www.example.org\r\n" |
| 8425 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8426 | |
| 8427 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 8428 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 8429 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8430 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8431 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 8432 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8433 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8434 | }; |
| 8435 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8436 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8437 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8438 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8439 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8440 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8441 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8442 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8443 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8444 | |
| 8445 | rv = callback.WaitForResult(); |
| 8446 | EXPECT_EQ(OK, rv); |
| 8447 | |
| 8448 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8449 | ASSERT_TRUE(response != NULL); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8450 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8451 | LoadTimingInfo load_timing_info; |
| 8452 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 8453 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8454 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 8455 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8456 | std::string response_text; |
| 8457 | rv = ReadTransaction(trans.get(), &response_text); |
| 8458 | EXPECT_EQ(OK, rv); |
| 8459 | EXPECT_EQ("Payload", response_text); |
| 8460 | } |
| 8461 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8462 | TEST_P(HttpNetworkTransactionTest, SOCKS5_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8463 | HttpRequestInfo request; |
| 8464 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8465 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8466 | request.load_flags = 0; |
| 8467 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8468 | session_deps_.proxy_service = |
| 8469 | ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8470 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8471 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8472 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8473 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8474 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8475 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8476 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8477 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 8478 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 8479 | const unsigned char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8480 | 0x05, // Version |
| 8481 | 0x01, // Command (CONNECT) |
| 8482 | 0x00, // Reserved. |
| 8483 | 0x03, // Address type (DOMAINNAME). |
| 8484 | 0x0F, // Length of domain (15) |
| 8485 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 8486 | '.', 'o', 'r', 'g', 0x01, 0xBB, // 16-bit port (443) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 8487 | }; |
| 8488 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8489 | const char kSOCKS5OkResponse[] = |
| 8490 | { 0x05, 0x00, 0x00, 0x01, 0, 0, 0, 0, 0x00, 0x00 }; |
| 8491 | |
| 8492 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8493 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 8494 | MockWrite(ASYNC, reinterpret_cast<const char*>(kSOCKS5OkRequest), |
| 8495 | arraysize(kSOCKS5OkRequest)), |
| 8496 | MockWrite( |
| 8497 | "GET / HTTP/1.1\r\n" |
| 8498 | "Host: www.example.org\r\n" |
| 8499 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8500 | |
| 8501 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 8502 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 8503 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8504 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8505 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 8506 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8507 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8508 | }; |
| 8509 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8510 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8511 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8512 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8513 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8514 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8515 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8516 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8517 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8518 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8519 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8520 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8521 | |
| 8522 | rv = callback.WaitForResult(); |
| 8523 | EXPECT_EQ(OK, rv); |
| 8524 | |
| 8525 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8526 | ASSERT_TRUE(response != NULL); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8527 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8528 | LoadTimingInfo load_timing_info; |
| 8529 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 8530 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8531 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 8532 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8533 | std::string response_text; |
| 8534 | rv = ReadTransaction(trans.get(), &response_text); |
| 8535 | EXPECT_EQ(OK, rv); |
| 8536 | EXPECT_EQ("Payload", response_text); |
| 8537 | } |
| 8538 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 8539 | namespace { |
| 8540 | |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 8541 | // Tests that for connection endpoints the group names are correctly set. |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8542 | |
| 8543 | struct GroupNameTest { |
| 8544 | std::string proxy_server; |
| 8545 | std::string url; |
| 8546 | std::string expected_group_name; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 8547 | bool ssl; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8548 | }; |
| 8549 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8550 | scoped_ptr<HttpNetworkSession> SetupSessionForGroupNameTests( |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8551 | NextProto next_proto, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8552 | SpdySessionDependencies* session_deps_) { |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8553 | scoped_ptr<HttpNetworkSession> session(CreateSession(session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8554 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 8555 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8556 | session->http_server_properties(); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 8557 | AlternativeService alternative_service( |
bnc | 4988e43 | 2015-03-31 03:06:25 | [diff] [blame] | 8558 | AlternateProtocolFromNextProto(next_proto), "", 443); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 8559 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 8560 | http_server_properties->SetAlternativeService( |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 8561 | HostPortPair("host.with.alternate", 80), alternative_service, 1.0, |
| 8562 | expiration); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8563 | |
| 8564 | return session; |
| 8565 | } |
| 8566 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8567 | int GroupNameTransactionHelper(const std::string& url, |
| 8568 | HttpNetworkSession* session) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8569 | HttpRequestInfo request; |
| 8570 | request.method = "GET"; |
| 8571 | request.url = GURL(url); |
| 8572 | request.load_flags = 0; |
| 8573 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8574 | scoped_ptr<HttpTransaction> trans( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8575 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8576 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8577 | TestCompletionCallback callback; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8578 | |
| 8579 | // We do not complete this request, the dtor will clean the transaction up. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8580 | return trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8581 | } |
| 8582 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 8583 | } // namespace |
| 8584 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8585 | TEST_P(HttpNetworkTransactionTest, GroupNameForDirectConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8586 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8587 | { |
| 8588 | "", // unused |
| 8589 | "http://www.example.org/direct", |
| 8590 | "www.example.org:80", |
| 8591 | false, |
| 8592 | }, |
| 8593 | { |
| 8594 | "", // unused |
| 8595 | "http://[2001:1418:13:1::25]/direct", |
| 8596 | "[2001:1418:13:1::25]:80", |
| 8597 | false, |
| 8598 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 8599 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8600 | // SSL Tests |
| 8601 | { |
| 8602 | "", // unused |
| 8603 | "https://www.example.org/direct_ssl", |
| 8604 | "ssl/www.example.org:443", |
| 8605 | true, |
| 8606 | }, |
| 8607 | { |
| 8608 | "", // unused |
| 8609 | "https://[2001:1418:13:1::25]/direct", |
| 8610 | "ssl/[2001:1418:13:1::25]:443", |
| 8611 | true, |
| 8612 | }, |
| 8613 | { |
| 8614 | "", // unused |
| 8615 | "http://host.with.alternate/direct", |
| 8616 | "ssl/host.with.alternate:443", |
| 8617 | true, |
| 8618 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8619 | }; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8620 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 8621 | session_deps_.use_alternative_services = true; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8622 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 8623 | for (size_t i = 0; i < arraysize(tests); ++i) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8624 | session_deps_.proxy_service = |
| 8625 | ProxyService::CreateFixed(tests[i].proxy_server); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8626 | scoped_ptr<HttpNetworkSession> session( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 8627 | SetupSessionForGroupNameTests(GetProtocol(), &session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8628 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8629 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 8630 | CaptureGroupNameTransportSocketPool* transport_conn_pool = |
| 8631 | new CaptureGroupNameTransportSocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 8632 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 8633 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 8634 | scoped_ptr<MockClientSocketPoolManager> mock_pool_manager( |
| 8635 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 8636 | mock_pool_manager->SetTransportSocketPool(transport_conn_pool); |
| 8637 | mock_pool_manager->SetSSLSocketPool(ssl_conn_pool); |
dcheng | e3d1ddc | 2014-10-15 19:30:51 | [diff] [blame] | 8638 | peer.SetClientSocketPoolManager(mock_pool_manager.Pass()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8639 | |
| 8640 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8641 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 8642 | if (tests[i].ssl) |
| 8643 | EXPECT_EQ(tests[i].expected_group_name, |
| 8644 | ssl_conn_pool->last_group_name_received()); |
| 8645 | else |
| 8646 | EXPECT_EQ(tests[i].expected_group_name, |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 8647 | transport_conn_pool->last_group_name_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8648 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8649 | } |
| 8650 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8651 | TEST_P(HttpNetworkTransactionTest, GroupNameForHTTPProxyConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8652 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8653 | { |
| 8654 | "http_proxy", |
| 8655 | "http://www.example.org/http_proxy_normal", |
| 8656 | "www.example.org:80", |
| 8657 | false, |
| 8658 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8659 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8660 | // SSL Tests |
| 8661 | { |
| 8662 | "http_proxy", |
| 8663 | "https://www.example.org/http_connect_ssl", |
| 8664 | "ssl/www.example.org:443", |
| 8665 | true, |
| 8666 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 8667 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8668 | { |
| 8669 | "http_proxy", |
| 8670 | "http://host.with.alternate/direct", |
| 8671 | "ssl/host.with.alternate:443", |
| 8672 | true, |
| 8673 | }, |
[email protected] | 4549925 | 2013-01-23 17:12:56 | [diff] [blame] | 8674 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8675 | { |
| 8676 | "http_proxy", |
| 8677 | "ftp://ftp.google.com/http_proxy_normal", |
| 8678 | "ftp/ftp.google.com:21", |
| 8679 | false, |
| 8680 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8681 | }; |
| 8682 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 8683 | session_deps_.use_alternative_services = true; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8684 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 8685 | for (size_t i = 0; i < arraysize(tests); ++i) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8686 | session_deps_.proxy_service = |
| 8687 | ProxyService::CreateFixed(tests[i].proxy_server); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8688 | scoped_ptr<HttpNetworkSession> session( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 8689 | SetupSessionForGroupNameTests(GetProtocol(), &session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8690 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8691 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8692 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 8693 | HostPortPair proxy_host("http_proxy", 80); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 8694 | CaptureGroupNameHttpProxySocketPool* http_proxy_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 8695 | new CaptureGroupNameHttpProxySocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 8696 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 8697 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 8698 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 8699 | scoped_ptr<MockClientSocketPoolManager> mock_pool_manager( |
| 8700 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 8701 | mock_pool_manager->SetSocketPoolForHTTPProxy(proxy_host, http_proxy_pool); |
| 8702 | mock_pool_manager->SetSocketPoolForSSLWithProxy(proxy_host, ssl_conn_pool); |
dcheng | e3d1ddc | 2014-10-15 19:30:51 | [diff] [blame] | 8703 | peer.SetClientSocketPoolManager(mock_pool_manager.Pass()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8704 | |
| 8705 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8706 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 8707 | if (tests[i].ssl) |
| 8708 | EXPECT_EQ(tests[i].expected_group_name, |
| 8709 | ssl_conn_pool->last_group_name_received()); |
| 8710 | else |
| 8711 | EXPECT_EQ(tests[i].expected_group_name, |
| 8712 | http_proxy_pool->last_group_name_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8713 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8714 | } |
| 8715 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8716 | TEST_P(HttpNetworkTransactionTest, GroupNameForSOCKSConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8717 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8718 | { |
| 8719 | "socks4://socks_proxy:1080", |
| 8720 | "http://www.example.org/socks4_direct", |
| 8721 | "socks4/www.example.org:80", |
| 8722 | false, |
| 8723 | }, |
| 8724 | { |
| 8725 | "socks5://socks_proxy:1080", |
| 8726 | "http://www.example.org/socks5_direct", |
| 8727 | "socks5/www.example.org:80", |
| 8728 | false, |
| 8729 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8730 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8731 | // SSL Tests |
| 8732 | { |
| 8733 | "socks4://socks_proxy:1080", |
| 8734 | "https://www.example.org/socks4_ssl", |
| 8735 | "socks4/ssl/www.example.org:443", |
| 8736 | true, |
| 8737 | }, |
| 8738 | { |
| 8739 | "socks5://socks_proxy:1080", |
| 8740 | "https://www.example.org/socks5_ssl", |
| 8741 | "socks5/ssl/www.example.org:443", |
| 8742 | true, |
| 8743 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 8744 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8745 | { |
| 8746 | "socks4://socks_proxy:1080", |
| 8747 | "http://host.with.alternate/direct", |
| 8748 | "socks4/ssl/host.with.alternate:443", |
| 8749 | true, |
| 8750 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 8751 | }; |
| 8752 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 8753 | session_deps_.use_alternative_services = true; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8754 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 8755 | for (size_t i = 0; i < arraysize(tests); ++i) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8756 | session_deps_.proxy_service = |
| 8757 | ProxyService::CreateFixed(tests[i].proxy_server); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8758 | scoped_ptr<HttpNetworkSession> session( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 8759 | SetupSessionForGroupNameTests(GetProtocol(), &session_deps_)); |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 8760 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8761 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 8762 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 8763 | HostPortPair proxy_host("socks_proxy", 1080); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 8764 | CaptureGroupNameSOCKSSocketPool* socks_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 8765 | new CaptureGroupNameSOCKSSocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 8766 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 8767 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 8768 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 8769 | scoped_ptr<MockClientSocketPoolManager> mock_pool_manager( |
| 8770 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 8771 | mock_pool_manager->SetSocketPoolForSOCKSProxy(proxy_host, socks_conn_pool); |
| 8772 | mock_pool_manager->SetSocketPoolForSSLWithProxy(proxy_host, ssl_conn_pool); |
dcheng | e3d1ddc | 2014-10-15 19:30:51 | [diff] [blame] | 8773 | peer.SetClientSocketPoolManager(mock_pool_manager.Pass()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 8774 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8775 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8776 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 8777 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8778 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8779 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 8780 | if (tests[i].ssl) |
| 8781 | EXPECT_EQ(tests[i].expected_group_name, |
| 8782 | ssl_conn_pool->last_group_name_received()); |
| 8783 | else |
| 8784 | EXPECT_EQ(tests[i].expected_group_name, |
| 8785 | socks_conn_pool->last_group_name_received()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 8786 | } |
| 8787 | } |
| 8788 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8789 | TEST_P(HttpNetworkTransactionTest, ReconsiderProxyAfterFailedConnection) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8790 | HttpRequestInfo request; |
| 8791 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8792 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8793 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8794 | session_deps_.proxy_service = |
| 8795 | ProxyService::CreateFixed("myproxy:70;foobar:80"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 8796 | |
[email protected] | 6971906 | 2010-01-05 20:09:21 | [diff] [blame] | 8797 | // This simulates failure resolving all hostnames; that means we will fail |
| 8798 | // connecting to both proxies (myproxy:70 and foobar:80). |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8799 | session_deps_.host_resolver->rules()->AddSimulatedFailure("*"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 8800 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8801 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 8802 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8803 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 8804 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8805 | TestCompletionCallback callback; |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 8806 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8807 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 8808 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8809 | |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 8810 | rv = callback.WaitForResult(); |
[email protected] | f7fccee | 2010-09-16 20:53:01 | [diff] [blame] | 8811 | EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, rv); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 8812 | } |
| 8813 | |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 8814 | // Base test to make sure that when the load flags for a request specify to |
| 8815 | // bypass the cache, the DNS cache is not used. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8816 | void HttpNetworkTransactionTest::BypassHostCacheOnRefreshHelper( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8817 | int load_flags) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8818 | // Issue a request, asking to bypass the cache(s). |
| 8819 | HttpRequestInfo request; |
| 8820 | request.method = "GET"; |
| 8821 | request.load_flags = load_flags; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8822 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8823 | |
[email protected] | a2c2fb9 | 2009-07-18 07:31:04 | [diff] [blame] | 8824 | // Select a host resolver that does caching. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8825 | session_deps_.host_resolver.reset(new MockCachingHostResolver); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 8826 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8827 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8828 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8829 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8830 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8831 | // 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] | 8832 | AddressList addrlist; |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 8833 | TestCompletionCallback callback; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8834 | int rv = session_deps_.host_resolver->Resolve( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8835 | HostResolver::RequestInfo(HostPortPair("www.example.org", 80)), |
| 8836 | DEFAULT_PRIORITY, &addrlist, callback.callback(), NULL, BoundNetLog()); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 8837 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8838 | rv = callback.WaitForResult(); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8839 | EXPECT_EQ(OK, rv); |
| 8840 | |
| 8841 | // Verify that it was added to host cache, by doing a subsequent async lookup |
| 8842 | // and confirming it completes synchronously. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8843 | rv = session_deps_.host_resolver->Resolve( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8844 | HostResolver::RequestInfo(HostPortPair("www.example.org", 80)), |
| 8845 | DEFAULT_PRIORITY, &addrlist, callback.callback(), NULL, BoundNetLog()); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 8846 | ASSERT_EQ(OK, rv); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8847 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8848 | // 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] | 8849 | // we can tell if the next lookup hit the cache, or the "network". |
| 8850 | // (cache --> success, "network" --> failure). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8851 | session_deps_.host_resolver->rules()->AddSimulatedFailure("www.example.org"); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8852 | |
| 8853 | // Connect up a mock socket which will fail with ERR_UNEXPECTED during the |
| 8854 | // 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] | 8855 | MockRead data_reads[] = { MockRead(SYNCHRONOUS, ERR_UNEXPECTED) }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8856 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8857 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8858 | |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8859 | // Run the request. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8860 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8861 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8862 | rv = callback.WaitForResult(); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8863 | |
| 8864 | // If we bypassed the cache, we would have gotten a failure while resolving |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8865 | // "www.example.org". |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8866 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, rv); |
| 8867 | } |
| 8868 | |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 8869 | // There are multiple load flags that should trigger the host cache bypass. |
| 8870 | // Test each in isolation: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8871 | TEST_P(HttpNetworkTransactionTest, BypassHostCacheOnRefresh1) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 8872 | BypassHostCacheOnRefreshHelper(LOAD_BYPASS_CACHE); |
| 8873 | } |
| 8874 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8875 | TEST_P(HttpNetworkTransactionTest, BypassHostCacheOnRefresh2) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 8876 | BypassHostCacheOnRefreshHelper(LOAD_VALIDATE_CACHE); |
| 8877 | } |
| 8878 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8879 | TEST_P(HttpNetworkTransactionTest, BypassHostCacheOnRefresh3) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 8880 | BypassHostCacheOnRefreshHelper(LOAD_DISABLE_CACHE); |
| 8881 | } |
| 8882 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8883 | // Make sure we can handle an error when writing the request. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8884 | TEST_P(HttpNetworkTransactionTest, RequestWriteError) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8885 | HttpRequestInfo request; |
| 8886 | request.method = "GET"; |
| 8887 | request.url = GURL("http://www.foo.com/"); |
| 8888 | request.load_flags = 0; |
| 8889 | |
| 8890 | MockWrite write_failure[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8891 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8892 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8893 | StaticSocketDataProvider data(NULL, 0, |
| 8894 | write_failure, arraysize(write_failure)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8895 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8896 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8897 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8898 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8899 | |
| 8900 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8901 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8902 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8903 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8904 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8905 | |
| 8906 | rv = callback.WaitForResult(); |
| 8907 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 8908 | |
| 8909 | IPEndPoint endpoint; |
| 8910 | EXPECT_TRUE(trans->GetRemoteEndpoint(&endpoint)); |
| 8911 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8912 | } |
| 8913 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 8914 | // Check that a connection closed after the start of the headers finishes ok. |
| 8915 | TEST_P(HttpNetworkTransactionTest, ConnectionClosedAfterStartOfHeaders) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8916 | HttpRequestInfo request; |
| 8917 | request.method = "GET"; |
| 8918 | request.url = GURL("http://www.foo.com/"); |
| 8919 | request.load_flags = 0; |
| 8920 | |
| 8921 | MockRead data_reads[] = { |
| 8922 | MockRead("HTTP/1."), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8923 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8924 | }; |
| 8925 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8926 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8927 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8928 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8929 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8930 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8931 | |
| 8932 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8933 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8934 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8935 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8936 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8937 | |
| 8938 | rv = callback.WaitForResult(); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 8939 | EXPECT_EQ(OK, rv); |
| 8940 | |
| 8941 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8942 | ASSERT_TRUE(response != NULL); |
| 8943 | |
| 8944 | EXPECT_TRUE(response->headers.get() != NULL); |
| 8945 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 8946 | |
| 8947 | std::string response_data; |
| 8948 | rv = ReadTransaction(trans.get(), &response_data); |
| 8949 | EXPECT_EQ(OK, rv); |
| 8950 | EXPECT_EQ("", response_data); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 8951 | |
| 8952 | IPEndPoint endpoint; |
| 8953 | EXPECT_TRUE(trans->GetRemoteEndpoint(&endpoint)); |
| 8954 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8955 | } |
| 8956 | |
| 8957 | // Make sure that a dropped connection while draining the body for auth |
| 8958 | // restart does the right thing. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8959 | TEST_P(HttpNetworkTransactionTest, DrainResetOK) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8960 | HttpRequestInfo request; |
| 8961 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8962 | request.url = GURL("http://www.example.org/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8963 | request.load_flags = 0; |
| 8964 | |
| 8965 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8966 | MockWrite( |
| 8967 | "GET / HTTP/1.1\r\n" |
| 8968 | "Host: www.example.org\r\n" |
| 8969 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8970 | }; |
| 8971 | |
| 8972 | MockRead data_reads1[] = { |
| 8973 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 8974 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8975 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8976 | MockRead("Content-Length: 14\r\n\r\n"), |
| 8977 | MockRead("Unauth"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8978 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8979 | }; |
| 8980 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8981 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 8982 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8983 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8984 | |
| 8985 | // After calling trans->RestartWithAuth(), this is the request we should |
| 8986 | // be issuing -- the final header line contains the credentials. |
| 8987 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8988 | MockWrite( |
| 8989 | "GET / HTTP/1.1\r\n" |
| 8990 | "Host: www.example.org\r\n" |
| 8991 | "Connection: keep-alive\r\n" |
| 8992 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8993 | }; |
| 8994 | |
| 8995 | // Lastly, the server responds with the actual content. |
| 8996 | MockRead data_reads2[] = { |
| 8997 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 8998 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8999 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9000 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9001 | }; |
| 9002 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9003 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 9004 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9005 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9006 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9007 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9008 | TestCompletionCallback callback1; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9009 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9010 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9011 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 9012 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9013 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9014 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9015 | |
| 9016 | rv = callback1.WaitForResult(); |
| 9017 | EXPECT_EQ(OK, rv); |
| 9018 | |
| 9019 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 9020 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9021 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9022 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9023 | TestCompletionCallback callback2; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9024 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9025 | rv = trans->RestartWithAuth( |
| 9026 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9027 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9028 | |
| 9029 | rv = callback2.WaitForResult(); |
| 9030 | EXPECT_EQ(OK, rv); |
| 9031 | |
| 9032 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 9033 | ASSERT_TRUE(response != NULL); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9034 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 9035 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9036 | } |
| 9037 | |
| 9038 | // Test HTTPS connections going through a proxy that sends extra data. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9039 | TEST_P(HttpNetworkTransactionTest, HTTPSViaProxyWithExtraData) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9040 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9041 | |
| 9042 | HttpRequestInfo request; |
| 9043 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9044 | request.url = GURL("https://www.example.org/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9045 | request.load_flags = 0; |
| 9046 | |
| 9047 | MockRead proxy_reads[] = { |
| 9048 | MockRead("HTTP/1.0 200 Connected\r\n\r\nExtra data"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9049 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9050 | }; |
| 9051 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9052 | StaticSocketDataProvider data(proxy_reads, arraysize(proxy_reads), NULL, 0); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9053 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9054 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9055 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9056 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9057 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9058 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9059 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9060 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9061 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9062 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9063 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 9064 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9065 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9066 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9067 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9068 | |
| 9069 | rv = callback.WaitForResult(); |
| 9070 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
| 9071 | } |
| 9072 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9073 | TEST_P(HttpNetworkTransactionTest, LargeContentLengthThenClose) { |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9074 | HttpRequestInfo request; |
| 9075 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9076 | request.url = GURL("http://www.example.org/"); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9077 | request.load_flags = 0; |
| 9078 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9079 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9080 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 9081 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9082 | |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 9083 | MockRead data_reads[] = { |
| 9084 | 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] | 9085 | MockRead(SYNCHRONOUS, OK), |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 9086 | }; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9087 | |
| 9088 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9089 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9090 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9091 | TestCompletionCallback callback; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9092 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9093 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9094 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9095 | |
| 9096 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9097 | |
| 9098 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 9099 | ASSERT_TRUE(response != NULL); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9100 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9101 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9102 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 9103 | |
| 9104 | std::string response_data; |
| 9105 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 5543cbb | 2012-04-20 16:35:23 | [diff] [blame] | 9106 | EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, rv); |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 9107 | } |
| 9108 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9109 | TEST_P(HttpNetworkTransactionTest, UploadFileSmallerThanLength) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 9110 | base::FilePath temp_file_path; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 9111 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file_path)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9112 | const uint64 kFakeSize = 100000; // file is actually blank |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 9113 | UploadFileElementReader::ScopedOverridingContentLengthForTests |
| 9114 | overriding_content_length(kFakeSize); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9115 | |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 9116 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 9117 | element_readers.push_back(make_scoped_ptr(new UploadFileElementReader( |
| 9118 | base::ThreadTaskRunnerHandle::Get().get(), temp_file_path, 0, kuint64max, |
| 9119 | base::Time()))); |
| 9120 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9121 | |
| 9122 | HttpRequestInfo request; |
| 9123 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9124 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9125 | request.upload_data_stream = &upload_data_stream; |
| 9126 | request.load_flags = 0; |
| 9127 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9128 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9129 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 9130 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9131 | |
| 9132 | MockRead data_reads[] = { |
| 9133 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 9134 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9135 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9136 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9137 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9138 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9139 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9140 | TestCompletionCallback callback; |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9141 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9142 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9143 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9144 | |
| 9145 | rv = callback.WaitForResult(); |
| 9146 | EXPECT_EQ(OK, rv); |
| 9147 | |
| 9148 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 9149 | ASSERT_TRUE(response != NULL); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9150 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9151 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9152 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 9153 | |
| 9154 | std::string response_data; |
| 9155 | rv = ReadTransaction(trans.get(), &response_data); |
| 9156 | EXPECT_EQ(OK, rv); |
| 9157 | EXPECT_EQ("hello world", response_data); |
| 9158 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 9159 | base::DeleteFile(temp_file_path, false); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9160 | } |
| 9161 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9162 | TEST_P(HttpNetworkTransactionTest, UploadUnreadableFile) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 9163 | base::FilePath temp_file; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 9164 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9165 | std::string temp_file_content("Unreadable file."); |
[email protected] | e5c2a22e | 2014-03-06 20:42:30 | [diff] [blame] | 9166 | ASSERT_TRUE(base::WriteFile(temp_file, temp_file_content.c_str(), |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9167 | temp_file_content.length())); |
[email protected] | 92be8eb | 2014-08-07 22:57:11 | [diff] [blame] | 9168 | ASSERT_TRUE(base::MakeFileUnreadable(temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9169 | |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 9170 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 9171 | element_readers.push_back(make_scoped_ptr( |
skyostil | 4891b25b | 2015-06-11 11:43:45 | [diff] [blame] | 9172 | new UploadFileElementReader(base::ThreadTaskRunnerHandle::Get().get(), |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 9173 | temp_file, 0, kuint64max, base::Time()))); |
| 9174 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9175 | |
| 9176 | HttpRequestInfo request; |
| 9177 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9178 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9179 | request.upload_data_stream = &upload_data_stream; |
| 9180 | request.load_flags = 0; |
| 9181 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 9182 | // If we try to upload an unreadable file, the transaction should fail. |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9183 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9184 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 9185 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9186 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 9187 | StaticSocketDataProvider data(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9188 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9189 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9190 | TestCompletionCallback callback; |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9191 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9192 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9193 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9194 | |
| 9195 | rv = callback.WaitForResult(); |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 9196 | EXPECT_EQ(ERR_ACCESS_DENIED, rv); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9197 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 9198 | base::DeleteFile(temp_file, false); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9199 | } |
| 9200 | |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9201 | TEST_P(HttpNetworkTransactionTest, CancelDuringInitRequestBody) { |
| 9202 | class FakeUploadElementReader : public UploadElementReader { |
| 9203 | public: |
| 9204 | FakeUploadElementReader() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9205 | ~FakeUploadElementReader() override {} |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9206 | |
| 9207 | const CompletionCallback& callback() const { return callback_; } |
| 9208 | |
| 9209 | // UploadElementReader overrides: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9210 | int Init(const CompletionCallback& callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9211 | callback_ = callback; |
| 9212 | return ERR_IO_PENDING; |
| 9213 | } |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9214 | uint64 GetContentLength() const override { return 0; } |
| 9215 | uint64 BytesRemaining() const override { return 0; } |
| 9216 | int Read(IOBuffer* buf, |
| 9217 | int buf_length, |
| 9218 | const CompletionCallback& callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9219 | return ERR_FAILED; |
| 9220 | } |
| 9221 | |
| 9222 | private: |
| 9223 | CompletionCallback callback_; |
| 9224 | }; |
| 9225 | |
| 9226 | FakeUploadElementReader* fake_reader = new FakeUploadElementReader; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 9227 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 9228 | element_readers.push_back(make_scoped_ptr(fake_reader)); |
| 9229 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9230 | |
| 9231 | HttpRequestInfo request; |
| 9232 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9233 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9234 | request.upload_data_stream = &upload_data_stream; |
| 9235 | request.load_flags = 0; |
| 9236 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9237 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9238 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 9239 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9240 | |
| 9241 | StaticSocketDataProvider data; |
| 9242 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9243 | |
| 9244 | TestCompletionCallback callback; |
| 9245 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 9246 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9247 | base::MessageLoop::current()->RunUntilIdle(); |
| 9248 | |
| 9249 | // Transaction is pending on request body initialization. |
| 9250 | ASSERT_FALSE(fake_reader->callback().is_null()); |
| 9251 | |
| 9252 | // Return Init()'s result after the transaction gets destroyed. |
| 9253 | trans.reset(); |
| 9254 | fake_reader->callback().Run(OK); // Should not crash. |
| 9255 | } |
| 9256 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9257 | // Tests that changes to Auth realms are treated like auth rejections. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9258 | TEST_P(HttpNetworkTransactionTest, ChangeAuthRealms) { |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9259 | HttpRequestInfo request; |
| 9260 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9261 | request.url = GURL("http://www.example.org/"); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9262 | request.load_flags = 0; |
| 9263 | |
| 9264 | // First transaction will request a resource and receive a Basic challenge |
| 9265 | // with realm="first_realm". |
| 9266 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9267 | MockWrite( |
| 9268 | "GET / HTTP/1.1\r\n" |
| 9269 | "Host: www.example.org\r\n" |
| 9270 | "Connection: keep-alive\r\n" |
| 9271 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9272 | }; |
| 9273 | MockRead data_reads1[] = { |
| 9274 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 9275 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 9276 | "\r\n"), |
| 9277 | }; |
| 9278 | |
| 9279 | // After calling trans->RestartWithAuth(), provide an Authentication header |
| 9280 | // for first_realm. The server will reject and provide a challenge with |
| 9281 | // second_realm. |
| 9282 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9283 | MockWrite( |
| 9284 | "GET / HTTP/1.1\r\n" |
| 9285 | "Host: www.example.org\r\n" |
| 9286 | "Connection: keep-alive\r\n" |
| 9287 | "Authorization: Basic Zmlyc3Q6YmF6\r\n" |
| 9288 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9289 | }; |
| 9290 | MockRead data_reads2[] = { |
| 9291 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 9292 | "WWW-Authenticate: Basic realm=\"second_realm\"\r\n" |
| 9293 | "\r\n"), |
| 9294 | }; |
| 9295 | |
| 9296 | // This again fails, and goes back to first_realm. Make sure that the |
| 9297 | // entry is removed from cache. |
| 9298 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9299 | MockWrite( |
| 9300 | "GET / HTTP/1.1\r\n" |
| 9301 | "Host: www.example.org\r\n" |
| 9302 | "Connection: keep-alive\r\n" |
| 9303 | "Authorization: Basic c2Vjb25kOmZvdQ==\r\n" |
| 9304 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9305 | }; |
| 9306 | MockRead data_reads3[] = { |
| 9307 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 9308 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 9309 | "\r\n"), |
| 9310 | }; |
| 9311 | |
| 9312 | // Try one last time (with the correct password) and get the resource. |
| 9313 | MockWrite data_writes4[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9314 | MockWrite( |
| 9315 | "GET / HTTP/1.1\r\n" |
| 9316 | "Host: www.example.org\r\n" |
| 9317 | "Connection: keep-alive\r\n" |
| 9318 | "Authorization: Basic Zmlyc3Q6YmFy\r\n" |
| 9319 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9320 | }; |
| 9321 | MockRead data_reads4[] = { |
| 9322 | MockRead("HTTP/1.1 200 OK\r\n" |
| 9323 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 9324 | "Content-Length: 5\r\n" |
| 9325 | "\r\n" |
| 9326 | "hello"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9327 | }; |
| 9328 | |
| 9329 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 9330 | data_writes1, arraysize(data_writes1)); |
| 9331 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 9332 | data_writes2, arraysize(data_writes2)); |
| 9333 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 9334 | data_writes3, arraysize(data_writes3)); |
| 9335 | StaticSocketDataProvider data4(data_reads4, arraysize(data_reads4), |
| 9336 | data_writes4, arraysize(data_writes4)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9337 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 9338 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 9339 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 9340 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9341 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9342 | TestCompletionCallback callback1; |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9343 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9344 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 9345 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 9346 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 9347 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9348 | // Issue the first request with Authorize headers. There should be a |
| 9349 | // password prompt for first_realm waiting to be filled in after the |
| 9350 | // transaction completes. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9351 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9352 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9353 | rv = callback1.WaitForResult(); |
| 9354 | EXPECT_EQ(OK, rv); |
| 9355 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 9356 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9357 | const AuthChallengeInfo* challenge = response->auth_challenge.get(); |
| 9358 | ASSERT_FALSE(challenge == NULL); |
| 9359 | EXPECT_FALSE(challenge->is_proxy); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9360 | EXPECT_EQ("www.example.org:80", challenge->challenger.ToString()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9361 | EXPECT_EQ("first_realm", challenge->realm); |
| 9362 | EXPECT_EQ("basic", challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9363 | |
| 9364 | // Issue the second request with an incorrect password. There should be a |
| 9365 | // password prompt for second_realm waiting to be filled in after the |
| 9366 | // transaction completes. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9367 | TestCompletionCallback callback2; |
| 9368 | rv = trans->RestartWithAuth( |
| 9369 | AuthCredentials(kFirst, kBaz), callback2.callback()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9370 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9371 | rv = callback2.WaitForResult(); |
| 9372 | EXPECT_EQ(OK, rv); |
| 9373 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 9374 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9375 | challenge = response->auth_challenge.get(); |
| 9376 | ASSERT_FALSE(challenge == NULL); |
| 9377 | EXPECT_FALSE(challenge->is_proxy); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9378 | EXPECT_EQ("www.example.org:80", challenge->challenger.ToString()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9379 | EXPECT_EQ("second_realm", challenge->realm); |
| 9380 | EXPECT_EQ("basic", challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9381 | |
| 9382 | // Issue the third request with another incorrect password. There should be |
| 9383 | // a password prompt for first_realm waiting to be filled in. If the password |
| 9384 | // prompt is not present, it indicates that the HttpAuthCacheEntry for |
| 9385 | // first_realm was not correctly removed. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9386 | TestCompletionCallback callback3; |
| 9387 | rv = trans->RestartWithAuth( |
| 9388 | AuthCredentials(kSecond, kFou), callback3.callback()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9389 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9390 | rv = callback3.WaitForResult(); |
| 9391 | EXPECT_EQ(OK, rv); |
| 9392 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 9393 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9394 | challenge = response->auth_challenge.get(); |
| 9395 | ASSERT_FALSE(challenge == NULL); |
| 9396 | EXPECT_FALSE(challenge->is_proxy); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9397 | EXPECT_EQ("www.example.org:80", challenge->challenger.ToString()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9398 | EXPECT_EQ("first_realm", challenge->realm); |
| 9399 | EXPECT_EQ("basic", challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9400 | |
| 9401 | // Issue the fourth request with the correct password and username. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9402 | TestCompletionCallback callback4; |
| 9403 | rv = trans->RestartWithAuth( |
| 9404 | AuthCredentials(kFirst, kBar), callback4.callback()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9405 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9406 | rv = callback4.WaitForResult(); |
| 9407 | EXPECT_EQ(OK, rv); |
| 9408 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 9409 | ASSERT_TRUE(response != NULL); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9410 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 9411 | } |
| 9412 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9413 | TEST_P(HttpNetworkTransactionTest, HonorAlternativeServiceHeader) { |
| 9414 | session_deps_.next_protos = SpdyNextProtos(); |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9415 | session_deps_.use_alternative_services = true; |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9416 | |
| 9417 | std::string alternative_service_http_header = |
| 9418 | GetAlternativeServiceHttpHeader(); |
| 9419 | |
| 9420 | MockRead data_reads[] = { |
| 9421 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9422 | MockRead(alternative_service_http_header.c_str()), |
| 9423 | MockRead("\r\n"), |
| 9424 | MockRead("hello world"), |
| 9425 | MockRead(SYNCHRONOUS, OK), |
| 9426 | }; |
| 9427 | |
| 9428 | HttpRequestInfo request; |
| 9429 | request.method = "GET"; |
| 9430 | request.url = GURL("http://www.example.org/"); |
| 9431 | request.load_flags = 0; |
| 9432 | |
| 9433 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 9434 | |
| 9435 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9436 | |
| 9437 | TestCompletionCallback callback; |
| 9438 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9439 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9440 | scoped_ptr<HttpTransaction> trans( |
| 9441 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 9442 | |
| 9443 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 9444 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9445 | |
| 9446 | HostPortPair http_host_port_pair("www.example.org", 80); |
| 9447 | HttpServerProperties& http_server_properties = |
| 9448 | *session->http_server_properties(); |
| 9449 | AlternativeServiceVector alternative_service_vector = |
| 9450 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9451 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 9452 | |
| 9453 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9454 | |
| 9455 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9456 | ASSERT_TRUE(response != NULL); |
| 9457 | ASSERT_TRUE(response->headers.get() != NULL); |
| 9458 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9459 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9460 | EXPECT_FALSE(response->was_npn_negotiated); |
| 9461 | |
| 9462 | std::string response_data; |
| 9463 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9464 | EXPECT_EQ("hello world", response_data); |
| 9465 | |
| 9466 | alternative_service_vector = |
| 9467 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9468 | ASSERT_EQ(1u, alternative_service_vector.size()); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 9469 | EXPECT_EQ(AlternateProtocolFromNextProto(GetProtocol()), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9470 | alternative_service_vector[0].protocol); |
| 9471 | EXPECT_EQ("www.example.com", alternative_service_vector[0].host); |
| 9472 | EXPECT_EQ(443, alternative_service_vector[0].port); |
| 9473 | } |
| 9474 | |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 9475 | TEST_P(HttpNetworkTransactionTest, ClearAlternativeServices) { |
| 9476 | session_deps_.next_protos = SpdyNextProtos(); |
| 9477 | session_deps_.use_alternative_services = true; |
| 9478 | |
| 9479 | // Set an alternative service for origin. |
| 9480 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 9481 | HttpServerProperties& http_server_properties = |
| 9482 | *session->http_server_properties(); |
| 9483 | HostPortPair http_host_port_pair("www.example.org", 80); |
| 9484 | AlternativeService alternative_service(QUIC, "", 80); |
| 9485 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 9486 | http_server_properties.SetAlternativeService( |
| 9487 | http_host_port_pair, alternative_service, 1.0, expiration); |
| 9488 | AlternativeServiceVector alternative_service_vector = |
| 9489 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9490 | EXPECT_EQ(1u, alternative_service_vector.size()); |
| 9491 | |
| 9492 | // Send a clear header. |
| 9493 | MockRead data_reads[] = { |
| 9494 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9495 | MockRead("Alt-Svc: clear\r\n"), |
| 9496 | MockRead("\r\n"), |
| 9497 | MockRead("hello world"), |
| 9498 | MockRead(SYNCHRONOUS, OK), |
| 9499 | }; |
| 9500 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), nullptr, 0); |
| 9501 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9502 | |
| 9503 | HttpRequestInfo request; |
| 9504 | request.method = "GET"; |
| 9505 | request.url = GURL("http://www.example.org/"); |
| 9506 | request.load_flags = 0; |
| 9507 | |
| 9508 | TestCompletionCallback callback; |
| 9509 | |
| 9510 | scoped_ptr<HttpTransaction> trans( |
| 9511 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 9512 | |
| 9513 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 9514 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 9515 | |
| 9516 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9517 | ASSERT_TRUE(response != nullptr); |
| 9518 | ASSERT_TRUE(response->headers.get() != nullptr); |
| 9519 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9520 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9521 | EXPECT_FALSE(response->was_npn_negotiated); |
| 9522 | |
| 9523 | std::string response_data; |
| 9524 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9525 | EXPECT_EQ("hello world", response_data); |
| 9526 | |
| 9527 | alternative_service_vector = |
| 9528 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9529 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 9530 | } |
| 9531 | |
bnc | 54ec34b7 | 2015-08-26 19:34:56 | [diff] [blame] | 9532 | // Alternative Service headers must be ignored when |use_alternative_services| |
| 9533 | // is false. |
| 9534 | TEST_P(HttpNetworkTransactionTest, DoNotHonorAlternativeServiceHeader) { |
| 9535 | session_deps_.next_protos = SpdyNextProtos(); |
| 9536 | session_deps_.use_alternative_services = false; |
| 9537 | |
| 9538 | std::string alternative_service_http_header = |
| 9539 | GetAlternativeServiceHttpHeader(); |
| 9540 | |
| 9541 | MockRead data_reads[] = { |
| 9542 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9543 | MockRead(alternative_service_http_header.c_str()), |
| 9544 | MockRead("\r\n"), |
| 9545 | MockRead("hello world"), |
| 9546 | MockRead(SYNCHRONOUS, OK), |
| 9547 | }; |
| 9548 | |
| 9549 | HttpRequestInfo request; |
| 9550 | request.method = "GET"; |
| 9551 | request.url = GURL("http://www.example.org/"); |
| 9552 | request.load_flags = 0; |
| 9553 | |
| 9554 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), nullptr, 0); |
| 9555 | |
| 9556 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9557 | |
| 9558 | TestCompletionCallback callback; |
| 9559 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9560 | scoped_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
bnc | 54ec34b7 | 2015-08-26 19:34:56 | [diff] [blame] | 9561 | scoped_ptr<HttpTransaction> trans( |
| 9562 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 9563 | |
| 9564 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 9565 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9566 | |
| 9567 | HostPortPair http_host_port_pair("www.example.org", 80); |
| 9568 | HttpServerProperties& http_server_properties = |
| 9569 | *session->http_server_properties(); |
| 9570 | AlternativeServiceVector alternative_service_vector = |
| 9571 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9572 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 9573 | |
| 9574 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9575 | |
| 9576 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9577 | ASSERT_TRUE(response != nullptr); |
| 9578 | ASSERT_TRUE(response->headers.get() != nullptr); |
| 9579 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9580 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9581 | EXPECT_FALSE(response->was_npn_negotiated); |
| 9582 | |
| 9583 | std::string response_data; |
| 9584 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9585 | EXPECT_EQ("hello world", response_data); |
| 9586 | |
| 9587 | alternative_service_vector = |
| 9588 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9589 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 9590 | } |
| 9591 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9592 | TEST_P(HttpNetworkTransactionTest, HonorMultipleAlternativeServiceHeader) { |
| 9593 | session_deps_.next_protos = SpdyNextProtos(); |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9594 | session_deps_.use_alternative_services = true; |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9595 | |
| 9596 | MockRead data_reads[] = { |
| 9597 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9598 | MockRead("Alt-Svc: "), |
| 9599 | MockRead(GetAlternateProtocolFromParam()), |
bnc | 44858c8 | 2015-10-16 11:57:21 | [diff] [blame] | 9600 | MockRead("=\"www.example.com:443\";p=\"1.0\","), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9601 | MockRead("quic=\":1234\"\r\n\r\n"), |
| 9602 | MockRead("hello world"), |
| 9603 | MockRead(SYNCHRONOUS, OK), |
| 9604 | }; |
| 9605 | |
| 9606 | HttpRequestInfo request; |
| 9607 | request.method = "GET"; |
| 9608 | request.url = GURL("http://www.example.org/"); |
| 9609 | request.load_flags = 0; |
| 9610 | |
| 9611 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 9612 | |
| 9613 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9614 | |
| 9615 | TestCompletionCallback callback; |
| 9616 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9617 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9618 | scoped_ptr<HttpTransaction> trans( |
| 9619 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 9620 | |
| 9621 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 9622 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9623 | |
| 9624 | HostPortPair http_host_port_pair("www.example.org", 80); |
| 9625 | HttpServerProperties& http_server_properties = |
| 9626 | *session->http_server_properties(); |
| 9627 | AlternativeServiceVector alternative_service_vector = |
| 9628 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9629 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 9630 | |
| 9631 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9632 | |
| 9633 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9634 | ASSERT_TRUE(response != NULL); |
| 9635 | ASSERT_TRUE(response->headers.get() != NULL); |
| 9636 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9637 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9638 | EXPECT_FALSE(response->was_npn_negotiated); |
| 9639 | |
| 9640 | std::string response_data; |
| 9641 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9642 | EXPECT_EQ("hello world", response_data); |
| 9643 | |
| 9644 | alternative_service_vector = |
| 9645 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9646 | ASSERT_EQ(2u, alternative_service_vector.size()); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 9647 | EXPECT_EQ(AlternateProtocolFromNextProto(GetProtocol()), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9648 | alternative_service_vector[0].protocol); |
| 9649 | EXPECT_EQ("www.example.com", alternative_service_vector[0].host); |
| 9650 | EXPECT_EQ(443, alternative_service_vector[0].port); |
| 9651 | EXPECT_EQ(QUIC, alternative_service_vector[1].protocol); |
| 9652 | EXPECT_EQ("www.example.org", alternative_service_vector[1].host); |
| 9653 | EXPECT_EQ(1234, alternative_service_vector[1].port); |
| 9654 | } |
| 9655 | |
bnc | 54ec34b7 | 2015-08-26 19:34:56 | [diff] [blame] | 9656 | // Alternate Protocol headers must be honored even if |use_alternative_services| |
| 9657 | // is false. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9658 | TEST_P(HttpNetworkTransactionTest, HonorAlternateProtocolHeader) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 9659 | session_deps_.next_protos = SpdyNextProtos(); |
bnc | 54ec34b7 | 2015-08-26 19:34:56 | [diff] [blame] | 9660 | session_deps_.use_alternative_services = false; |
[email protected] | a2cb812 | 2010-03-10 17:22:42 | [diff] [blame] | 9661 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9662 | std::string alternate_protocol_http_header = |
| 9663 | GetAlternateProtocolHttpHeader(); |
| 9664 | |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9665 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9666 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9667 | MockRead(alternate_protocol_http_header.c_str()), |
| 9668 | MockRead("\r\n"), |
| 9669 | MockRead("hello world"), |
| 9670 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9671 | }; |
| 9672 | |
| 9673 | HttpRequestInfo request; |
| 9674 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9675 | request.url = GURL("http://www.example.org/"); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9676 | request.load_flags = 0; |
| 9677 | |
| 9678 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 9679 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9680 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9681 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9682 | TestCompletionCallback callback; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9683 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9684 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9685 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9686 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9687 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9688 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9689 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 9690 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9691 | HostPortPair http_host_port_pair("www.example.org", 80); |
[email protected] | 9801e370 | 2014-03-07 09:33:55 | [diff] [blame] | 9692 | HttpServerProperties& http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 9693 | *session->http_server_properties(); |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 9694 | AlternativeServiceVector alternative_service_vector = |
| 9695 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9696 | EXPECT_TRUE(alternative_service_vector.empty()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9697 | |
| 9698 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9699 | |
| 9700 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9701 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9702 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9703 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9704 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9705 | EXPECT_FALSE(response->was_npn_negotiated); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9706 | |
| 9707 | std::string response_data; |
| 9708 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9709 | EXPECT_EQ("hello world", response_data); |
| 9710 | |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 9711 | alternative_service_vector = |
| 9712 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9713 | ASSERT_EQ(1u, alternative_service_vector.size()); |
| 9714 | EXPECT_EQ(443, alternative_service_vector[0].port); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 9715 | EXPECT_EQ(AlternateProtocolFromNextProto(GetProtocol()), |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 9716 | alternative_service_vector[0].protocol); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9717 | } |
| 9718 | |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 9719 | TEST_P(HttpNetworkTransactionTest, EmptyAlternateProtocolHeader) { |
| 9720 | session_deps_.next_protos = SpdyNextProtos(); |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9721 | session_deps_.use_alternative_services = true; |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 9722 | |
| 9723 | MockRead data_reads[] = { |
| 9724 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9725 | MockRead("Alternate-Protocol: \r\n\r\n"), |
| 9726 | MockRead("hello world"), |
| 9727 | MockRead(SYNCHRONOUS, OK), |
| 9728 | }; |
| 9729 | |
| 9730 | HttpRequestInfo request; |
| 9731 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9732 | request.url = GURL("http://www.example.org/"); |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 9733 | request.load_flags = 0; |
| 9734 | |
| 9735 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 9736 | |
| 9737 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9738 | |
| 9739 | TestCompletionCallback callback; |
| 9740 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9741 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 9742 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9743 | HostPortPair http_host_port_pair("www.example.org", 80); |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 9744 | HttpServerProperties& http_server_properties = |
| 9745 | *session->http_server_properties(); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9746 | AlternativeService alternative_service(QUIC, "", 80); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9747 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 9748 | http_server_properties.SetAlternativeService( |
| 9749 | http_host_port_pair, alternative_service, 1.0, expiration); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9750 | |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 9751 | AlternativeServiceVector alternative_service_vector = |
| 9752 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9753 | ASSERT_EQ(1u, alternative_service_vector.size()); |
| 9754 | EXPECT_EQ(QUIC, alternative_service_vector[0].protocol); |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 9755 | |
| 9756 | scoped_ptr<HttpTransaction> trans( |
| 9757 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 9758 | |
| 9759 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 9760 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9761 | |
| 9762 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9763 | |
| 9764 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9765 | ASSERT_TRUE(response != NULL); |
| 9766 | ASSERT_TRUE(response->headers.get() != NULL); |
| 9767 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9768 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9769 | EXPECT_FALSE(response->was_npn_negotiated); |
| 9770 | |
| 9771 | std::string response_data; |
| 9772 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9773 | EXPECT_EQ("hello world", response_data); |
| 9774 | |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 9775 | alternative_service_vector = |
| 9776 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9777 | EXPECT_TRUE(alternative_service_vector.empty()); |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 9778 | } |
| 9779 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9780 | TEST_P(HttpNetworkTransactionTest, AltSvcOverwritesAlternateProtocol) { |
| 9781 | session_deps_.next_protos = SpdyNextProtos(); |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9782 | session_deps_.use_alternative_services = true; |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9783 | |
| 9784 | std::string alternative_service_http_header = |
| 9785 | GetAlternativeServiceHttpHeader(); |
| 9786 | std::string alternate_protocol_http_header = GetAlternateProtocolHttpHeader(); |
| 9787 | |
| 9788 | MockRead data_reads[] = { |
| 9789 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9790 | MockRead(alternative_service_http_header.c_str()), |
| 9791 | MockRead(alternate_protocol_http_header.c_str()), |
| 9792 | MockRead("\r\n"), |
| 9793 | MockRead("hello world"), |
| 9794 | MockRead(SYNCHRONOUS, OK), |
| 9795 | }; |
| 9796 | |
| 9797 | HttpRequestInfo request; |
| 9798 | request.method = "GET"; |
| 9799 | request.url = GURL("http://www.example.org/"); |
| 9800 | request.load_flags = 0; |
| 9801 | |
| 9802 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 9803 | |
| 9804 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9805 | |
| 9806 | TestCompletionCallback callback; |
| 9807 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9808 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9809 | scoped_ptr<HttpTransaction> trans( |
| 9810 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 9811 | |
| 9812 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 9813 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9814 | |
| 9815 | HostPortPair http_host_port_pair("www.example.org", 80); |
| 9816 | HttpServerProperties& http_server_properties = |
| 9817 | *session->http_server_properties(); |
| 9818 | AlternativeServiceVector alternative_service_vector = |
| 9819 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9820 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 9821 | |
| 9822 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9823 | |
| 9824 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9825 | ASSERT_TRUE(response != NULL); |
| 9826 | ASSERT_TRUE(response->headers.get() != NULL); |
| 9827 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9828 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9829 | EXPECT_FALSE(response->was_npn_negotiated); |
| 9830 | |
| 9831 | std::string response_data; |
| 9832 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9833 | EXPECT_EQ("hello world", response_data); |
| 9834 | |
| 9835 | alternative_service_vector = |
| 9836 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9837 | ASSERT_EQ(1u, alternative_service_vector.size()); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 9838 | EXPECT_EQ(AlternateProtocolFromNextProto(GetProtocol()), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9839 | alternative_service_vector[0].protocol); |
| 9840 | EXPECT_EQ("www.example.com", alternative_service_vector[0].host); |
| 9841 | EXPECT_EQ(443, alternative_service_vector[0].port); |
| 9842 | } |
| 9843 | |
bnc | 54ec34b7 | 2015-08-26 19:34:56 | [diff] [blame] | 9844 | // When |use_alternative_services| is false, do not observe alternative service |
| 9845 | // entries that point to a different host. |
| 9846 | TEST_P(HttpNetworkTransactionTest, DisableAlternativeServiceToDifferentHost) { |
| 9847 | session_deps_.use_alternative_services = false; |
| 9848 | |
| 9849 | HttpRequestInfo request; |
| 9850 | request.method = "GET"; |
| 9851 | request.url = GURL("http://www.example.org/"); |
| 9852 | request.load_flags = 0; |
| 9853 | |
| 9854 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 9855 | StaticSocketDataProvider first_data; |
| 9856 | first_data.set_connect_data(mock_connect); |
| 9857 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
| 9858 | |
| 9859 | MockRead data_reads[] = { |
| 9860 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 9861 | MockRead(ASYNC, OK), |
| 9862 | }; |
| 9863 | StaticSocketDataProvider second_data(data_reads, arraysize(data_reads), |
| 9864 | nullptr, 0); |
| 9865 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 9866 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9867 | scoped_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
bnc | 54ec34b7 | 2015-08-26 19:34:56 | [diff] [blame] | 9868 | |
| 9869 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 9870 | session->http_server_properties(); |
| 9871 | AlternativeService alternative_service( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 9872 | AlternateProtocolFromNextProto(GetProtocol()), "different.example.org", |
| 9873 | 80); |
bnc | 54ec34b7 | 2015-08-26 19:34:56 | [diff] [blame] | 9874 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 9875 | http_server_properties->SetAlternativeService( |
| 9876 | HostPortPair::FromURL(request.url), alternative_service, 1.0, expiration); |
| 9877 | |
| 9878 | scoped_ptr<HttpTransaction> trans( |
| 9879 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 9880 | TestCompletionCallback callback; |
| 9881 | |
| 9882 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 9883 | // The connetion to origin was refused, and the alternative service should not |
| 9884 | // be used (even though mock data are there), therefore the request should |
| 9885 | // fail. |
| 9886 | EXPECT_EQ(ERR_CONNECTION_REFUSED, callback.GetResult(rv)); |
| 9887 | } |
| 9888 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9889 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9890 | MarkBrokenAlternateProtocolAndFallback) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9891 | session_deps_.use_alternative_services = true; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9892 | |
| 9893 | HttpRequestInfo request; |
| 9894 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9895 | request.url = GURL("http://www.example.org/"); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9896 | request.load_flags = 0; |
| 9897 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 9898 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9899 | StaticSocketDataProvider first_data; |
| 9900 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9901 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9902 | |
| 9903 | MockRead data_reads[] = { |
| 9904 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 9905 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9906 | MockRead(ASYNC, OK), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9907 | }; |
| 9908 | StaticSocketDataProvider second_data( |
| 9909 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9910 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9911 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9912 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9913 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 9914 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 9915 | session->http_server_properties(); |
bnc | 8445b300 | 2015-03-13 01:57:09 | [diff] [blame] | 9916 | const HostPortPair host_port_pair = HostPortPair::FromURL(request.url); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9917 | // Port must be < 1024, or the header will be ignored (since initial port was |
| 9918 | // port 80 (another restricted port). |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 9919 | const AlternativeService alternative_service( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 9920 | AlternateProtocolFromNextProto(GetProtocol()), "www.example.org", |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 9921 | 666); // Port is ignored by MockConnect anyway. |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9922 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 9923 | http_server_properties->SetAlternativeService( |
| 9924 | host_port_pair, alternative_service, 1.0, expiration); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9925 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9926 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9927 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9928 | TestCompletionCallback callback; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9929 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9930 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9931 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9932 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9933 | |
| 9934 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9935 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9936 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9937 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9938 | |
| 9939 | std::string response_data; |
| 9940 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9941 | EXPECT_EQ("hello world", response_data); |
| 9942 | |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 9943 | const AlternativeServiceVector alternative_service_vector = |
| 9944 | http_server_properties->GetAlternativeServices(host_port_pair); |
| 9945 | ASSERT_EQ(1u, alternative_service_vector.size()); |
| 9946 | EXPECT_EQ(alternative_service, alternative_service_vector[0]); |
| 9947 | EXPECT_TRUE(http_server_properties->IsAlternativeServiceBroken( |
| 9948 | alternative_service_vector[0])); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9949 | } |
| 9950 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9951 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 9952 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 9953 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 9954 | // cases. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9955 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9956 | AlternateProtocolPortRestrictedBlocked) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9957 | session_deps_.use_alternative_services = true; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9958 | |
| 9959 | HttpRequestInfo restricted_port_request; |
| 9960 | restricted_port_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9961 | restricted_port_request.url = GURL("http://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9962 | restricted_port_request.load_flags = 0; |
| 9963 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 9964 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9965 | StaticSocketDataProvider first_data; |
| 9966 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9967 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9968 | |
| 9969 | MockRead data_reads[] = { |
| 9970 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 9971 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9972 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9973 | }; |
| 9974 | StaticSocketDataProvider second_data( |
| 9975 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9976 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9977 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9978 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9979 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 9980 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 9981 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9982 | const int kUnrestrictedAlternatePort = 1024; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9983 | AlternativeService alternative_service( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 9984 | AlternateProtocolFromNextProto(GetProtocol()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9985 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9986 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9987 | http_server_properties->SetAlternativeService( |
| 9988 | HostPortPair::FromURL(restricted_port_request.url), alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9989 | 1.0, expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9990 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9991 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9992 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9993 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9994 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9995 | int rv = trans->Start( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9996 | &restricted_port_request, |
| 9997 | callback.callback(), BoundNetLog()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9998 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9999 | // Invalid change to unrestricted port should fail. |
| 10000 | EXPECT_EQ(ERR_CONNECTION_REFUSED, callback.WaitForResult()); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10001 | } |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10002 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10003 | // Ensure that we are allowed to redirect traffic via an alternate protocol to |
| 10004 | // an unrestricted (port >= 1024) when the original traffic was on a restricted |
| 10005 | // port (port < 1024) if we set |enable_user_alternate_protocol_ports|. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10006 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10007 | AlternateProtocolPortRestrictedPermitted) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10008 | session_deps_.use_alternative_services = true; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10009 | session_deps_.enable_user_alternate_protocol_ports = true; |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10010 | |
| 10011 | HttpRequestInfo restricted_port_request; |
| 10012 | restricted_port_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10013 | restricted_port_request.url = GURL("http://www.example.org:1023/"); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10014 | restricted_port_request.load_flags = 0; |
| 10015 | |
| 10016 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 10017 | StaticSocketDataProvider first_data; |
| 10018 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10019 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10020 | |
| 10021 | MockRead data_reads[] = { |
| 10022 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10023 | MockRead("hello world"), |
| 10024 | MockRead(ASYNC, OK), |
| 10025 | }; |
| 10026 | StaticSocketDataProvider second_data( |
| 10027 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10028 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10029 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10030 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10031 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 10032 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10033 | session->http_server_properties(); |
| 10034 | const int kUnrestrictedAlternatePort = 1024; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10035 | AlternativeService alternative_service( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 10036 | AlternateProtocolFromNextProto(GetProtocol()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10037 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10038 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10039 | http_server_properties->SetAlternativeService( |
| 10040 | HostPortPair::FromURL(restricted_port_request.url), alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10041 | 1.0, expiration); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10042 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10043 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10044 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10045 | TestCompletionCallback callback; |
| 10046 | |
| 10047 | EXPECT_EQ(ERR_IO_PENDING, trans->Start( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10048 | &restricted_port_request, |
| 10049 | callback.callback(), BoundNetLog())); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10050 | // Change to unrestricted port should succeed. |
| 10051 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10052 | } |
| 10053 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10054 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10055 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 10056 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 10057 | // cases. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10058 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 10059 | AlternateProtocolPortRestrictedAllowed) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10060 | session_deps_.use_alternative_services = true; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10061 | |
| 10062 | HttpRequestInfo restricted_port_request; |
| 10063 | restricted_port_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10064 | restricted_port_request.url = GURL("http://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10065 | restricted_port_request.load_flags = 0; |
| 10066 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10067 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10068 | StaticSocketDataProvider first_data; |
| 10069 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10070 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10071 | |
| 10072 | MockRead data_reads[] = { |
| 10073 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10074 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10075 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10076 | }; |
| 10077 | StaticSocketDataProvider second_data( |
| 10078 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10079 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10080 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10081 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10082 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 10083 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10084 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10085 | const int kRestrictedAlternatePort = 80; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10086 | AlternativeService alternative_service( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 10087 | AlternateProtocolFromNextProto(GetProtocol()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10088 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10089 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10090 | http_server_properties->SetAlternativeService( |
| 10091 | HostPortPair::FromURL(restricted_port_request.url), alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10092 | 1.0, expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10093 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10094 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10095 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10096 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10097 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10098 | int rv = trans->Start( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10099 | &restricted_port_request, |
| 10100 | callback.callback(), BoundNetLog()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10101 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10102 | // Valid change to restricted port should pass. |
| 10103 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10104 | } |
| 10105 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10106 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10107 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 10108 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 10109 | // cases. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10110 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 10111 | AlternateProtocolPortUnrestrictedAllowed1) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10112 | session_deps_.use_alternative_services = true; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10113 | |
| 10114 | HttpRequestInfo unrestricted_port_request; |
| 10115 | unrestricted_port_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10116 | unrestricted_port_request.url = GURL("http://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10117 | unrestricted_port_request.load_flags = 0; |
| 10118 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10119 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10120 | StaticSocketDataProvider first_data; |
| 10121 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10122 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10123 | |
| 10124 | MockRead data_reads[] = { |
| 10125 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10126 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10127 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10128 | }; |
| 10129 | StaticSocketDataProvider second_data( |
| 10130 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10131 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10132 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10133 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10134 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 10135 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10136 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10137 | const int kRestrictedAlternatePort = 80; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10138 | AlternativeService alternative_service( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 10139 | AlternateProtocolFromNextProto(GetProtocol()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10140 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10141 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10142 | http_server_properties->SetAlternativeService( |
| 10143 | HostPortPair::FromURL(unrestricted_port_request.url), alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10144 | 1.0, expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10145 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10146 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10147 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10148 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10149 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10150 | int rv = trans->Start( |
| 10151 | &unrestricted_port_request, callback.callback(), BoundNetLog()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10152 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10153 | // Valid change to restricted port should pass. |
| 10154 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10155 | } |
| 10156 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10157 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10158 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 10159 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 10160 | // cases. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10161 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 10162 | AlternateProtocolPortUnrestrictedAllowed2) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10163 | session_deps_.use_alternative_services = true; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10164 | |
| 10165 | HttpRequestInfo unrestricted_port_request; |
| 10166 | unrestricted_port_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10167 | unrestricted_port_request.url = GURL("http://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10168 | unrestricted_port_request.load_flags = 0; |
| 10169 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10170 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10171 | StaticSocketDataProvider first_data; |
| 10172 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10173 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10174 | |
| 10175 | MockRead data_reads[] = { |
| 10176 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10177 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10178 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10179 | }; |
| 10180 | StaticSocketDataProvider second_data( |
| 10181 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10182 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10183 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10184 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10185 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 10186 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10187 | session->http_server_properties(); |
bnc | 0bbb0262 | 2015-07-23 10:06:22 | [diff] [blame] | 10188 | const int kUnrestrictedAlternatePort = 1025; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10189 | AlternativeService alternative_service( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 10190 | AlternateProtocolFromNextProto(GetProtocol()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10191 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10192 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10193 | http_server_properties->SetAlternativeService( |
| 10194 | HostPortPair::FromURL(unrestricted_port_request.url), alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10195 | 1.0, expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10196 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10197 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10198 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10199 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10200 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10201 | int rv = trans->Start( |
| 10202 | &unrestricted_port_request, callback.callback(), BoundNetLog()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10203 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10204 | // Valid change to an unrestricted port should pass. |
| 10205 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10206 | } |
| 10207 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10208 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10209 | // to an unsafe port, and that we resume the second HttpStreamFactoryImpl::Job |
| 10210 | // once the alternate protocol request fails. |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 10211 | TEST_P(HttpNetworkTransactionTest, AlternateProtocolUnsafeBlocked) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10212 | session_deps_.use_alternative_services = true; |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10213 | |
| 10214 | HttpRequestInfo request; |
| 10215 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10216 | request.url = GURL("http://www.example.org/"); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10217 | request.load_flags = 0; |
| 10218 | |
| 10219 | // The alternate protocol request will error out before we attempt to connect, |
| 10220 | // so only the standard HTTP request will try to connect. |
| 10221 | MockRead data_reads[] = { |
| 10222 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10223 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10224 | MockRead(ASYNC, OK), |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10225 | }; |
| 10226 | StaticSocketDataProvider data( |
| 10227 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10228 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10229 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10230 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10231 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 10232 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10233 | session->http_server_properties(); |
| 10234 | const int kUnsafePort = 7; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10235 | AlternativeService alternative_service( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 10236 | AlternateProtocolFromNextProto(GetProtocol()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10237 | kUnsafePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10238 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10239 | http_server_properties->SetAlternativeService( |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10240 | HostPortPair::FromURL(request.url), alternative_service, 1.0, expiration); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10241 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10242 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10243 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10244 | TestCompletionCallback callback; |
| 10245 | |
| 10246 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 10247 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10248 | // The HTTP request should succeed. |
| 10249 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 10250 | |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10251 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10252 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10253 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10254 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10255 | |
| 10256 | std::string response_data; |
| 10257 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10258 | EXPECT_EQ("hello world", response_data); |
| 10259 | } |
| 10260 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10261 | TEST_P(HttpNetworkTransactionTest, UseAlternateProtocolForNpnSpdy) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10262 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 10263 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10264 | |
| 10265 | HttpRequestInfo request; |
| 10266 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10267 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10268 | request.load_flags = 0; |
| 10269 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 10270 | std::string alternate_protocol_http_header = |
| 10271 | GetAlternateProtocolHttpHeader(); |
| 10272 | |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10273 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10274 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10275 | MockRead(alternate_protocol_http_header.c_str()), |
| 10276 | MockRead("\r\n"), |
| 10277 | MockRead("hello world"), |
| 10278 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 10279 | MockRead(ASYNC, OK)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10280 | |
| 10281 | StaticSocketDataProvider first_transaction( |
| 10282 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10283 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10284 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10285 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 10286 | ssl.SetNextProto(GetProtocol()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10287 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 10288 | ASSERT_TRUE(ssl.cert.get()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10289 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10290 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 10291 | scoped_ptr<SpdyFrame> req( |
| 10292 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10293 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10294 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10295 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 10296 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10297 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10298 | CreateMockRead(*resp, 1), CreateMockRead(*data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10299 | }; |
| 10300 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10301 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 10302 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10303 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10304 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10305 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10306 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 10307 | NULL, 0, NULL, 0); |
| 10308 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 10309 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10310 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10311 | &hanging_non_alternate_protocol_socket); |
| 10312 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10313 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10314 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10315 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10316 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10317 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10318 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10319 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10320 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10321 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 10322 | |
| 10323 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10324 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10325 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10326 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10327 | |
| 10328 | std::string response_data; |
| 10329 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10330 | EXPECT_EQ("hello world", response_data); |
| 10331 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10332 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10333 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10334 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10335 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10336 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 10337 | |
| 10338 | response = trans->GetResponseInfo(); |
| 10339 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10340 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame^] | 10341 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10342 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 10343 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10344 | |
| 10345 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10346 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10347 | } |
| 10348 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10349 | TEST_P(HttpNetworkTransactionTest, AlternateProtocolWithSpdyLateBinding) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10350 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 10351 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10352 | |
| 10353 | HttpRequestInfo request; |
| 10354 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10355 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10356 | request.load_flags = 0; |
| 10357 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 10358 | std::string alternate_protocol_http_header = |
| 10359 | GetAlternateProtocolHttpHeader(); |
| 10360 | |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10361 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10362 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10363 | MockRead(alternate_protocol_http_header.c_str()), |
| 10364 | MockRead("\r\n"), |
| 10365 | MockRead("hello world"), |
| 10366 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 10367 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10368 | }; |
| 10369 | |
| 10370 | StaticSocketDataProvider first_transaction( |
| 10371 | data_reads, arraysize(data_reads), NULL, 0); |
| 10372 | // Socket 1 is the HTTP transaction with the Alternate-Protocol header. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10373 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10374 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10375 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10376 | StaticSocketDataProvider hanging_socket( |
| 10377 | NULL, 0, NULL, 0); |
| 10378 | hanging_socket.set_connect_data(never_finishing_connect); |
| 10379 | // Socket 2 and 3 are the hanging Alternate-Protocol and |
| 10380 | // non-Alternate-Protocol jobs from the 2nd transaction. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10381 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket); |
| 10382 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10383 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10384 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 10385 | ssl.SetNextProto(GetProtocol()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10386 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 10387 | ASSERT_TRUE(ssl.cert.get()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10388 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10389 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 10390 | scoped_ptr<SpdyFrame> req1( |
| 10391 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 10392 | scoped_ptr<SpdyFrame> req2( |
| 10393 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, LOWEST, true)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10394 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10395 | CreateMockWrite(*req1, 0), CreateMockWrite(*req2, 1), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10396 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10397 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 10398 | scoped_ptr<SpdyFrame> data1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 10399 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 10400 | scoped_ptr<SpdyFrame> data2(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10401 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10402 | CreateMockRead(*resp1, 2), |
| 10403 | CreateMockRead(*data1, 3), |
| 10404 | CreateMockRead(*resp2, 4), |
| 10405 | CreateMockRead(*data2, 5), |
| 10406 | MockRead(ASYNC, 0, 6), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10407 | }; |
| 10408 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10409 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 10410 | arraysize(spdy_writes)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10411 | // Socket 4 is the successful Alternate-Protocol for transaction 3. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10412 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10413 | |
| 10414 | // Socket 5 is the unsuccessful non-Alternate-Protocol for transaction 3. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10415 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10416 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10417 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10418 | TestCompletionCallback callback1; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10419 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10420 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10421 | int rv = trans1.Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10422 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10423 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 10424 | |
| 10425 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 10426 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10427 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10428 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10429 | |
| 10430 | std::string response_data; |
| 10431 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); |
| 10432 | EXPECT_EQ("hello world", response_data); |
| 10433 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10434 | TestCompletionCallback callback2; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10435 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10436 | rv = trans2.Start(&request, callback2.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10437 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10438 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10439 | TestCompletionCallback callback3; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10440 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10441 | rv = trans3.Start(&request, callback3.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10442 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10443 | |
| 10444 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 10445 | EXPECT_EQ(OK, callback3.WaitForResult()); |
| 10446 | |
| 10447 | response = trans2.GetResponseInfo(); |
| 10448 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10449 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame^] | 10450 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10451 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 10452 | EXPECT_TRUE(response->was_npn_negotiated); |
| 10453 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 10454 | EXPECT_EQ("hello!", response_data); |
| 10455 | |
| 10456 | response = trans3.GetResponseInfo(); |
| 10457 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10458 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame^] | 10459 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10460 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 10461 | EXPECT_TRUE(response->was_npn_negotiated); |
| 10462 | ASSERT_EQ(OK, ReadTransaction(&trans3, &response_data)); |
| 10463 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10464 | } |
| 10465 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10466 | TEST_P(HttpNetworkTransactionTest, StallAlternateProtocolForNpnSpdy) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10467 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 10468 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10469 | |
| 10470 | HttpRequestInfo request; |
| 10471 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10472 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10473 | request.load_flags = 0; |
| 10474 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 10475 | std::string alternate_protocol_http_header = |
| 10476 | GetAlternateProtocolHttpHeader(); |
| 10477 | |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10478 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10479 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10480 | MockRead(alternate_protocol_http_header.c_str()), |
| 10481 | MockRead("\r\n"), |
| 10482 | MockRead("hello world"), |
| 10483 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 10484 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10485 | }; |
| 10486 | |
| 10487 | StaticSocketDataProvider first_transaction( |
| 10488 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10489 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10490 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10491 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 10492 | ssl.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10493 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10494 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10495 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10496 | StaticSocketDataProvider hanging_alternate_protocol_socket( |
| 10497 | NULL, 0, NULL, 0); |
| 10498 | hanging_alternate_protocol_socket.set_connect_data( |
| 10499 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10500 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10501 | &hanging_alternate_protocol_socket); |
| 10502 | |
| 10503 | // 2nd request is just a copy of the first one, over HTTP again. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10504 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10505 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10506 | TestCompletionCallback callback; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10507 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10508 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10509 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10510 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10511 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10512 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10513 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10514 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 10515 | |
| 10516 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10517 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10518 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10519 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10520 | |
| 10521 | std::string response_data; |
| 10522 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10523 | EXPECT_EQ("hello world", response_data); |
| 10524 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10525 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10526 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10527 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10528 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10529 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 10530 | |
| 10531 | response = trans->GetResponseInfo(); |
| 10532 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10533 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10534 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10535 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 10536 | EXPECT_FALSE(response->was_npn_negotiated); |
| 10537 | |
| 10538 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10539 | EXPECT_EQ("hello world", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10540 | } |
| 10541 | |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10542 | class CapturingProxyResolver : public ProxyResolver { |
| 10543 | public: |
sammc | e90c921 | 2015-05-27 23:43:35 | [diff] [blame] | 10544 | CapturingProxyResolver() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 10545 | ~CapturingProxyResolver() override {} |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10546 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 10547 | int GetProxyForURL(const GURL& url, |
| 10548 | ProxyInfo* results, |
| 10549 | const CompletionCallback& callback, |
| 10550 | RequestHandle* request, |
| 10551 | const BoundNetLog& net_log) override { |
[email protected] | fae7669f | 2010-08-02 21:49:40 | [diff] [blame] | 10552 | ProxyServer proxy_server(ProxyServer::SCHEME_HTTP, |
| 10553 | HostPortPair("myproxy", 80)); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 10554 | results->UseProxyServer(proxy_server); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10555 | resolved_.push_back(url); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 10556 | return OK; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10557 | } |
| 10558 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 10559 | void CancelRequest(RequestHandle request) override { NOTREACHED(); } |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10560 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 10561 | LoadState GetLoadState(RequestHandle request) const override { |
[email protected] | f2c971f | 2011-11-08 00:33:17 | [diff] [blame] | 10562 | NOTREACHED(); |
| 10563 | return LOAD_STATE_IDLE; |
| 10564 | } |
| 10565 | |
[email protected] | 2447640 | 2010-07-20 20:55:17 | [diff] [blame] | 10566 | const std::vector<GURL>& resolved() const { return resolved_; } |
| 10567 | |
| 10568 | private: |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10569 | std::vector<GURL> resolved_; |
| 10570 | |
| 10571 | DISALLOW_COPY_AND_ASSIGN(CapturingProxyResolver); |
| 10572 | }; |
| 10573 | |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 10574 | class CapturingProxyResolverFactory : public ProxyResolverFactory { |
| 10575 | public: |
| 10576 | explicit CapturingProxyResolverFactory(CapturingProxyResolver* resolver) |
| 10577 | : ProxyResolverFactory(false), resolver_(resolver) {} |
| 10578 | |
| 10579 | int CreateProxyResolver( |
| 10580 | const scoped_refptr<ProxyResolverScriptData>& pac_script, |
| 10581 | scoped_ptr<ProxyResolver>* resolver, |
| 10582 | const net::CompletionCallback& callback, |
| 10583 | scoped_ptr<Request>* request) override { |
| 10584 | resolver->reset(new ForwardingProxyResolver(resolver_)); |
| 10585 | return OK; |
| 10586 | } |
| 10587 | |
| 10588 | private: |
| 10589 | ProxyResolver* resolver_; |
| 10590 | }; |
| 10591 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10592 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 10593 | UseAlternateProtocolForTunneledNpnSpdy) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10594 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 10595 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10596 | |
| 10597 | ProxyConfig proxy_config; |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 10598 | proxy_config.set_auto_detect(true); |
| 10599 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 10600 | |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 10601 | CapturingProxyResolver capturing_proxy_resolver; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10602 | session_deps_.proxy_service.reset(new ProxyService( |
csharrison | b7e3a08 | 2015-09-22 19:13:04 | [diff] [blame] | 10603 | make_scoped_ptr(new ProxyConfigServiceFixed(proxy_config)), |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 10604 | make_scoped_ptr( |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 10605 | new CapturingProxyResolverFactory(&capturing_proxy_resolver)), |
[email protected] | 66761b95 | 2010-06-25 21:30:38 | [diff] [blame] | 10606 | NULL)); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10607 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10608 | session_deps_.net_log = &net_log; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10609 | |
| 10610 | HttpRequestInfo request; |
| 10611 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10612 | request.url = GURL("http://www.example.org/"); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10613 | request.load_flags = 0; |
| 10614 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 10615 | std::string alternate_protocol_http_header = |
| 10616 | GetAlternateProtocolHttpHeader(); |
| 10617 | |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10618 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10619 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10620 | MockRead(alternate_protocol_http_header.c_str()), |
| 10621 | MockRead("\r\n"), |
| 10622 | MockRead("hello world"), |
| 10623 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 10624 | MockRead(ASYNC, OK), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10625 | }; |
| 10626 | |
| 10627 | StaticSocketDataProvider first_transaction( |
| 10628 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10629 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10630 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10631 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 10632 | ssl.SetNextProto(GetProtocol()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10633 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 10634 | ASSERT_TRUE(ssl.cert.get()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10635 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10636 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 10637 | scoped_ptr<SpdyFrame> req( |
| 10638 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10639 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10640 | MockWrite(ASYNC, 0, |
| 10641 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 10642 | "Host: www.example.org:443\r\n" |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10643 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 10644 | CreateMockWrite(*req, 2), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10645 | }; |
| 10646 | |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 10647 | const char kCONNECTResponse[] = "HTTP/1.1 200 Connected\r\n\r\n"; |
| 10648 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10649 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 10650 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10651 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10652 | MockRead(ASYNC, 1, kCONNECTResponse), |
| 10653 | CreateMockRead(*resp.get(), 3), |
| 10654 | CreateMockRead(*data.get(), 4), |
| 10655 | MockRead(ASYNC, ERR_IO_PENDING, 5), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10656 | }; |
| 10657 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10658 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 10659 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10660 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10661 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10662 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10663 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 10664 | NULL, 0, NULL, 0); |
| 10665 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 10666 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10667 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10668 | &hanging_non_alternate_protocol_socket); |
| 10669 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10670 | TestCompletionCallback callback; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10671 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10672 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10673 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10674 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10675 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10676 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10677 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10678 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 10679 | |
| 10680 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10681 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10682 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10683 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10684 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 10685 | EXPECT_FALSE(response->was_npn_negotiated); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10686 | |
| 10687 | std::string response_data; |
| 10688 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10689 | EXPECT_EQ("hello world", response_data); |
| 10690 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10691 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10692 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10693 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10694 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10695 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 10696 | |
| 10697 | response = trans->GetResponseInfo(); |
| 10698 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10699 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame^] | 10700 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10701 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 10702 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10703 | |
| 10704 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10705 | EXPECT_EQ("hello!", response_data); |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 10706 | ASSERT_EQ(3u, capturing_proxy_resolver.resolved().size()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10707 | EXPECT_EQ("http://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 10708 | capturing_proxy_resolver.resolved()[0].spec()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10709 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 10710 | capturing_proxy_resolver.resolved()[1].spec()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10711 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10712 | LoadTimingInfo load_timing_info; |
| 10713 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 10714 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10715 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10716 | } |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10717 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10718 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10719 | UseAlternateProtocolForNpnSpdyWithExistingSpdySession) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10720 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 10721 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10722 | |
| 10723 | HttpRequestInfo request; |
| 10724 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10725 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10726 | request.load_flags = 0; |
| 10727 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 10728 | std::string alternate_protocol_http_header = |
| 10729 | GetAlternateProtocolHttpHeader(); |
| 10730 | |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10731 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10732 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10733 | MockRead(alternate_protocol_http_header.c_str()), |
| 10734 | MockRead("\r\n"), |
| 10735 | MockRead("hello world"), |
| 10736 | MockRead(ASYNC, OK), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10737 | }; |
| 10738 | |
| 10739 | StaticSocketDataProvider first_transaction( |
| 10740 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10741 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10742 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10743 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 10744 | ssl.SetNextProto(GetProtocol()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10745 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 10746 | ASSERT_TRUE(ssl.cert.get()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10747 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10748 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 10749 | scoped_ptr<SpdyFrame> req( |
| 10750 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10751 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10752 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10753 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 10754 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10755 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10756 | CreateMockRead(*resp, 1), CreateMockRead(*data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10757 | }; |
| 10758 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10759 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 10760 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10761 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10762 | |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 10763 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10764 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10765 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10766 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10767 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10768 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10769 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10770 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10771 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10772 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10773 | |
| 10774 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10775 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10776 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10777 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10778 | |
| 10779 | std::string response_data; |
| 10780 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10781 | EXPECT_EQ("hello world", response_data); |
| 10782 | |
| 10783 | // Set up an initial SpdySession in the pool to reuse. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10784 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 10785 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 10786 | PRIVACY_MODE_DISABLED); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 10787 | base::WeakPtr<SpdySession> spdy_session = |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10788 | CreateSecureSpdySession(session.get(), key, BoundNetLog()); |
[email protected] | 02b0c34 | 2010-09-25 21:09:38 | [diff] [blame] | 10789 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10790 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10791 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10792 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10793 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10794 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10795 | |
| 10796 | response = trans->GetResponseInfo(); |
| 10797 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10798 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame^] | 10799 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10800 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 10801 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10802 | |
| 10803 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10804 | EXPECT_EQ("hello!", response_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10805 | } |
| 10806 | |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10807 | // GenerateAuthToken is a mighty big test. |
| 10808 | // It tests all permutation of GenerateAuthToken behavior: |
| 10809 | // - Synchronous and Asynchronous completion. |
| 10810 | // - OK or error on completion. |
| 10811 | // - Direct connection, non-authenticating proxy, and authenticating proxy. |
| 10812 | // - HTTP or HTTPS backend (to include proxy tunneling). |
| 10813 | // - Non-authenticating and authenticating backend. |
| 10814 | // |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 10815 | // In all, there are 44 reasonable permuations (for example, if there are |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10816 | // problems generating an auth token for an authenticating proxy, we don't |
| 10817 | // need to test all permutations of the backend server). |
| 10818 | // |
| 10819 | // The test proceeds by going over each of the configuration cases, and |
| 10820 | // potentially running up to three rounds in each of the tests. The TestConfig |
| 10821 | // specifies both the configuration for the test as well as the expectations |
| 10822 | // for the results. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10823 | TEST_P(HttpNetworkTransactionTest, GenerateAuthToken) { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 10824 | static const char kServer[] = "http://www.example.com"; |
| 10825 | static const char kSecureServer[] = "https://www.example.com"; |
| 10826 | static const char kProxy[] = "myproxy:70"; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10827 | const int kAuthErr = ERR_INVALID_AUTH_CREDENTIALS; |
| 10828 | |
| 10829 | enum AuthTiming { |
| 10830 | AUTH_NONE, |
| 10831 | AUTH_SYNC, |
| 10832 | AUTH_ASYNC, |
| 10833 | }; |
| 10834 | |
| 10835 | const MockWrite kGet( |
| 10836 | "GET / HTTP/1.1\r\n" |
| 10837 | "Host: www.example.com\r\n" |
| 10838 | "Connection: keep-alive\r\n\r\n"); |
| 10839 | const MockWrite kGetProxy( |
| 10840 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 10841 | "Host: www.example.com\r\n" |
| 10842 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 10843 | const MockWrite kGetAuth( |
| 10844 | "GET / HTTP/1.1\r\n" |
| 10845 | "Host: www.example.com\r\n" |
| 10846 | "Connection: keep-alive\r\n" |
| 10847 | "Authorization: auth_token\r\n\r\n"); |
| 10848 | const MockWrite kGetProxyAuth( |
| 10849 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 10850 | "Host: www.example.com\r\n" |
| 10851 | "Proxy-Connection: keep-alive\r\n" |
| 10852 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 10853 | const MockWrite kGetAuthThroughProxy( |
| 10854 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 10855 | "Host: www.example.com\r\n" |
| 10856 | "Proxy-Connection: keep-alive\r\n" |
| 10857 | "Authorization: auth_token\r\n\r\n"); |
| 10858 | const MockWrite kGetAuthWithProxyAuth( |
| 10859 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 10860 | "Host: www.example.com\r\n" |
| 10861 | "Proxy-Connection: keep-alive\r\n" |
| 10862 | "Proxy-Authorization: auth_token\r\n" |
| 10863 | "Authorization: auth_token\r\n\r\n"); |
| 10864 | const MockWrite kConnect( |
| 10865 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 10866 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10867 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 10868 | const MockWrite kConnectProxyAuth( |
| 10869 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 10870 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10871 | "Proxy-Connection: keep-alive\r\n" |
| 10872 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 10873 | |
| 10874 | const MockRead kSuccess( |
| 10875 | "HTTP/1.1 200 OK\r\n" |
| 10876 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 10877 | "Content-Length: 3\r\n\r\n" |
| 10878 | "Yes"); |
| 10879 | const MockRead kFailure( |
| 10880 | "Should not be called."); |
| 10881 | const MockRead kServerChallenge( |
| 10882 | "HTTP/1.1 401 Unauthorized\r\n" |
| 10883 | "WWW-Authenticate: Mock realm=server\r\n" |
| 10884 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 10885 | "Content-Length: 14\r\n\r\n" |
| 10886 | "Unauthorized\r\n"); |
| 10887 | const MockRead kProxyChallenge( |
| 10888 | "HTTP/1.1 407 Unauthorized\r\n" |
| 10889 | "Proxy-Authenticate: Mock realm=proxy\r\n" |
| 10890 | "Proxy-Connection: close\r\n" |
| 10891 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 10892 | "Content-Length: 14\r\n\r\n" |
| 10893 | "Unauthorized\r\n"); |
| 10894 | const MockRead kProxyConnected( |
| 10895 | "HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 10896 | |
| 10897 | // NOTE(cbentzel): I wanted TestReadWriteRound to be a simple struct with |
| 10898 | // no constructors, but the C++ compiler on Windows warns about |
| 10899 | // unspecified data in compound literals. So, moved to using constructors, |
| 10900 | // and TestRound's created with the default constructor should not be used. |
| 10901 | struct TestRound { |
| 10902 | TestRound() |
| 10903 | : expected_rv(ERR_UNEXPECTED), |
| 10904 | extra_write(NULL), |
| 10905 | extra_read(NULL) { |
| 10906 | } |
| 10907 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 10908 | int expected_rv_arg) |
| 10909 | : write(write_arg), |
| 10910 | read(read_arg), |
| 10911 | expected_rv(expected_rv_arg), |
| 10912 | extra_write(NULL), |
| 10913 | extra_read(NULL) { |
| 10914 | } |
| 10915 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 10916 | int expected_rv_arg, const MockWrite* extra_write_arg, |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 10917 | const MockRead* extra_read_arg) |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10918 | : write(write_arg), |
| 10919 | read(read_arg), |
| 10920 | expected_rv(expected_rv_arg), |
| 10921 | extra_write(extra_write_arg), |
| 10922 | extra_read(extra_read_arg) { |
| 10923 | } |
| 10924 | MockWrite write; |
| 10925 | MockRead read; |
| 10926 | int expected_rv; |
| 10927 | const MockWrite* extra_write; |
| 10928 | const MockRead* extra_read; |
| 10929 | }; |
| 10930 | |
| 10931 | static const int kNoSSL = 500; |
| 10932 | |
| 10933 | struct TestConfig { |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 10934 | const char* const proxy_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10935 | AuthTiming proxy_auth_timing; |
| 10936 | int proxy_auth_rv; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 10937 | const char* const server_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10938 | AuthTiming server_auth_timing; |
| 10939 | int server_auth_rv; |
| 10940 | int num_auth_rounds; |
| 10941 | int first_ssl_round; |
| 10942 | TestRound rounds[3]; |
| 10943 | } test_configs[] = { |
| 10944 | // Non-authenticating HTTP server with a direct connection. |
| 10945 | { NULL, AUTH_NONE, OK, kServer, AUTH_NONE, OK, 1, kNoSSL, |
| 10946 | { TestRound(kGet, kSuccess, OK)}}, |
| 10947 | // Authenticating HTTP server with a direct connection. |
| 10948 | { NULL, AUTH_NONE, OK, kServer, AUTH_SYNC, OK, 2, kNoSSL, |
| 10949 | { TestRound(kGet, kServerChallenge, OK), |
| 10950 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 10951 | { NULL, AUTH_NONE, OK, kServer, AUTH_SYNC, kAuthErr, 2, kNoSSL, |
| 10952 | { TestRound(kGet, kServerChallenge, OK), |
| 10953 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 10954 | { NULL, AUTH_NONE, OK, kServer, AUTH_ASYNC, OK, 2, kNoSSL, |
| 10955 | { TestRound(kGet, kServerChallenge, OK), |
| 10956 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 10957 | { NULL, AUTH_NONE, OK, kServer, AUTH_ASYNC, kAuthErr, 2, kNoSSL, |
| 10958 | { TestRound(kGet, kServerChallenge, OK), |
| 10959 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 10960 | // Non-authenticating HTTP server through a non-authenticating proxy. |
| 10961 | { kProxy, AUTH_NONE, OK, kServer, AUTH_NONE, OK, 1, kNoSSL, |
| 10962 | { TestRound(kGetProxy, kSuccess, OK)}}, |
| 10963 | // Authenticating HTTP server through a non-authenticating proxy. |
| 10964 | { kProxy, AUTH_NONE, OK, kServer, AUTH_SYNC, OK, 2, kNoSSL, |
| 10965 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 10966 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
| 10967 | { kProxy, AUTH_NONE, OK, kServer, AUTH_SYNC, kAuthErr, 2, kNoSSL, |
| 10968 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 10969 | TestRound(kGetAuthThroughProxy, kFailure, kAuthErr)}}, |
| 10970 | { kProxy, AUTH_NONE, OK, kServer, AUTH_ASYNC, OK, 2, kNoSSL, |
| 10971 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 10972 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
| 10973 | { kProxy, AUTH_NONE, OK, kServer, AUTH_ASYNC, kAuthErr, 2, kNoSSL, |
| 10974 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 10975 | TestRound(kGetAuthThroughProxy, kFailure, kAuthErr)}}, |
| 10976 | // Non-authenticating HTTP server through an authenticating proxy. |
| 10977 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 10978 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10979 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
| 10980 | { kProxy, AUTH_SYNC, kAuthErr, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 10981 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10982 | TestRound(kGetProxyAuth, kFailure, kAuthErr)}}, |
| 10983 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 10984 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10985 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
| 10986 | { kProxy, AUTH_ASYNC, kAuthErr, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 10987 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10988 | TestRound(kGetProxyAuth, kFailure, kAuthErr)}}, |
| 10989 | // Authenticating HTTP server through an authenticating proxy. |
| 10990 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_SYNC, OK, 3, kNoSSL, |
| 10991 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10992 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 10993 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 10994 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_SYNC, kAuthErr, 3, kNoSSL, |
| 10995 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10996 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 10997 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 10998 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_SYNC, OK, 3, kNoSSL, |
| 10999 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11000 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11001 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 11002 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_SYNC, kAuthErr, 3, kNoSSL, |
| 11003 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11004 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11005 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 11006 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_ASYNC, OK, 3, kNoSSL, |
| 11007 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11008 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11009 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 11010 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_ASYNC, kAuthErr, 3, kNoSSL, |
| 11011 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11012 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11013 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 11014 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_ASYNC, OK, 3, kNoSSL, |
| 11015 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11016 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11017 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 11018 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_ASYNC, kAuthErr, 3, kNoSSL, |
| 11019 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11020 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11021 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 11022 | // Non-authenticating HTTPS server with a direct connection. |
| 11023 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_NONE, OK, 1, 0, |
| 11024 | { TestRound(kGet, kSuccess, OK)}}, |
| 11025 | // Authenticating HTTPS server with a direct connection. |
| 11026 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, OK, 2, 0, |
| 11027 | { TestRound(kGet, kServerChallenge, OK), |
| 11028 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11029 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, kAuthErr, 2, 0, |
| 11030 | { TestRound(kGet, kServerChallenge, OK), |
| 11031 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11032 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, OK, 2, 0, |
| 11033 | { TestRound(kGet, kServerChallenge, OK), |
| 11034 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11035 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 2, 0, |
| 11036 | { TestRound(kGet, kServerChallenge, OK), |
| 11037 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11038 | // Non-authenticating HTTPS server with a non-authenticating proxy. |
| 11039 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_NONE, OK, 1, 0, |
| 11040 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 11041 | // Authenticating HTTPS server through a non-authenticating proxy. |
| 11042 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, OK, 2, 0, |
| 11043 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 11044 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11045 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, kAuthErr, 2, 0, |
| 11046 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 11047 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11048 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, OK, 2, 0, |
| 11049 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 11050 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11051 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 2, 0, |
| 11052 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 11053 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11054 | // Non-Authenticating HTTPS server through an authenticating proxy. |
| 11055 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_NONE, OK, 2, 1, |
| 11056 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11057 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 11058 | { kProxy, AUTH_SYNC, kAuthErr, kSecureServer, AUTH_NONE, OK, 2, kNoSSL, |
| 11059 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11060 | TestRound(kConnectProxyAuth, kFailure, kAuthErr)}}, |
| 11061 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_NONE, OK, 2, 1, |
| 11062 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11063 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 11064 | { kProxy, AUTH_ASYNC, kAuthErr, kSecureServer, AUTH_NONE, OK, 2, kNoSSL, |
| 11065 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11066 | TestRound(kConnectProxyAuth, kFailure, kAuthErr)}}, |
| 11067 | // Authenticating HTTPS server through an authenticating proxy. |
| 11068 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_SYNC, OK, 3, 1, |
| 11069 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11070 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 11071 | &kGet, &kServerChallenge), |
| 11072 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11073 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_SYNC, kAuthErr, 3, 1, |
| 11074 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11075 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 11076 | &kGet, &kServerChallenge), |
| 11077 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11078 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_SYNC, OK, 3, 1, |
| 11079 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11080 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 11081 | &kGet, &kServerChallenge), |
| 11082 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11083 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_SYNC, kAuthErr, 3, 1, |
| 11084 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11085 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 11086 | &kGet, &kServerChallenge), |
| 11087 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11088 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_ASYNC, OK, 3, 1, |
| 11089 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11090 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 11091 | &kGet, &kServerChallenge), |
| 11092 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11093 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 3, 1, |
| 11094 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11095 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 11096 | &kGet, &kServerChallenge), |
| 11097 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11098 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_ASYNC, OK, 3, 1, |
| 11099 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11100 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 11101 | &kGet, &kServerChallenge), |
| 11102 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11103 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 3, 1, |
| 11104 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11105 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 11106 | &kGet, &kServerChallenge), |
| 11107 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11108 | }; |
| 11109 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 11110 | for (size_t i = 0; i < arraysize(test_configs); ++i) { |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 11111 | HttpAuthHandlerMock::Factory* auth_factory( |
| 11112 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11113 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11114 | const TestConfig& test_config = test_configs[i]; |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 11115 | |
| 11116 | // Set up authentication handlers as necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11117 | if (test_config.proxy_auth_timing != AUTH_NONE) { |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 11118 | for (int n = 0; n < 2; n++) { |
| 11119 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 11120 | std::string auth_challenge = "Mock realm=proxy"; |
| 11121 | GURL origin(test_config.proxy_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 11122 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 11123 | auth_challenge.end()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 11124 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_PROXY, |
| 11125 | origin, BoundNetLog()); |
| 11126 | auth_handler->SetGenerateExpectation( |
| 11127 | test_config.proxy_auth_timing == AUTH_ASYNC, |
| 11128 | test_config.proxy_auth_rv); |
| 11129 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
| 11130 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11131 | } |
| 11132 | if (test_config.server_auth_timing != AUTH_NONE) { |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 11133 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11134 | std::string auth_challenge = "Mock realm=server"; |
| 11135 | GURL origin(test_config.server_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 11136 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 11137 | auth_challenge.end()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11138 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
| 11139 | origin, BoundNetLog()); |
| 11140 | auth_handler->SetGenerateExpectation( |
| 11141 | test_config.server_auth_timing == AUTH_ASYNC, |
| 11142 | test_config.server_auth_rv); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 11143 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11144 | } |
| 11145 | if (test_config.proxy_url) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 11146 | session_deps_.proxy_service = |
| 11147 | ProxyService::CreateFixed(test_config.proxy_url); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11148 | } else { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 11149 | session_deps_.proxy_service = ProxyService::CreateDirect(); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11150 | } |
| 11151 | |
| 11152 | HttpRequestInfo request; |
| 11153 | request.method = "GET"; |
| 11154 | request.url = GURL(test_config.server_url); |
| 11155 | request.load_flags = 0; |
| 11156 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11157 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 11158 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11159 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11160 | SSLSocketDataProvider ssl_socket_data_provider(SYNCHRONOUS, OK); |
| 11161 | |
| 11162 | std::vector<std::vector<MockRead>> mock_reads(1); |
| 11163 | std::vector<std::vector<MockWrite>> mock_writes(1); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11164 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
| 11165 | const TestRound& read_write_round = test_config.rounds[round]; |
| 11166 | |
| 11167 | // Set up expected reads and writes. |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11168 | mock_reads.back().push_back(read_write_round.read); |
| 11169 | mock_writes.back().push_back(read_write_round.write); |
| 11170 | |
| 11171 | // kProxyChallenge uses Proxy-Connection: close which means that the |
| 11172 | // socket is closed and a new one will be created for the next request. |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 11173 | if (read_write_round.read.data == kProxyChallenge.data) { |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11174 | mock_reads.push_back(std::vector<MockRead>()); |
| 11175 | mock_writes.push_back(std::vector<MockWrite>()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11176 | } |
| 11177 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11178 | if (read_write_round.extra_read) { |
| 11179 | mock_reads.back().push_back(*read_write_round.extra_read); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11180 | } |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11181 | if (read_write_round.extra_write) { |
| 11182 | mock_writes.back().push_back(*read_write_round.extra_write); |
| 11183 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11184 | |
| 11185 | // Add an SSL sequence if necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11186 | if (round >= test_config.first_ssl_round) |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11187 | session_deps_.socket_factory->AddSSLSocketDataProvider( |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11188 | &ssl_socket_data_provider); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11189 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11190 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11191 | ScopedVector<StaticSocketDataProvider> data_providers; |
| 11192 | for (size_t i = 0; i < mock_reads.size(); ++i) { |
| 11193 | data_providers.push_back(new StaticSocketDataProvider( |
davidben | 5f8b6bc | 2015-11-25 03:19:54 | [diff] [blame] | 11194 | mock_reads[i].data(), mock_reads[i].size(), mock_writes[i].data(), |
| 11195 | mock_writes[i].size())); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11196 | session_deps_.socket_factory->AddSocketDataProvider( |
| 11197 | data_providers.back()); |
| 11198 | } |
| 11199 | |
| 11200 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
| 11201 | const TestRound& read_write_round = test_config.rounds[round]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11202 | // Start or restart the transaction. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11203 | TestCompletionCallback callback; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11204 | int rv; |
| 11205 | if (round == 0) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11206 | rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11207 | } else { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11208 | rv = trans.RestartWithAuth( |
| 11209 | AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11210 | } |
| 11211 | if (rv == ERR_IO_PENDING) |
| 11212 | rv = callback.WaitForResult(); |
| 11213 | |
| 11214 | // Compare results with expected data. |
| 11215 | EXPECT_EQ(read_write_round.expected_rv, rv); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11216 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | c0c82849 | 2015-05-15 01:25:55 | [diff] [blame] | 11217 | if (read_write_round.expected_rv != OK) { |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11218 | EXPECT_EQ(round + 1, test_config.num_auth_rounds); |
| 11219 | continue; |
| 11220 | } |
| 11221 | if (round + 1 < test_config.num_auth_rounds) { |
| 11222 | EXPECT_FALSE(response->auth_challenge.get() == NULL); |
| 11223 | } else { |
| 11224 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 11225 | } |
| 11226 | } |
[email protected] | e5ae96a | 2010-04-14 20:12:45 | [diff] [blame] | 11227 | } |
| 11228 | } |
| 11229 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11230 | TEST_P(HttpNetworkTransactionTest, MultiRoundAuth) { |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11231 | // Do multi-round authentication and make sure it works correctly. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11232 | HttpAuthHandlerMock::Factory* auth_factory( |
| 11233 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11234 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 11235 | session_deps_.proxy_service = ProxyService::CreateDirect(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11236 | session_deps_.host_resolver->rules()->AddRule("www.example.com", "10.0.0.1"); |
| 11237 | session_deps_.host_resolver->set_synchronous_mode(true); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11238 | |
| 11239 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 11240 | auth_handler->set_connection_based(true); |
| 11241 | std::string auth_challenge = "Mock realm=server"; |
| 11242 | GURL origin("http://www.example.com"); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 11243 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 11244 | auth_challenge.end()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11245 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
| 11246 | origin, BoundNetLog()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 11247 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11248 | |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11249 | int rv = OK; |
| 11250 | const HttpResponseInfo* response = NULL; |
| 11251 | HttpRequestInfo request; |
| 11252 | request.method = "GET"; |
| 11253 | request.url = origin; |
| 11254 | request.load_flags = 0; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11255 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11256 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11257 | |
| 11258 | // Use a TCP Socket Pool with only one connection per group. This is used |
| 11259 | // to validate that the TCP socket is not released to the pool between |
| 11260 | // each round of multi-round authentication. |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11261 | HttpNetworkSessionPeer session_peer(session.get()); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 11262 | TransportClientSocketPool* transport_pool = new TransportClientSocketPool( |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11263 | 50, // Max sockets for pool |
| 11264 | 1, // Max sockets per group |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11265 | session_deps_.host_resolver.get(), |
| 11266 | session_deps_.socket_factory.get(), |
| 11267 | session_deps_.net_log); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 11268 | scoped_ptr<MockClientSocketPoolManager> mock_pool_manager( |
| 11269 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 11270 | mock_pool_manager->SetTransportSocketPool(transport_pool); |
dcheng | e3d1ddc | 2014-10-15 19:30:51 | [diff] [blame] | 11271 | session_peer.SetClientSocketPoolManager(mock_pool_manager.Pass()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11272 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11273 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11274 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11275 | TestCompletionCallback callback; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11276 | |
| 11277 | const MockWrite kGet( |
| 11278 | "GET / HTTP/1.1\r\n" |
| 11279 | "Host: www.example.com\r\n" |
| 11280 | "Connection: keep-alive\r\n\r\n"); |
| 11281 | const MockWrite kGetAuth( |
| 11282 | "GET / HTTP/1.1\r\n" |
| 11283 | "Host: www.example.com\r\n" |
| 11284 | "Connection: keep-alive\r\n" |
| 11285 | "Authorization: auth_token\r\n\r\n"); |
| 11286 | |
| 11287 | const MockRead kServerChallenge( |
| 11288 | "HTTP/1.1 401 Unauthorized\r\n" |
| 11289 | "WWW-Authenticate: Mock realm=server\r\n" |
| 11290 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11291 | "Content-Length: 14\r\n\r\n" |
| 11292 | "Unauthorized\r\n"); |
| 11293 | const MockRead kSuccess( |
| 11294 | "HTTP/1.1 200 OK\r\n" |
| 11295 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11296 | "Content-Length: 3\r\n\r\n" |
| 11297 | "Yes"); |
| 11298 | |
| 11299 | MockWrite writes[] = { |
| 11300 | // First round |
| 11301 | kGet, |
| 11302 | // Second round |
| 11303 | kGetAuth, |
| 11304 | // Third round |
| 11305 | kGetAuth, |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 11306 | // Fourth round |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11307 | kGetAuth, |
| 11308 | // Competing request |
| 11309 | kGet, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11310 | }; |
| 11311 | MockRead reads[] = { |
| 11312 | // First round |
| 11313 | kServerChallenge, |
| 11314 | // Second round |
| 11315 | kServerChallenge, |
| 11316 | // Third round |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 11317 | kServerChallenge, |
| 11318 | // Fourth round |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11319 | kSuccess, |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11320 | // Competing response |
| 11321 | kSuccess, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11322 | }; |
| 11323 | StaticSocketDataProvider data_provider(reads, arraysize(reads), |
| 11324 | writes, arraysize(writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11325 | session_deps_.socket_factory->AddSocketDataProvider(&data_provider); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11326 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 11327 | const char kSocketGroup[] = "www.example.com:80"; |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11328 | |
| 11329 | // First round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11330 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11331 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11332 | if (rv == ERR_IO_PENDING) |
| 11333 | rv = callback.WaitForResult(); |
| 11334 | EXPECT_EQ(OK, rv); |
| 11335 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 11336 | ASSERT_TRUE(response != NULL); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11337 | EXPECT_FALSE(response->auth_challenge.get() == NULL); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 11338 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11339 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11340 | // In between rounds, another request comes in for the same domain. |
| 11341 | // It should not be able to grab the TCP socket that trans has already |
| 11342 | // claimed. |
| 11343 | scoped_ptr<HttpTransaction> trans_compete( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11344 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11345 | TestCompletionCallback callback_compete; |
| 11346 | rv = trans_compete->Start( |
| 11347 | &request, callback_compete.callback(), BoundNetLog()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11348 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11349 | // callback_compete.WaitForResult at this point would stall forever, |
| 11350 | // since the HttpNetworkTransaction does not release the request back to |
| 11351 | // the pool until after authentication completes. |
| 11352 | |
| 11353 | // Second round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11354 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11355 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11356 | if (rv == ERR_IO_PENDING) |
| 11357 | rv = callback.WaitForResult(); |
| 11358 | EXPECT_EQ(OK, rv); |
| 11359 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 11360 | ASSERT_TRUE(response != NULL); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11361 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 11362 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11363 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11364 | // Third round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11365 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11366 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11367 | if (rv == ERR_IO_PENDING) |
| 11368 | rv = callback.WaitForResult(); |
| 11369 | EXPECT_EQ(OK, rv); |
| 11370 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 11371 | ASSERT_TRUE(response != NULL); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11372 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 11373 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 11374 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11375 | // Fourth round of authentication, which completes successfully. |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 11376 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11377 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 11378 | if (rv == ERR_IO_PENDING) |
| 11379 | rv = callback.WaitForResult(); |
| 11380 | EXPECT_EQ(OK, rv); |
| 11381 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 11382 | ASSERT_TRUE(response != NULL); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 11383 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 11384 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11385 | |
| 11386 | // Read the body since the fourth round was successful. This will also |
| 11387 | // release the socket back to the pool. |
| 11388 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(50)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11389 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11390 | if (rv == ERR_IO_PENDING) |
| 11391 | rv = callback.WaitForResult(); |
| 11392 | EXPECT_EQ(3, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11393 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11394 | EXPECT_EQ(0, rv); |
| 11395 | // There are still 0 idle sockets, since the trans_compete transaction |
| 11396 | // will be handed it immediately after trans releases it to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 11397 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11398 | |
| 11399 | // The competing request can now finish. Wait for the headers and then |
| 11400 | // read the body. |
| 11401 | rv = callback_compete.WaitForResult(); |
| 11402 | EXPECT_EQ(OK, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11403 | rv = trans_compete->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11404 | if (rv == ERR_IO_PENDING) |
| 11405 | rv = callback.WaitForResult(); |
| 11406 | EXPECT_EQ(3, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11407 | rv = trans_compete->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11408 | EXPECT_EQ(0, rv); |
| 11409 | |
| 11410 | // Finally, the socket is released to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 11411 | EXPECT_EQ(1, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11412 | } |
| 11413 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11414 | // This tests the case that a request is issued via http instead of spdy after |
| 11415 | // npn is negotiated. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11416 | TEST_P(HttpNetworkTransactionTest, NpnWithHttpOverSSL) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11417 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 11418 | NextProtoVector next_protos; |
[email protected] | 0ce3af8 | 2013-07-22 16:17:16 | [diff] [blame] | 11419 | next_protos.push_back(kProtoHTTP11); |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 11420 | session_deps_.next_protos = next_protos; |
| 11421 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11422 | HttpRequestInfo request; |
| 11423 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11424 | request.url = GURL("https://www.example.org/"); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11425 | request.load_flags = 0; |
| 11426 | |
| 11427 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11428 | MockWrite( |
| 11429 | "GET / HTTP/1.1\r\n" |
| 11430 | "Host: www.example.org\r\n" |
| 11431 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11432 | }; |
| 11433 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 11434 | std::string alternate_protocol_http_header = |
| 11435 | GetAlternateProtocolHttpHeader(); |
| 11436 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11437 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11438 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 11439 | MockRead(alternate_protocol_http_header.c_str()), |
| 11440 | MockRead("\r\n"), |
| 11441 | MockRead("hello world"), |
| 11442 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11443 | }; |
| 11444 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11445 | SSLSocketDataProvider ssl(ASYNC, OK); |
davidben | 6974bf7 | 2015-04-27 17:52:48 | [diff] [blame] | 11446 | ssl.SetNextProto(kProtoHTTP11); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11447 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11448 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11449 | |
| 11450 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 11451 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11452 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11453 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11454 | TestCompletionCallback callback; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11455 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11456 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11457 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11458 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11459 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11460 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11461 | |
| 11462 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11463 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 11464 | |
| 11465 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 11466 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11467 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11468 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11469 | |
| 11470 | std::string response_data; |
| 11471 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 11472 | EXPECT_EQ("hello world", response_data); |
| 11473 | |
| 11474 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 11475 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11476 | } |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11477 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11478 | // Simulate the SSL handshake completing with an NPN negotiation followed by an |
| 11479 | // immediate server closing of the socket. |
| 11480 | // Regression test for https://crbug.com/46369. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11481 | TEST_P(HttpNetworkTransactionTest, SpdyPostNPNServerHangup) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11482 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 11483 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11484 | |
| 11485 | HttpRequestInfo request; |
| 11486 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11487 | request.url = GURL("https://www.example.org/"); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11488 | request.load_flags = 0; |
| 11489 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11490 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 11491 | ssl.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11492 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11493 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11494 | scoped_ptr<SpdyFrame> req( |
| 11495 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11496 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 1)}; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11497 | |
| 11498 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11499 | MockRead(SYNCHRONOUS, 0, 0) // Not async - return 0 immediately. |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11500 | }; |
| 11501 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11502 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 11503 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11504 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11505 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11506 | TestCompletionCallback callback; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11507 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11508 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11509 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11510 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11511 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11512 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11513 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11514 | EXPECT_EQ(ERR_CONNECTION_CLOSED, callback.WaitForResult()); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11515 | } |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 11516 | |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 11517 | // A subclass of HttpAuthHandlerMock that records the request URL when |
| 11518 | // it gets it. This is needed since the auth handler may get destroyed |
| 11519 | // before we get a chance to query it. |
| 11520 | class UrlRecordingHttpAuthHandlerMock : public HttpAuthHandlerMock { |
| 11521 | public: |
| 11522 | explicit UrlRecordingHttpAuthHandlerMock(GURL* url) : url_(url) {} |
| 11523 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11524 | ~UrlRecordingHttpAuthHandlerMock() override {} |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 11525 | |
| 11526 | protected: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11527 | int GenerateAuthTokenImpl(const AuthCredentials* credentials, |
| 11528 | const HttpRequestInfo* request, |
| 11529 | const CompletionCallback& callback, |
| 11530 | std::string* auth_token) override { |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 11531 | *url_ = request->url; |
| 11532 | return HttpAuthHandlerMock::GenerateAuthTokenImpl( |
| 11533 | credentials, request, callback, auth_token); |
| 11534 | } |
| 11535 | |
| 11536 | private: |
| 11537 | GURL* url_; |
| 11538 | }; |
| 11539 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11540 | // This test ensures that the URL passed into the proxy is upgraded to https |
| 11541 | // when doing an Alternate Protocol upgrade. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11542 | TEST_P(HttpNetworkTransactionTest, SpdyAlternateProtocolThroughProxy) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11543 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 11544 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11545 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 11546 | session_deps_.proxy_service = |
| 11547 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11548 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11549 | session_deps_.net_log = &net_log; |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 11550 | GURL request_url; |
| 11551 | { |
| 11552 | HttpAuthHandlerMock::Factory* auth_factory = |
| 11553 | new HttpAuthHandlerMock::Factory(); |
| 11554 | UrlRecordingHttpAuthHandlerMock* auth_handler = |
| 11555 | new UrlRecordingHttpAuthHandlerMock(&request_url); |
| 11556 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
| 11557 | auth_factory->set_do_init_from_challenge(true); |
| 11558 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
| 11559 | } |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11560 | |
| 11561 | HttpRequestInfo request; |
| 11562 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11563 | request.url = GURL("http://www.example.org"); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11564 | request.load_flags = 0; |
| 11565 | |
| 11566 | // First round goes unauthenticated through the proxy. |
| 11567 | MockWrite data_writes_1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11568 | MockWrite( |
| 11569 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 11570 | "Host: www.example.org\r\n" |
| 11571 | "Proxy-Connection: keep-alive\r\n" |
| 11572 | "\r\n"), |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11573 | }; |
| 11574 | MockRead data_reads_1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11575 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
bnc | 33b8cef4 | 2014-11-19 17:30:38 | [diff] [blame] | 11576 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 11577 | MockRead("Alternate-Protocol: 443:"), |
| 11578 | MockRead(GetAlternateProtocolFromParam()), |
| 11579 | MockRead("\r\n"), |
| 11580 | MockRead("Proxy-Connection: close\r\n"), |
| 11581 | MockRead("\r\n"), |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11582 | }; |
| 11583 | StaticSocketDataProvider data_1(data_reads_1, arraysize(data_reads_1), |
| 11584 | data_writes_1, arraysize(data_writes_1)); |
| 11585 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11586 | // Second round tries to tunnel to www.example.org due to the |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11587 | // Alternate-Protocol announcement in the first round. It fails due |
| 11588 | // to a proxy authentication challenge. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11589 | // After the failure, a tunnel is established to www.example.org using |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 11590 | // Proxy-Authorization headers. There is then a SPDY request round. |
| 11591 | // |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 11592 | // NOTE: Despite the "Proxy-Connection: Close", these are done on the |
| 11593 | // same MockTCPClientSocket since the underlying HttpNetworkClientSocket |
| 11594 | // does a Disconnect and Connect on the same socket, rather than trying |
| 11595 | // to obtain a new one. |
| 11596 | // |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 11597 | // NOTE: Originally, the proxy response to the second CONNECT request |
| 11598 | // simply returned another 407 so the unit test could skip the SSL connection |
| 11599 | // establishment and SPDY framing issues. Alas, the |
| 11600 | // retry-http-when-alternate-protocol fails logic kicks in, which was more |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11601 | // complicated to set up expectations for than the SPDY session. |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 11602 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11603 | scoped_ptr<SpdyFrame> req( |
| 11604 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11605 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11606 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11607 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 11608 | MockWrite data_writes_2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11609 | // First connection attempt without Proxy-Authorization. |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11610 | MockWrite(ASYNC, 0, |
| 11611 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 11612 | "Host: www.example.org:443\r\n" |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11613 | "Proxy-Connection: keep-alive\r\n" |
| 11614 | "\r\n"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 11615 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11616 | // Second connection attempt with Proxy-Authorization. |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11617 | MockWrite(ASYNC, 2, |
| 11618 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 11619 | "Host: www.example.org:443\r\n" |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11620 | "Proxy-Connection: keep-alive\r\n" |
| 11621 | "Proxy-Authorization: auth_token\r\n" |
| 11622 | "\r\n"), |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11623 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11624 | // SPDY request |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11625 | CreateMockWrite(*req, 4), |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11626 | }; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 11627 | MockRead data_reads_2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11628 | // First connection attempt fails |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 11629 | MockRead(ASYNC, 1, |
| 11630 | "HTTP/1.1 407 Unauthorized\r\n" |
| 11631 | "Proxy-Authenticate: Mock\r\n" |
| 11632 | "Content-Length: 0\r\n" |
| 11633 | "Proxy-Connection: keep-alive\r\n" |
| 11634 | "\r\n"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 11635 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11636 | // Second connection attempt passes |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 11637 | MockRead(ASYNC, 3, "HTTP/1.1 200 Connected\r\n\r\n"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 11638 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11639 | // SPDY response |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 11640 | CreateMockRead(*resp.get(), 5), CreateMockRead(*data.get(), 6), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11641 | MockRead(ASYNC, 0, 0, 7), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 11642 | }; |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11643 | SequencedSocketData data_2(data_reads_2, arraysize(data_reads_2), |
| 11644 | data_writes_2, arraysize(data_writes_2)); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11645 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11646 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 11647 | ssl.SetNextProto(GetProtocol()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11648 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 11649 | ASSERT_TRUE(ssl.cert.get()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11650 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11651 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11652 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 11653 | NULL, 0, NULL, 0); |
| 11654 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 11655 | never_finishing_connect); |
| 11656 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11657 | session_deps_.socket_factory->AddSocketDataProvider(&data_1); |
| 11658 | session_deps_.socket_factory->AddSocketDataProvider(&data_2); |
| 11659 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11660 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11661 | &hanging_non_alternate_protocol_socket); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11662 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11663 | |
| 11664 | // First round should work and provide the Alternate-Protocol state. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11665 | TestCompletionCallback callback_1; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11666 | scoped_ptr<HttpTransaction> trans_1( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11667 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11668 | int rv = trans_1->Start(&request, callback_1.callback(), BoundNetLog()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11669 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11670 | EXPECT_EQ(OK, callback_1.WaitForResult()); |
| 11671 | |
| 11672 | // Second round should attempt a tunnel connect and get an auth challenge. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11673 | TestCompletionCallback callback_2; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11674 | scoped_ptr<HttpTransaction> trans_2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11675 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11676 | rv = trans_2->Start(&request, callback_2.callback(), BoundNetLog()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11677 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11678 | EXPECT_EQ(OK, callback_2.WaitForResult()); |
| 11679 | const HttpResponseInfo* response = trans_2->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 11680 | ASSERT_TRUE(response != NULL); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11681 | ASSERT_FALSE(response->auth_challenge.get() == NULL); |
| 11682 | |
| 11683 | // Restart with auth. Tunnel should work and response received. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11684 | TestCompletionCallback callback_3; |
| 11685 | rv = trans_2->RestartWithAuth( |
| 11686 | AuthCredentials(kFoo, kBar), callback_3.callback()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11687 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11688 | EXPECT_EQ(OK, callback_3.WaitForResult()); |
| 11689 | |
| 11690 | // After all that work, these two lines (or actually, just the scheme) are |
| 11691 | // what this test is all about. Make sure it happens correctly. |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11692 | EXPECT_EQ("https", request_url.scheme()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11693 | EXPECT_EQ("www.example.org", request_url.host()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11694 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11695 | LoadTimingInfo load_timing_info; |
| 11696 | EXPECT_TRUE(trans_2->GetLoadTimingInfo(&load_timing_info)); |
| 11697 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 11698 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 11699 | } |
| 11700 | |
| 11701 | // Test that if we cancel the transaction as the connection is completing, that |
| 11702 | // everything tears down correctly. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11703 | TEST_P(HttpNetworkTransactionTest, SimpleCancel) { |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 11704 | // Setup everything about the connection to complete synchronously, so that |
| 11705 | // after calling HttpNetworkTransaction::Start, the only thing we're waiting |
| 11706 | // for is the callback from the HttpStreamRequest. |
| 11707 | // Then cancel the transaction. |
| 11708 | // Verify that we don't crash. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11709 | MockConnect mock_connect(SYNCHRONOUS, OK); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 11710 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11711 | MockRead(SYNCHRONOUS, "HTTP/1.0 200 OK\r\n\r\n"), |
| 11712 | MockRead(SYNCHRONOUS, "hello world"), |
| 11713 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 11714 | }; |
| 11715 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 11716 | HttpRequestInfo request; |
| 11717 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11718 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 11719 | request.load_flags = 0; |
| 11720 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11721 | session_deps_.host_resolver->set_synchronous_mode(true); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11722 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11723 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 11724 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11725 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 11726 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 11727 | data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11728 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 11729 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11730 | TestCompletionCallback callback; |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 11731 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11732 | BoundTestNetLog log; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11733 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 11734 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11735 | trans.reset(); // Cancel the transaction here. |
| 11736 | |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 11737 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11738 | } |
| 11739 | |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 11740 | // Test that if a transaction is cancelled after receiving the headers, the |
| 11741 | // stream is drained properly and added back to the socket pool. The main |
| 11742 | // purpose of this test is to make sure that an HttpStreamParser can be read |
| 11743 | // from after the HttpNetworkTransaction and the objects it owns have been |
| 11744 | // deleted. |
| 11745 | // See http://crbug.com/368418 |
| 11746 | TEST_P(HttpNetworkTransactionTest, CancelAfterHeaders) { |
| 11747 | MockRead data_reads[] = { |
| 11748 | MockRead(ASYNC, "HTTP/1.1 200 OK\r\n"), |
| 11749 | MockRead(ASYNC, "Content-Length: 2\r\n"), |
| 11750 | MockRead(ASYNC, "Connection: Keep-Alive\r\n\r\n"), |
| 11751 | MockRead(ASYNC, "1"), |
| 11752 | // 2 async reads are necessary to trigger a ReadResponseBody call after the |
| 11753 | // HttpNetworkTransaction has been deleted. |
| 11754 | MockRead(ASYNC, "2"), |
| 11755 | MockRead(SYNCHRONOUS, ERR_IO_PENDING), // Should never read this. |
| 11756 | }; |
| 11757 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 11758 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11759 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11760 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 11761 | |
| 11762 | { |
| 11763 | HttpRequestInfo request; |
| 11764 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11765 | request.url = GURL("http://www.example.org/"); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 11766 | request.load_flags = 0; |
| 11767 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 11768 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 11769 | TestCompletionCallback callback; |
| 11770 | |
| 11771 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
| 11772 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11773 | callback.WaitForResult(); |
| 11774 | |
| 11775 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 11776 | ASSERT_TRUE(response != NULL); |
| 11777 | EXPECT_TRUE(response->headers.get() != NULL); |
| 11778 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11779 | |
| 11780 | // The transaction and HttpRequestInfo are deleted. |
| 11781 | } |
| 11782 | |
| 11783 | // Let the HttpResponseBodyDrainer drain the socket. |
| 11784 | base::MessageLoop::current()->RunUntilIdle(); |
| 11785 | |
| 11786 | // Socket should now be idle, waiting to be reused. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 11787 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 11788 | } |
| 11789 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11790 | // Test a basic GET request through a proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11791 | TEST_P(HttpNetworkTransactionTest, ProxyGet) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 11792 | session_deps_.proxy_service = |
| 11793 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11794 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11795 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11796 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11797 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11798 | HttpRequestInfo request; |
| 11799 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11800 | request.url = GURL("http://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11801 | |
| 11802 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11803 | MockWrite( |
| 11804 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 11805 | "Host: www.example.org\r\n" |
| 11806 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11807 | }; |
| 11808 | |
| 11809 | MockRead data_reads1[] = { |
| 11810 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 11811 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 11812 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11813 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11814 | }; |
| 11815 | |
| 11816 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 11817 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11818 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11819 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11820 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11821 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11822 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11823 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 11824 | BeforeProxyHeadersSentHandler proxy_headers_handler; |
| 11825 | trans->SetBeforeProxyHeadersSentCallback( |
| 11826 | base::Bind(&BeforeProxyHeadersSentHandler::OnBeforeProxyHeadersSent, |
| 11827 | base::Unretained(&proxy_headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11828 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11829 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11830 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11831 | |
| 11832 | rv = callback1.WaitForResult(); |
| 11833 | EXPECT_EQ(OK, rv); |
| 11834 | |
| 11835 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 11836 | ASSERT_TRUE(response != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11837 | |
| 11838 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 11839 | EXPECT_EQ(200, response->headers->response_code()); |
| 11840 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 11841 | EXPECT_TRUE(response->was_fetched_via_proxy); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 11842 | EXPECT_TRUE( |
| 11843 | response->proxy_server.Equals(HostPortPair::FromString("myproxy:70"))); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 11844 | EXPECT_TRUE(proxy_headers_handler.observed_before_proxy_headers_sent()); |
| 11845 | EXPECT_EQ("myproxy:70", proxy_headers_handler.observed_proxy_server_uri()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11846 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11847 | |
| 11848 | LoadTimingInfo load_timing_info; |
| 11849 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 11850 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 11851 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11852 | } |
| 11853 | |
| 11854 | // Test a basic HTTPS GET request through a proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11855 | TEST_P(HttpNetworkTransactionTest, ProxyTunnelGet) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 11856 | session_deps_.proxy_service = |
| 11857 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11858 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11859 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11860 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11861 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11862 | HttpRequestInfo request; |
| 11863 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11864 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11865 | |
| 11866 | // Since we have proxy, should try to establish tunnel. |
| 11867 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 11868 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 11869 | "Host: www.example.org:443\r\n" |
| 11870 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11871 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 11872 | MockWrite("GET / HTTP/1.1\r\n" |
| 11873 | "Host: www.example.org\r\n" |
| 11874 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11875 | }; |
| 11876 | |
| 11877 | MockRead data_reads1[] = { |
| 11878 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 11879 | |
| 11880 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 11881 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 11882 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11883 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11884 | }; |
| 11885 | |
| 11886 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 11887 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11888 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11889 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11890 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11891 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11892 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11893 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11894 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11895 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11896 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11897 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11898 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11899 | |
| 11900 | rv = callback1.WaitForResult(); |
| 11901 | EXPECT_EQ(OK, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 11902 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 11903 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11904 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 11905 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11906 | NetLog::PHASE_NONE); |
| 11907 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 11908 | entries, pos, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11909 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 11910 | NetLog::PHASE_NONE); |
| 11911 | |
| 11912 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 11913 | ASSERT_TRUE(response != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11914 | |
| 11915 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 11916 | EXPECT_EQ(200, response->headers->response_code()); |
| 11917 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 11918 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 11919 | EXPECT_TRUE(response->was_fetched_via_proxy); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 11920 | EXPECT_TRUE( |
| 11921 | response->proxy_server.Equals(HostPortPair::FromString("myproxy:70"))); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11922 | |
| 11923 | LoadTimingInfo load_timing_info; |
| 11924 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 11925 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 11926 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11927 | } |
| 11928 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 11929 | // Test a basic HTTPS GET request through a proxy, connecting to an IPv6 |
| 11930 | // literal host. |
| 11931 | TEST_P(HttpNetworkTransactionTest, ProxyTunnelGetIPv6) { |
| 11932 | session_deps_.proxy_service = |
| 11933 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 11934 | BoundTestNetLog log; |
| 11935 | session_deps_.net_log = log.bound().net_log(); |
| 11936 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 11937 | |
| 11938 | HttpRequestInfo request; |
| 11939 | request.method = "GET"; |
| 11940 | request.url = GURL("https://[::1]:443/"); |
| 11941 | |
| 11942 | // Since we have proxy, should try to establish tunnel. |
| 11943 | MockWrite data_writes1[] = { |
| 11944 | MockWrite("CONNECT [::1]:443 HTTP/1.1\r\n" |
| 11945 | "Host: [::1]:443\r\n" |
| 11946 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 11947 | |
| 11948 | MockWrite("GET / HTTP/1.1\r\n" |
| 11949 | "Host: [::1]\r\n" |
| 11950 | "Connection: keep-alive\r\n\r\n"), |
| 11951 | }; |
| 11952 | |
| 11953 | MockRead data_reads1[] = { |
| 11954 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 11955 | |
| 11956 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 11957 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 11958 | MockRead("Content-Length: 100\r\n\r\n"), |
| 11959 | MockRead(SYNCHRONOUS, OK), |
| 11960 | }; |
| 11961 | |
| 11962 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 11963 | data_writes1, arraysize(data_writes1)); |
| 11964 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 11965 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 11966 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11967 | |
| 11968 | TestCompletionCallback callback1; |
| 11969 | |
| 11970 | scoped_ptr<HttpTransaction> trans( |
| 11971 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 11972 | |
| 11973 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 11974 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11975 | |
| 11976 | rv = callback1.WaitForResult(); |
| 11977 | EXPECT_EQ(OK, rv); |
| 11978 | TestNetLogEntry::List entries; |
| 11979 | log.GetEntries(&entries); |
| 11980 | size_t pos = ExpectLogContainsSomewhere( |
| 11981 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 11982 | NetLog::PHASE_NONE); |
| 11983 | ExpectLogContainsSomewhere( |
| 11984 | entries, pos, NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 11985 | NetLog::PHASE_NONE); |
| 11986 | |
| 11987 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 11988 | ASSERT_TRUE(response != NULL); |
| 11989 | |
| 11990 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 11991 | EXPECT_EQ(200, response->headers->response_code()); |
| 11992 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 11993 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 11994 | EXPECT_TRUE(response->was_fetched_via_proxy); |
| 11995 | EXPECT_TRUE( |
| 11996 | response->proxy_server.Equals(HostPortPair::FromString("myproxy:70"))); |
| 11997 | |
| 11998 | LoadTimingInfo load_timing_info; |
| 11999 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 12000 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 12001 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 12002 | } |
| 12003 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12004 | // Test a basic HTTPS GET request through a proxy, but the server hangs up |
| 12005 | // while establishing the tunnel. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12006 | TEST_P(HttpNetworkTransactionTest, ProxyTunnelGetHangup) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12007 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12008 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12009 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12010 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12011 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12012 | HttpRequestInfo request; |
| 12013 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12014 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12015 | |
| 12016 | // Since we have proxy, should try to establish tunnel. |
| 12017 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12018 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 12019 | "Host: www.example.org:443\r\n" |
| 12020 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12021 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12022 | MockWrite("GET / HTTP/1.1\r\n" |
| 12023 | "Host: www.example.org\r\n" |
| 12024 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12025 | }; |
| 12026 | |
| 12027 | MockRead data_reads1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12028 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12029 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12030 | MockRead(ASYNC, 0, 0), // EOF |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12031 | }; |
| 12032 | |
| 12033 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 12034 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12035 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12036 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12037 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12038 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12039 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12040 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 12041 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12042 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 12043 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12044 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12045 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12046 | |
| 12047 | rv = callback1.WaitForResult(); |
| 12048 | EXPECT_EQ(ERR_EMPTY_RESPONSE, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 12049 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 12050 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12051 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 12052 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12053 | NetLog::PHASE_NONE); |
| 12054 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 12055 | entries, pos, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12056 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 12057 | NetLog::PHASE_NONE); |
| 12058 | } |
| 12059 | |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12060 | // Test for crbug.com/55424. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12061 | TEST_P(HttpNetworkTransactionTest, PreconnectWithExistingSpdySession) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12062 | scoped_ptr<SpdyFrame> req( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12063 | spdy_util_.ConstructSpdyGet("https://www.example.org", false, 1, LOWEST)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12064 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12065 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12066 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12067 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12068 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12069 | CreateMockRead(*resp, 1), CreateMockRead(*data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12070 | }; |
| 12071 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12072 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 12073 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12074 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12075 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12076 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 12077 | ssl.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12078 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12079 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12080 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12081 | |
| 12082 | // Set up an initial SpdySession in the pool to reuse. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12083 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 12084 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 12085 | PRIVACY_MODE_DISABLED); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 12086 | base::WeakPtr<SpdySession> spdy_session = |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12087 | CreateInsecureSpdySession(session.get(), key, BoundNetLog()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12088 | |
| 12089 | HttpRequestInfo request; |
| 12090 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12091 | request.url = GURL("https://www.example.org/"); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12092 | request.load_flags = 0; |
| 12093 | |
| 12094 | // This is the important line that marks this as a preconnect. |
| 12095 | request.motivation = HttpRequestInfo::PRECONNECT_MOTIVATED; |
| 12096 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 12097 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12098 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12099 | |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 12100 | TestCompletionCallback callback; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12101 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12102 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12103 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12104 | } |
| 12105 | |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 12106 | // Given a net error, cause that error to be returned from the first Write() |
| 12107 | // call and verify that the HttpTransaction fails with that error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12108 | void HttpNetworkTransactionTest::CheckErrorIsPassedBack( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12109 | int error, IoMode mode) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12110 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12111 | request_info.url = GURL("https://www.example.com/"); |
| 12112 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12113 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12114 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12115 | SSLSocketDataProvider ssl_data(mode, OK); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12116 | MockWrite data_writes[] = { |
| 12117 | MockWrite(mode, error), |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 12118 | }; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12119 | StaticSocketDataProvider data(NULL, 0, data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12120 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12121 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 12122 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12123 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 12124 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12125 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 12126 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12127 | TestCompletionCallback callback; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12128 | int rv = trans->Start(&request_info, callback.callback(), BoundNetLog()); |
| 12129 | if (rv == ERR_IO_PENDING) |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 12130 | rv = callback.WaitForResult(); |
| 12131 | ASSERT_EQ(error, rv); |
| 12132 | } |
| 12133 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12134 | TEST_P(HttpNetworkTransactionTest, SSLWriteCertError) { |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 12135 | // Just check a grab bag of cert errors. |
| 12136 | static const int kErrors[] = { |
| 12137 | ERR_CERT_COMMON_NAME_INVALID, |
| 12138 | ERR_CERT_AUTHORITY_INVALID, |
| 12139 | ERR_CERT_DATE_INVALID, |
| 12140 | }; |
| 12141 | for (size_t i = 0; i < arraysize(kErrors); i++) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12142 | CheckErrorIsPassedBack(kErrors[i], ASYNC); |
| 12143 | CheckErrorIsPassedBack(kErrors[i], SYNCHRONOUS); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 12144 | } |
| 12145 | } |
| 12146 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12147 | // Ensure that a client certificate is removed from the SSL client auth |
| 12148 | // cache when: |
| 12149 | // 1) No proxy is involved. |
| 12150 | // 2) TLS False Start is disabled. |
| 12151 | // 3) The initial TLS handshake requests a client certificate. |
| 12152 | // 4) The client supplies an invalid/unacceptable certificate. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12153 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 12154 | ClientAuthCertCache_Direct_NoFalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12155 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12156 | request_info.url = GURL("https://www.example.com/"); |
| 12157 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12158 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12159 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12160 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12161 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12162 | |
| 12163 | // [ssl_]data1 contains the data for the first SSL handshake. When a |
| 12164 | // CertificateRequest is received for the first time, the handshake will |
| 12165 | // be aborted to allow the caller to provide a certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12166 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12167 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12168 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12169 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12170 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12171 | |
| 12172 | // [ssl_]data2 contains the data for the second SSL handshake. When TLS |
| 12173 | // False Start is not being used, the result of the SSL handshake will be |
| 12174 | // returned as part of the SSLClientSocket::Connect() call. This test |
| 12175 | // matches the result of a server sending a handshake_failure alert, |
| 12176 | // rather than a Finished message, because it requires a client |
| 12177 | // certificate and none was supplied. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12178 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12179 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12180 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12181 | StaticSocketDataProvider data2(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12182 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12183 | |
| 12184 | // [ssl_]data3 contains the data for the third SSL handshake. When a |
| 12185 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 12186 | // HttpNetworkTransaction will attempt to fallback to TLSv1.1 if the previous |
| 12187 | // connection was attempted with TLSv1.2. This is transparent to the caller |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12188 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 12189 | // requiring a client certificate, this fallback handshake should also |
| 12190 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12191 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12192 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12193 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12194 | StaticSocketDataProvider data3(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12195 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12196 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12197 | // [ssl_]data4 contains the data for the fourth SSL handshake. When a |
| 12198 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 12199 | // HttpNetworkTransaction will attempt to fallback to TLSv1 if the previous |
| 12200 | // connection was attempted with TLSv1.1. This is transparent to the caller |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12201 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 12202 | // requiring a client certificate, this fallback handshake should also |
| 12203 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12204 | SSLSocketDataProvider ssl_data4(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12205 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12206 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12207 | StaticSocketDataProvider data4(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12208 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12209 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12210 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 12211 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12212 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12213 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12214 | // Begin the SSL handshake with the peer. This consumes ssl_data1. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12215 | TestCompletionCallback callback; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12216 | int rv = trans->Start(&request_info, callback.callback(), BoundNetLog()); |
| 12217 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12218 | |
| 12219 | // Complete the SSL handshake, which should abort due to requiring a |
| 12220 | // client certificate. |
| 12221 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12222 | ASSERT_EQ(ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12223 | |
| 12224 | // Indicate that no certificate should be supplied. From the perspective |
| 12225 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 12226 | // certificate, so this is the same as supply a |
| 12227 | // legitimate-but-unacceptable certificate. |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12228 | rv = trans->RestartWithCertificate(NULL, NULL, callback.callback()); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12229 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12230 | |
| 12231 | // Ensure the certificate was added to the client auth cache before |
| 12232 | // allowing the connection to continue restarting. |
| 12233 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12234 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12235 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12236 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12237 | ASSERT_EQ(NULL, client_cert.get()); |
| 12238 | |
| 12239 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12240 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 12241 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12242 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12243 | ASSERT_EQ(ERR_SSL_PROTOCOL_ERROR, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12244 | |
| 12245 | // Ensure that the client certificate is removed from the cache on a |
| 12246 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12247 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12248 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12249 | } |
| 12250 | |
| 12251 | // Ensure that a client certificate is removed from the SSL client auth |
| 12252 | // cache when: |
| 12253 | // 1) No proxy is involved. |
| 12254 | // 2) TLS False Start is enabled. |
| 12255 | // 3) The initial TLS handshake requests a client certificate. |
| 12256 | // 4) The client supplies an invalid/unacceptable certificate. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12257 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 12258 | ClientAuthCertCache_Direct_FalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12259 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12260 | request_info.url = GURL("https://www.example.com/"); |
| 12261 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12262 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12263 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12264 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12265 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12266 | |
| 12267 | // When TLS False Start is used, SSLClientSocket::Connect() calls will |
| 12268 | // return successfully after reading up to the peer's Certificate message. |
| 12269 | // This is to allow the caller to call SSLClientSocket::Write(), which can |
| 12270 | // enqueue application data to be sent in the same packet as the |
| 12271 | // ChangeCipherSpec and Finished messages. |
| 12272 | // The actual handshake will be finished when SSLClientSocket::Read() is |
| 12273 | // called, which expects to process the peer's ChangeCipherSpec and |
| 12274 | // Finished messages. If there was an error negotiating with the peer, |
| 12275 | // such as due to the peer requiring a client certificate when none was |
| 12276 | // supplied, the alert sent by the peer won't be processed until Read() is |
| 12277 | // called. |
| 12278 | |
| 12279 | // Like the non-False Start case, when a client certificate is requested by |
| 12280 | // the peer, the handshake is aborted during the Connect() call. |
| 12281 | // [ssl_]data1 represents the initial SSL handshake with the peer. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12282 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12283 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12284 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12285 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12286 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12287 | |
| 12288 | // When a client certificate is supplied, Connect() will not be aborted |
| 12289 | // when the peer requests the certificate. Instead, the handshake will |
| 12290 | // artificially succeed, allowing the caller to write the HTTP request to |
| 12291 | // the socket. The handshake messages are not processed until Read() is |
| 12292 | // called, which then detects that the handshake was aborted, due to the |
| 12293 | // peer sending a handshake_failure because it requires a client |
| 12294 | // certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12295 | SSLSocketDataProvider ssl_data2(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12296 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12297 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12298 | MockRead data2_reads[] = { |
| 12299 | MockRead(ASYNC /* async */, ERR_SSL_PROTOCOL_ERROR), |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12300 | }; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12301 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12302 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12303 | |
| 12304 | // As described in ClientAuthCertCache_Direct_NoFalseStart, [ssl_]data3 is |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12305 | // the data for the SSL handshake once the TLSv1.1 connection falls back to |
| 12306 | // TLSv1. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12307 | SSLSocketDataProvider ssl_data3(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12308 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12309 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12310 | StaticSocketDataProvider data3(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12311 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12312 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12313 | // [ssl_]data4 is the data for the SSL handshake once the TLSv1 connection |
| 12314 | // falls back to SSLv3. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12315 | SSLSocketDataProvider ssl_data4(ASYNC, OK); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12316 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12317 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12318 | StaticSocketDataProvider data4(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12319 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12320 | |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 12321 | // Need one more if TLSv1.2 is enabled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12322 | SSLSocketDataProvider ssl_data5(ASYNC, OK); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 12323 | ssl_data5.cert_request_info = cert_request.get(); |
| 12324 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data5); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12325 | StaticSocketDataProvider data5(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 12326 | session_deps_.socket_factory->AddSocketDataProvider(&data5); |
| 12327 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12328 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 12329 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12330 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12331 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12332 | // Begin the initial SSL handshake. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12333 | TestCompletionCallback callback; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12334 | int rv = trans->Start(&request_info, callback.callback(), BoundNetLog()); |
| 12335 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12336 | |
| 12337 | // Complete the SSL handshake, which should abort due to requiring a |
| 12338 | // client certificate. |
| 12339 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12340 | ASSERT_EQ(ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12341 | |
| 12342 | // Indicate that no certificate should be supplied. From the perspective |
| 12343 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 12344 | // certificate, so this is the same as supply a |
| 12345 | // legitimate-but-unacceptable certificate. |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12346 | rv = trans->RestartWithCertificate(NULL, NULL, callback.callback()); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12347 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12348 | |
| 12349 | // Ensure the certificate was added to the client auth cache before |
| 12350 | // allowing the connection to continue restarting. |
| 12351 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12352 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12353 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12354 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12355 | ASSERT_EQ(NULL, client_cert.get()); |
| 12356 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12357 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12358 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 12359 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12360 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12361 | ASSERT_EQ(ERR_SSL_PROTOCOL_ERROR, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12362 | |
| 12363 | // Ensure that the client certificate is removed from the cache on a |
| 12364 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12365 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12366 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12367 | } |
| 12368 | |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12369 | // Ensure that a client certificate is removed from the SSL client auth |
| 12370 | // cache when: |
| 12371 | // 1) An HTTPS proxy is involved. |
| 12372 | // 3) The HTTPS proxy requests a client certificate. |
| 12373 | // 4) The client supplies an invalid/unacceptable certificate for the |
| 12374 | // proxy. |
| 12375 | // The test is repeated twice, first for connecting to an HTTPS endpoint, |
| 12376 | // then for connecting to an HTTP endpoint. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12377 | TEST_P(HttpNetworkTransactionTest, ClientAuthCertCache_Proxy_Fail) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12378 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12379 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12380 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12381 | |
| 12382 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12383 | cert_request->host_and_port = HostPortPair("proxy", 70); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12384 | |
| 12385 | // See ClientAuthCertCache_Direct_NoFalseStart for the explanation of |
| 12386 | // [ssl_]data[1-3]. Rather than represending the endpoint |
| 12387 | // (www.example.com:443), they represent failures with the HTTPS proxy |
| 12388 | // (proxy:70). |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12389 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12390 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12391 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12392 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12393 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12394 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12395 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12396 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12397 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12398 | StaticSocketDataProvider data2(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12399 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12400 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12401 | // TODO(wtc): find out why this unit test doesn't need [ssl_]data3. |
| 12402 | #if 0 |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12403 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12404 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12405 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12406 | StaticSocketDataProvider data3(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12407 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12408 | #endif |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12409 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12410 | HttpRequestInfo requests[2]; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12411 | requests[0].url = GURL("https://www.example.com/"); |
| 12412 | requests[0].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12413 | requests[0].load_flags = LOAD_NORMAL; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12414 | |
| 12415 | requests[1].url = GURL("http://www.example.com/"); |
| 12416 | requests[1].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12417 | requests[1].load_flags = LOAD_NORMAL; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12418 | |
| 12419 | for (size_t i = 0; i < arraysize(requests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12420 | session_deps_.socket_factory->ResetNextMockIndexes(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12421 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12422 | scoped_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12423 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12424 | |
| 12425 | // Begin the SSL handshake with the proxy. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12426 | TestCompletionCallback callback; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12427 | int rv = trans->Start(&requests[i], callback.callback(), BoundNetLog()); |
| 12428 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12429 | |
| 12430 | // Complete the SSL handshake, which should abort due to requiring a |
| 12431 | // client certificate. |
| 12432 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12433 | ASSERT_EQ(ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12434 | |
| 12435 | // Indicate that no certificate should be supplied. From the perspective |
| 12436 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 12437 | // certificate, so this is the same as supply a |
| 12438 | // legitimate-but-unacceptable certificate. |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12439 | rv = trans->RestartWithCertificate(NULL, NULL, callback.callback()); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12440 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12441 | |
| 12442 | // Ensure the certificate was added to the client auth cache before |
| 12443 | // allowing the connection to continue restarting. |
| 12444 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12445 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12446 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12447 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12448 | ASSERT_EQ(NULL, client_cert.get()); |
| 12449 | // Ensure the certificate was NOT cached for the endpoint. This only |
| 12450 | // applies to HTTPS requests, but is fine to check for HTTP requests. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12451 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12452 | HostPortPair("www.example.com", 443), &client_cert, |
| 12453 | &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12454 | |
| 12455 | // Restart the handshake. This will consume ssl_data2, which fails, and |
| 12456 | // then consume ssl_data3, which should also fail. The result code is |
| 12457 | // checked against what ssl_data3 should return. |
| 12458 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12459 | ASSERT_EQ(ERR_PROXY_CONNECTION_FAILED, rv); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12460 | |
| 12461 | // Now that the new handshake has failed, ensure that the client |
| 12462 | // certificate was removed from the client auth cache. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12463 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12464 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12465 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12466 | HostPortPair("www.example.com", 443), &client_cert, |
| 12467 | &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12468 | } |
| 12469 | } |
| 12470 | |
mmenke | 5c64213 | 2015-06-02 16:05:13 | [diff] [blame] | 12471 | TEST_P(HttpNetworkTransactionTest, UseIPConnectionPooling) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12472 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 12473 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12474 | |
| 12475 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12476 | session_deps_.host_resolver.reset(new MockCachingHostResolver()); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12477 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | b9ec688 | 2011-07-01 07:40:26 | [diff] [blame] | 12478 | SpdySessionPoolPeer pool_peer(session->spdy_session_pool()); |
| 12479 | pool_peer.DisableDomainAuthenticationVerification(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12480 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12481 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 12482 | ssl.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12483 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12484 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12485 | scoped_ptr<SpdyFrame> host1_req( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12486 | spdy_util_.ConstructSpdyGet("https://www.example.org", false, 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 12487 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12488 | scoped_ptr<SpdyFrame> host2_req( |
| 12489 | spdy_util_.ConstructSpdyGet("https://www.gmail.com", false, 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12490 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12491 | CreateMockWrite(*host1_req, 0), CreateMockWrite(*host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12492 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12493 | scoped_ptr<SpdyFrame> host1_resp( |
| 12494 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12495 | scoped_ptr<SpdyFrame> host1_resp_body( |
| 12496 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 12497 | scoped_ptr<SpdyFrame> host2_resp( |
| 12498 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 12499 | scoped_ptr<SpdyFrame> host2_resp_body( |
| 12500 | spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12501 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12502 | CreateMockRead(*host1_resp, 1), |
| 12503 | CreateMockRead(*host1_resp_body, 2), |
| 12504 | CreateMockRead(*host2_resp, 4), |
| 12505 | CreateMockRead(*host2_resp_body, 5), |
| 12506 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12507 | }; |
| 12508 | |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12509 | IPAddressNumber ip; |
| 12510 | ASSERT_TRUE(ParseIPLiteralToNumber("127.0.0.1", &ip)); |
| 12511 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 12512 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12513 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 12514 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12515 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12516 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 12517 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12518 | HttpRequestInfo request1; |
| 12519 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12520 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12521 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12522 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12523 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12524 | int rv = trans1.Start(&request1, callback.callback(), BoundNetLog()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12525 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12526 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12527 | |
| 12528 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 12529 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12530 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame^] | 12531 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12532 | |
| 12533 | std::string response_data; |
| 12534 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); |
| 12535 | EXPECT_EQ("hello!", response_data); |
| 12536 | |
| 12537 | // Preload www.gmail.com into HostCache. |
| 12538 | HostPortPair host_port("www.gmail.com", 443); |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 12539 | HostResolver::RequestInfo resolve_info(host_port); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12540 | AddressList ignored; |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 12541 | rv = session_deps_.host_resolver->Resolve(resolve_info, |
| 12542 | DEFAULT_PRIORITY, |
| 12543 | &ignored, |
| 12544 | callback.callback(), |
| 12545 | NULL, |
| 12546 | BoundNetLog()); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 12547 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12548 | rv = callback.WaitForResult(); |
| 12549 | EXPECT_EQ(OK, rv); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12550 | |
| 12551 | HttpRequestInfo request2; |
| 12552 | request2.method = "GET"; |
| 12553 | request2.url = GURL("https://www.gmail.com/"); |
| 12554 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12555 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12556 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12557 | rv = trans2.Start(&request2, callback.callback(), BoundNetLog()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12558 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12559 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12560 | |
| 12561 | response = trans2.GetResponseInfo(); |
| 12562 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12563 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame^] | 12564 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12565 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 12566 | EXPECT_TRUE(response->was_npn_negotiated); |
| 12567 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 12568 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12569 | } |
| 12570 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12571 | TEST_P(HttpNetworkTransactionTest, UseIPConnectionPoolingAfterResolution) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12572 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 12573 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12574 | |
| 12575 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12576 | session_deps_.host_resolver.reset(new MockCachingHostResolver()); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12577 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12578 | SpdySessionPoolPeer pool_peer(session->spdy_session_pool()); |
| 12579 | pool_peer.DisableDomainAuthenticationVerification(); |
| 12580 | |
| 12581 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 12582 | ssl.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12583 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12584 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12585 | scoped_ptr<SpdyFrame> host1_req( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12586 | spdy_util_.ConstructSpdyGet("https://www.example.org", false, 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 12587 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12588 | scoped_ptr<SpdyFrame> host2_req( |
| 12589 | spdy_util_.ConstructSpdyGet("https://www.gmail.com", false, 3, LOWEST)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12590 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12591 | CreateMockWrite(*host1_req, 0), CreateMockWrite(*host2_req, 3), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12592 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12593 | scoped_ptr<SpdyFrame> host1_resp( |
| 12594 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12595 | scoped_ptr<SpdyFrame> host1_resp_body( |
| 12596 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 12597 | scoped_ptr<SpdyFrame> host2_resp( |
| 12598 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 12599 | scoped_ptr<SpdyFrame> host2_resp_body( |
| 12600 | spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12601 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12602 | CreateMockRead(*host1_resp, 1), |
| 12603 | CreateMockRead(*host1_resp_body, 2), |
| 12604 | CreateMockRead(*host2_resp, 4), |
| 12605 | CreateMockRead(*host2_resp_body, 5), |
| 12606 | MockRead(ASYNC, 0, 6), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12607 | }; |
| 12608 | |
| 12609 | IPAddressNumber ip; |
| 12610 | ASSERT_TRUE(ParseIPLiteralToNumber("127.0.0.1", &ip)); |
| 12611 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 12612 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12613 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 12614 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12615 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12616 | |
| 12617 | TestCompletionCallback callback; |
| 12618 | HttpRequestInfo request1; |
| 12619 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12620 | request1.url = GURL("https://www.example.org/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12621 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12622 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12623 | |
| 12624 | int rv = trans1.Start(&request1, callback.callback(), BoundNetLog()); |
| 12625 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12626 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 12627 | |
| 12628 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 12629 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12630 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame^] | 12631 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12632 | |
| 12633 | std::string response_data; |
| 12634 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); |
| 12635 | EXPECT_EQ("hello!", response_data); |
| 12636 | |
| 12637 | HttpRequestInfo request2; |
| 12638 | request2.method = "GET"; |
| 12639 | request2.url = GURL("https://www.gmail.com/"); |
| 12640 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12641 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12642 | |
| 12643 | rv = trans2.Start(&request2, callback.callback(), BoundNetLog()); |
| 12644 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12645 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 12646 | |
| 12647 | response = trans2.GetResponseInfo(); |
| 12648 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12649 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame^] | 12650 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12651 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 12652 | EXPECT_TRUE(response->was_npn_negotiated); |
| 12653 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 12654 | EXPECT_EQ("hello!", response_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12655 | } |
| 12656 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12657 | class OneTimeCachingHostResolver : public HostResolver { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12658 | public: |
| 12659 | explicit OneTimeCachingHostResolver(const HostPortPair& host_port) |
| 12660 | : host_port_(host_port) {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12661 | ~OneTimeCachingHostResolver() override {} |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12662 | |
| 12663 | RuleBasedHostResolverProc* rules() { return host_resolver_.rules(); } |
| 12664 | |
| 12665 | // HostResolver methods: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12666 | int Resolve(const RequestInfo& info, |
| 12667 | RequestPriority priority, |
| 12668 | AddressList* addresses, |
| 12669 | const CompletionCallback& callback, |
| 12670 | RequestHandle* out_req, |
| 12671 | const BoundNetLog& net_log) override { |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 12672 | return host_resolver_.Resolve( |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 12673 | info, priority, addresses, callback, out_req, net_log); |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 12674 | } |
| 12675 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12676 | int ResolveFromCache(const RequestInfo& info, |
| 12677 | AddressList* addresses, |
| 12678 | const BoundNetLog& net_log) override { |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 12679 | int rv = host_resolver_.ResolveFromCache(info, addresses, net_log); |
| 12680 | if (rv == OK && info.host_port_pair().Equals(host_port_)) |
[email protected] | 98e1cd01 | 2011-11-08 15:33:09 | [diff] [blame] | 12681 | host_resolver_.GetHostCache()->clear(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12682 | return rv; |
| 12683 | } |
| 12684 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12685 | void CancelRequest(RequestHandle req) override { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12686 | host_resolver_.CancelRequest(req); |
| 12687 | } |
| 12688 | |
[email protected] | 46da33be | 2011-07-19 21:58:04 | [diff] [blame] | 12689 | MockCachingHostResolver* GetMockHostResolver() { |
| 12690 | return &host_resolver_; |
| 12691 | } |
| 12692 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12693 | private: |
| 12694 | MockCachingHostResolver host_resolver_; |
| 12695 | const HostPortPair host_port_; |
| 12696 | }; |
| 12697 | |
mmenke | 5c64213 | 2015-06-02 16:05:13 | [diff] [blame] | 12698 | TEST_P(HttpNetworkTransactionTest, |
| 12699 | UseIPConnectionPoolingWithHostCacheExpiration) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12700 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 12701 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12702 | |
| 12703 | // Set up a special HttpNetworkSession with a OneTimeCachingHostResolver. |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12704 | OneTimeCachingHostResolver host_resolver(HostPortPair("www.gmail.com", 443)); |
[email protected] | c6bf815 | 2012-12-02 07:43:34 | [diff] [blame] | 12705 | HttpNetworkSession::Params params = |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12706 | SpdySessionDependencies::CreateSessionParams(&session_deps_); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12707 | params.host_resolver = &host_resolver; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12708 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | b9ec688 | 2011-07-01 07:40:26 | [diff] [blame] | 12709 | SpdySessionPoolPeer pool_peer(session->spdy_session_pool()); |
| 12710 | pool_peer.DisableDomainAuthenticationVerification(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12711 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12712 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 12713 | ssl.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12714 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12715 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12716 | scoped_ptr<SpdyFrame> host1_req( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12717 | spdy_util_.ConstructSpdyGet("https://www.example.org", false, 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 12718 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12719 | scoped_ptr<SpdyFrame> host2_req( |
| 12720 | spdy_util_.ConstructSpdyGet("https://www.gmail.com", false, 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12721 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12722 | CreateMockWrite(*host1_req, 0), CreateMockWrite(*host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12723 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12724 | scoped_ptr<SpdyFrame> host1_resp( |
| 12725 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12726 | scoped_ptr<SpdyFrame> host1_resp_body( |
| 12727 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 12728 | scoped_ptr<SpdyFrame> host2_resp( |
| 12729 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 12730 | scoped_ptr<SpdyFrame> host2_resp_body( |
| 12731 | spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12732 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12733 | CreateMockRead(*host1_resp, 1), |
| 12734 | CreateMockRead(*host1_resp_body, 2), |
| 12735 | CreateMockRead(*host2_resp, 4), |
| 12736 | CreateMockRead(*host2_resp_body, 5), |
| 12737 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12738 | }; |
| 12739 | |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12740 | IPAddressNumber ip; |
| 12741 | ASSERT_TRUE(ParseIPLiteralToNumber("127.0.0.1", &ip)); |
| 12742 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 12743 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12744 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 12745 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12746 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12747 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 12748 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12749 | HttpRequestInfo request1; |
| 12750 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12751 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12752 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12753 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12754 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12755 | int rv = trans1.Start(&request1, callback.callback(), BoundNetLog()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12756 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12757 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12758 | |
| 12759 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 12760 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12761 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame^] | 12762 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12763 | |
| 12764 | std::string response_data; |
| 12765 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); |
| 12766 | EXPECT_EQ("hello!", response_data); |
| 12767 | |
| 12768 | // Preload cache entries into HostCache. |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 12769 | HostResolver::RequestInfo resolve_info(HostPortPair("www.gmail.com", 443)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12770 | AddressList ignored; |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 12771 | rv = host_resolver.Resolve(resolve_info, |
| 12772 | DEFAULT_PRIORITY, |
| 12773 | &ignored, |
| 12774 | callback.callback(), |
| 12775 | NULL, |
| 12776 | BoundNetLog()); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 12777 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12778 | rv = callback.WaitForResult(); |
| 12779 | EXPECT_EQ(OK, rv); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12780 | |
| 12781 | HttpRequestInfo request2; |
| 12782 | request2.method = "GET"; |
| 12783 | request2.url = GURL("https://www.gmail.com/"); |
| 12784 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12785 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12786 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12787 | rv = trans2.Start(&request2, callback.callback(), BoundNetLog()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12788 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12789 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12790 | |
| 12791 | response = trans2.GetResponseInfo(); |
| 12792 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12793 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame^] | 12794 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12795 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 12796 | EXPECT_TRUE(response->was_npn_negotiated); |
| 12797 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 12798 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12799 | } |
| 12800 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12801 | TEST_P(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttp) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12802 | const std::string https_url = "https://www.example.org:8080/"; |
| 12803 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12804 | |
| 12805 | // SPDY GET for HTTPS URL |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12806 | scoped_ptr<SpdyFrame> req1( |
| 12807 | spdy_util_.ConstructSpdyGet(https_url.c_str(), false, 1, LOWEST)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12808 | |
| 12809 | MockWrite writes1[] = { |
| 12810 | CreateMockWrite(*req1, 0), |
| 12811 | }; |
| 12812 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12813 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12814 | scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12815 | MockRead reads1[] = { |
| 12816 | CreateMockRead(*resp1, 1), |
| 12817 | CreateMockRead(*body1, 2), |
| 12818 | MockRead(ASYNC, ERR_IO_PENDING, 3) |
| 12819 | }; |
| 12820 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12821 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 12822 | arraysize(writes1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12823 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 12824 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12825 | |
| 12826 | // HTTP GET for the HTTP URL |
| 12827 | MockWrite writes2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12828 | MockWrite(ASYNC, 0, |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 12829 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12830 | "Host: www.example.org:8080\r\n" |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 12831 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12832 | }; |
| 12833 | |
| 12834 | MockRead reads2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12835 | MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 12836 | MockRead(ASYNC, 2, "hello"), |
| 12837 | MockRead(ASYNC, OK, 3), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12838 | }; |
| 12839 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12840 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 12841 | arraysize(writes2)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12842 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12843 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 12844 | ssl.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12845 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12846 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 12847 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12848 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12849 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12850 | |
| 12851 | // Start the first transaction to set up the SpdySession |
| 12852 | HttpRequestInfo request1; |
| 12853 | request1.method = "GET"; |
| 12854 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12855 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12856 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12857 | TestCompletionCallback callback1; |
| 12858 | EXPECT_EQ(ERR_IO_PENDING, |
| 12859 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 12860 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12861 | |
| 12862 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 12863 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 12864 | |
| 12865 | // Now, start the HTTP request |
| 12866 | HttpRequestInfo request2; |
| 12867 | request2.method = "GET"; |
| 12868 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12869 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12870 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12871 | TestCompletionCallback callback2; |
| 12872 | EXPECT_EQ(ERR_IO_PENDING, |
| 12873 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 12874 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12875 | |
| 12876 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 12877 | EXPECT_FALSE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 12878 | } |
| 12879 | |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 12880 | class AltSvcCertificateVerificationTest : public HttpNetworkTransactionTest { |
| 12881 | public: |
| 12882 | void Run(bool pooling, bool valid) { |
| 12883 | HostPortPair origin(valid ? "mail.example.org" : "invalid.example.org", |
| 12884 | 443); |
| 12885 | HostPortPair alternative("www.example.org", 443); |
| 12886 | |
| 12887 | base::FilePath certs_dir = GetTestCertsDirectory(); |
| 12888 | scoped_refptr<X509Certificate> cert( |
| 12889 | ImportCertFromFile(certs_dir, "spdy_pooling.pem")); |
| 12890 | ASSERT_TRUE(cert.get()); |
| 12891 | bool common_name_fallback_used; |
| 12892 | EXPECT_EQ(valid, |
| 12893 | cert->VerifyNameMatch(origin.host(), &common_name_fallback_used)); |
| 12894 | EXPECT_TRUE( |
| 12895 | cert->VerifyNameMatch(alternative.host(), &common_name_fallback_used)); |
| 12896 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 12897 | ssl.SetNextProto(GetProtocol()); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 12898 | ssl.cert = cert; |
| 12899 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12900 | |
| 12901 | // If pooling, then start a request to alternative first to create a |
| 12902 | // SpdySession. |
| 12903 | std::string url0 = "https://www.example.org:443"; |
| 12904 | // Second request to origin, which has an alternative service, and could |
| 12905 | // open a connection to the alternative host or pool to the existing one. |
| 12906 | std::string url1("https://"); |
| 12907 | url1.append(origin.host()); |
| 12908 | url1.append(":443"); |
| 12909 | |
| 12910 | scoped_ptr<SpdyFrame> req0; |
| 12911 | scoped_ptr<SpdyFrame> req1; |
| 12912 | scoped_ptr<SpdyFrame> resp0; |
| 12913 | scoped_ptr<SpdyFrame> body0; |
| 12914 | scoped_ptr<SpdyFrame> resp1; |
| 12915 | scoped_ptr<SpdyFrame> body1; |
| 12916 | std::vector<MockWrite> writes; |
| 12917 | std::vector<MockRead> reads; |
| 12918 | |
| 12919 | if (pooling) { |
| 12920 | req0.reset(spdy_util_.ConstructSpdyGet(url0.c_str(), false, 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 12921 | spdy_util_.UpdateWithStreamDestruction(1); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 12922 | req1.reset(spdy_util_.ConstructSpdyGet(url1.c_str(), false, 3, LOWEST)); |
| 12923 | |
| 12924 | writes.push_back(CreateMockWrite(*req0, 0)); |
| 12925 | writes.push_back(CreateMockWrite(*req1, 3)); |
| 12926 | |
| 12927 | resp0.reset(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12928 | body0.reset(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 12929 | resp1.reset(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 12930 | body1.reset(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
| 12931 | |
| 12932 | reads.push_back(CreateMockRead(*resp0, 1)); |
| 12933 | reads.push_back(CreateMockRead(*body0, 2)); |
| 12934 | reads.push_back(MockRead(ASYNC, ERR_IO_PENDING, 4)); |
| 12935 | reads.push_back(CreateMockRead(*resp1, 5)); |
| 12936 | reads.push_back(CreateMockRead(*body1, 6)); |
| 12937 | reads.push_back(MockRead(ASYNC, OK, 7)); |
| 12938 | } else { |
| 12939 | req1.reset(spdy_util_.ConstructSpdyGet(url1.c_str(), false, 1, LOWEST)); |
| 12940 | |
| 12941 | writes.push_back(CreateMockWrite(*req1, 0)); |
| 12942 | |
| 12943 | resp1.reset(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12944 | body1.reset(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 12945 | |
| 12946 | reads.push_back(CreateMockRead(*resp1, 1)); |
| 12947 | reads.push_back(CreateMockRead(*body1, 2)); |
| 12948 | reads.push_back(MockRead(ASYNC, OK, 3)); |
| 12949 | } |
| 12950 | |
davidben | 5f8b6bc | 2015-11-25 03:19:54 | [diff] [blame] | 12951 | SequencedSocketData data(reads.data(), reads.size(), writes.data(), |
| 12952 | writes.size()); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 12953 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12954 | |
| 12955 | // Connection to the origin fails. |
| 12956 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 12957 | StaticSocketDataProvider data_refused; |
| 12958 | data_refused.set_connect_data(mock_connect); |
| 12959 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 12960 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12961 | session_deps_.use_alternative_services = true; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12962 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 12963 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 12964 | session->http_server_properties(); |
| 12965 | AlternativeService alternative_service( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 12966 | AlternateProtocolFromNextProto(GetProtocol()), alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12967 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 12968 | http_server_properties->SetAlternativeService(origin, alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12969 | 1.0, expiration); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 12970 | |
| 12971 | // First request to alternative. |
| 12972 | if (pooling) { |
| 12973 | scoped_ptr<HttpTransaction> trans0( |
| 12974 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 12975 | HttpRequestInfo request0; |
| 12976 | request0.method = "GET"; |
| 12977 | request0.url = GURL(url0); |
| 12978 | request0.load_flags = 0; |
| 12979 | TestCompletionCallback callback0; |
| 12980 | |
| 12981 | int rv = trans0->Start(&request0, callback0.callback(), BoundNetLog()); |
| 12982 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12983 | rv = callback0.WaitForResult(); |
| 12984 | EXPECT_EQ(OK, rv); |
| 12985 | } |
| 12986 | |
| 12987 | // Second request to origin. |
| 12988 | scoped_ptr<HttpTransaction> trans1( |
| 12989 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 12990 | HttpRequestInfo request1; |
| 12991 | request1.method = "GET"; |
| 12992 | request1.url = GURL(url1); |
| 12993 | request1.load_flags = 0; |
| 12994 | TestCompletionCallback callback1; |
| 12995 | |
| 12996 | int rv = trans1->Start(&request1, callback1.callback(), BoundNetLog()); |
| 12997 | EXPECT_EQ(ERR_IO_PENDING, rv); |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 12998 | base::MessageLoop::current()->RunUntilIdle(); |
| 12999 | if (data.IsReadPaused()) { |
| 13000 | data.CompleteRead(); |
| 13001 | } |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 13002 | rv = callback1.WaitForResult(); |
| 13003 | if (valid) { |
| 13004 | EXPECT_EQ(OK, rv); |
| 13005 | } else { |
| 13006 | if (pooling) { |
| 13007 | EXPECT_EQ(ERR_CONNECTION_REFUSED, rv); |
| 13008 | } else { |
| 13009 | EXPECT_EQ(ERR_ALTERNATIVE_CERT_NOT_VALID_FOR_ORIGIN, rv); |
| 13010 | } |
| 13011 | } |
| 13012 | } |
| 13013 | }; |
| 13014 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13015 | INSTANTIATE_TEST_CASE_P(ProtoPlusDepend, |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 13016 | AltSvcCertificateVerificationTest, |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13017 | testing::Values(kTestCaseSPDY31, |
| 13018 | kTestCaseHTTP2NoPriorityDependencies, |
| 13019 | kTestCaseHTTP2PriorityDependencies)); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 13020 | |
| 13021 | // The alternative service host must exhibit a certificate that is valid for the |
| 13022 | // origin host. Test that this is enforced when pooling to an existing |
| 13023 | // connection. |
| 13024 | TEST_P(AltSvcCertificateVerificationTest, PoolingValid) { |
| 13025 | Run(true, true); |
| 13026 | } |
| 13027 | |
| 13028 | TEST_P(AltSvcCertificateVerificationTest, PoolingInvalid) { |
| 13029 | Run(true, false); |
| 13030 | } |
| 13031 | |
| 13032 | // The alternative service host must exhibit a certificate that is valid for the |
| 13033 | // origin host. Test that this is enforced when opening a new connection. |
| 13034 | TEST_P(AltSvcCertificateVerificationTest, NewConnectionValid) { |
| 13035 | Run(false, true); |
| 13036 | } |
| 13037 | |
| 13038 | TEST_P(AltSvcCertificateVerificationTest, NewConnectionInvalid) { |
| 13039 | Run(false, false); |
| 13040 | } |
| 13041 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13042 | // Alternative service requires HTTP/2 (or SPDY), but HTTP/1.1 is negotiated |
| 13043 | // with the alternative server. That connection should not be used. |
| 13044 | TEST_P(HttpNetworkTransactionTest, AlternativeServiceNotOnHttp11) { |
| 13045 | HostPortPair origin("origin.example.org", 443); |
| 13046 | HostPortPair alternative("alternative.example.org", 443); |
| 13047 | |
| 13048 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 13049 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 13050 | ssl.SetNextProto(kProtoHTTP11); |
| 13051 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13052 | |
| 13053 | // No data should be read from the alternative, because HTTP/1.1 is |
| 13054 | // negotiated. |
| 13055 | StaticSocketDataProvider data; |
| 13056 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13057 | |
| 13058 | // This test documents that an alternate Job should not be used if HTTP/1.1 is |
| 13059 | // negotiated. In order to test this, a failed connection to the origin is |
| 13060 | // mocked. This way the request relies on the alternate Job. |
| 13061 | StaticSocketDataProvider data_refused; |
| 13062 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 13063 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 13064 | |
| 13065 | // Set up alternative service for origin. |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 13066 | session_deps_.use_alternative_services = true; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 13067 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13068 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 13069 | session->http_server_properties(); |
| 13070 | AlternativeService alternative_service( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13071 | AlternateProtocolFromNextProto(GetProtocol()), alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 13072 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13073 | http_server_properties->SetAlternativeService(origin, alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 13074 | 1.0, expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13075 | |
| 13076 | scoped_ptr<HttpTransaction> trans( |
| 13077 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 13078 | HttpRequestInfo request; |
| 13079 | request.method = "GET"; |
| 13080 | request.url = GURL("https://origin.example.org:443"); |
| 13081 | request.load_flags = 0; |
| 13082 | TestCompletionCallback callback; |
| 13083 | |
| 13084 | // HTTP/2 (or SPDY) is required for alternative service, if HTTP/1.1 is |
| 13085 | // negotiated, the alternate Job should fail with ERR_NPN_NEGOTIATION_FAILED. |
| 13086 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13087 | EXPECT_EQ(ERR_NPN_NEGOTIATION_FAILED, callback.GetResult(rv)); |
| 13088 | } |
| 13089 | |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13090 | // A request to a server with an alternative service fires two Jobs: one to the |
| 13091 | // origin, and an alternate one to the alternative server. If the former |
| 13092 | // succeeds, the request should succeed, even if the latter fails because |
| 13093 | // HTTP/1.1 is negotiated which is insufficient for alternative service. |
| 13094 | TEST_P(HttpNetworkTransactionTest, FailedAlternativeServiceIsNotUserVisible) { |
| 13095 | HostPortPair origin("origin.example.org", 443); |
| 13096 | HostPortPair alternative("alternative.example.org", 443); |
| 13097 | |
| 13098 | // Negotiate HTTP/1.1 with alternative. |
| 13099 | SSLSocketDataProvider alternative_ssl(ASYNC, OK); |
| 13100 | alternative_ssl.SetNextProto(kProtoHTTP11); |
| 13101 | session_deps_.socket_factory->AddSSLSocketDataProvider(&alternative_ssl); |
| 13102 | |
| 13103 | // No data should be read from the alternative, because HTTP/1.1 is |
| 13104 | // negotiated. |
| 13105 | StaticSocketDataProvider data; |
| 13106 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13107 | |
| 13108 | // Negotiate HTTP/1.1 with origin. |
| 13109 | SSLSocketDataProvider origin_ssl(ASYNC, OK); |
| 13110 | origin_ssl.SetNextProto(kProtoHTTP11); |
| 13111 | session_deps_.socket_factory->AddSSLSocketDataProvider(&origin_ssl); |
| 13112 | |
| 13113 | MockWrite http_writes[] = { |
| 13114 | MockWrite( |
| 13115 | "GET / HTTP/1.1\r\n" |
| 13116 | "Host: origin.example.org\r\n" |
| 13117 | "Connection: keep-alive\r\n\r\n"), |
| 13118 | MockWrite( |
| 13119 | "GET /second HTTP/1.1\r\n" |
| 13120 | "Host: origin.example.org\r\n" |
| 13121 | "Connection: keep-alive\r\n\r\n"), |
| 13122 | }; |
| 13123 | |
| 13124 | MockRead http_reads[] = { |
| 13125 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13126 | MockRead("Content-Type: text/html\r\n"), |
| 13127 | MockRead("Content-Length: 6\r\n\r\n"), |
| 13128 | MockRead("foobar"), |
| 13129 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13130 | MockRead("Content-Type: text/html\r\n"), |
| 13131 | MockRead("Content-Length: 7\r\n\r\n"), |
| 13132 | MockRead("another"), |
| 13133 | }; |
| 13134 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 13135 | http_writes, arraysize(http_writes)); |
| 13136 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 13137 | |
| 13138 | // Set up alternative service for origin. |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 13139 | session_deps_.use_alternative_services = true; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 13140 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13141 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 13142 | session->http_server_properties(); |
| 13143 | AlternativeService alternative_service( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13144 | AlternateProtocolFromNextProto(GetProtocol()), alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 13145 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13146 | http_server_properties->SetAlternativeService(origin, alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 13147 | 1.0, expiration); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13148 | |
| 13149 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 13150 | HttpRequestInfo request1; |
| 13151 | request1.method = "GET"; |
| 13152 | request1.url = GURL("https://origin.example.org:443"); |
| 13153 | request1.load_flags = 0; |
| 13154 | TestCompletionCallback callback1; |
| 13155 | |
| 13156 | int rv = trans1.Start(&request1, callback1.callback(), BoundNetLog()); |
| 13157 | rv = callback1.GetResult(rv); |
| 13158 | EXPECT_EQ(OK, rv); |
| 13159 | |
| 13160 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
| 13161 | ASSERT_TRUE(response1 != nullptr); |
| 13162 | ASSERT_TRUE(response1->headers.get() != nullptr); |
| 13163 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
| 13164 | |
| 13165 | std::string response_data1; |
| 13166 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data1)); |
| 13167 | EXPECT_EQ("foobar", response_data1); |
| 13168 | |
| 13169 | // Alternative should be marked as broken, because HTTP/1.1 is not sufficient |
| 13170 | // for alternative service. |
| 13171 | EXPECT_TRUE( |
| 13172 | http_server_properties->IsAlternativeServiceBroken(alternative_service)); |
| 13173 | |
| 13174 | // Since |alternative_service| is broken, a second transaction to origin |
| 13175 | // should not start an alternate Job. It should pool to existing connection |
| 13176 | // to origin. |
| 13177 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 13178 | HttpRequestInfo request2; |
| 13179 | request2.method = "GET"; |
| 13180 | request2.url = GURL("https://origin.example.org:443/second"); |
| 13181 | request2.load_flags = 0; |
| 13182 | TestCompletionCallback callback2; |
| 13183 | |
| 13184 | rv = trans2.Start(&request2, callback2.callback(), BoundNetLog()); |
| 13185 | rv = callback2.GetResult(rv); |
| 13186 | EXPECT_EQ(OK, rv); |
| 13187 | |
| 13188 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
| 13189 | ASSERT_TRUE(response2 != nullptr); |
| 13190 | ASSERT_TRUE(response2->headers.get() != nullptr); |
| 13191 | EXPECT_EQ("HTTP/1.1 200 OK", response2->headers->GetStatusLine()); |
| 13192 | |
| 13193 | std::string response_data2; |
| 13194 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data2)); |
| 13195 | EXPECT_EQ("another", response_data2); |
| 13196 | } |
| 13197 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13198 | // Alternative service requires HTTP/2 (or SPDY), but there is already a |
| 13199 | // HTTP/1.1 socket open to the alternative server. That socket should not be |
| 13200 | // used. |
| 13201 | TEST_P(HttpNetworkTransactionTest, AlternativeServiceShouldNotPoolToHttp11) { |
| 13202 | HostPortPair origin("origin.example.org", 443); |
| 13203 | HostPortPair alternative("alternative.example.org", 443); |
| 13204 | std::string origin_url = "https://origin.example.org:443"; |
| 13205 | std::string alternative_url = "https://alternative.example.org:443"; |
| 13206 | |
| 13207 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 13208 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 13209 | ssl.SetNextProto(kProtoHTTP11); |
| 13210 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13211 | |
| 13212 | // HTTP/1.1 data for |request1| and |request2|. |
| 13213 | MockWrite http_writes[] = { |
| 13214 | MockWrite( |
| 13215 | "GET / HTTP/1.1\r\n" |
| 13216 | "Host: alternative.example.org\r\n" |
| 13217 | "Connection: keep-alive\r\n\r\n"), |
| 13218 | MockWrite( |
| 13219 | "GET / HTTP/1.1\r\n" |
| 13220 | "Host: alternative.example.org\r\n" |
| 13221 | "Connection: keep-alive\r\n\r\n"), |
| 13222 | }; |
| 13223 | |
| 13224 | MockRead http_reads[] = { |
| 13225 | MockRead( |
| 13226 | "HTTP/1.1 200 OK\r\n" |
| 13227 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13228 | "Content-Length: 40\r\n\r\n" |
| 13229 | "first HTTP/1.1 response from alternative"), |
| 13230 | MockRead( |
| 13231 | "HTTP/1.1 200 OK\r\n" |
| 13232 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13233 | "Content-Length: 41\r\n\r\n" |
| 13234 | "second HTTP/1.1 response from alternative"), |
| 13235 | }; |
| 13236 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 13237 | http_writes, arraysize(http_writes)); |
| 13238 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 13239 | |
| 13240 | // This test documents that an alternate Job should not pool to an already |
| 13241 | // existing HTTP/1.1 connection. In order to test this, a failed connection |
| 13242 | // to the origin is mocked. This way |request2| relies on the alternate Job. |
| 13243 | StaticSocketDataProvider data_refused; |
| 13244 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 13245 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 13246 | |
| 13247 | // Set up alternative service for origin. |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 13248 | session_deps_.use_alternative_services = true; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 13249 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13250 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 13251 | session->http_server_properties(); |
| 13252 | AlternativeService alternative_service( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13253 | AlternateProtocolFromNextProto(GetProtocol()), alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 13254 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13255 | http_server_properties->SetAlternativeService(origin, alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 13256 | 1.0, expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13257 | |
| 13258 | // First transaction to alternative to open an HTTP/1.1 socket. |
| 13259 | scoped_ptr<HttpTransaction> trans1( |
| 13260 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 13261 | HttpRequestInfo request1; |
| 13262 | request1.method = "GET"; |
| 13263 | request1.url = GURL(alternative_url); |
| 13264 | request1.load_flags = 0; |
| 13265 | TestCompletionCallback callback1; |
| 13266 | |
| 13267 | int rv = trans1->Start(&request1, callback1.callback(), BoundNetLog()); |
| 13268 | EXPECT_EQ(OK, callback1.GetResult(rv)); |
| 13269 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 13270 | ASSERT_TRUE(response1); |
| 13271 | ASSERT_TRUE(response1->headers.get()); |
| 13272 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
| 13273 | EXPECT_TRUE(response1->was_npn_negotiated); |
| 13274 | EXPECT_FALSE(response1->was_fetched_via_spdy); |
| 13275 | std::string response_data1; |
| 13276 | ASSERT_EQ(OK, ReadTransaction(trans1.get(), &response_data1)); |
| 13277 | EXPECT_EQ("first HTTP/1.1 response from alternative", response_data1); |
| 13278 | |
| 13279 | // Request for origin.example.org, which has an alternative service. This |
| 13280 | // will start two Jobs: the alternative looks for connections to pool to, |
| 13281 | // finds one which is HTTP/1.1, and should ignore it, and should not try to |
| 13282 | // open other connections to alternative server. The Job to origin fails, so |
| 13283 | // this request fails. |
| 13284 | scoped_ptr<HttpTransaction> trans2( |
| 13285 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 13286 | HttpRequestInfo request2; |
| 13287 | request2.method = "GET"; |
| 13288 | request2.url = GURL(origin_url); |
| 13289 | request2.load_flags = 0; |
| 13290 | TestCompletionCallback callback2; |
| 13291 | |
| 13292 | rv = trans2->Start(&request2, callback2.callback(), BoundNetLog()); |
| 13293 | EXPECT_EQ(ERR_CONNECTION_REFUSED, callback2.GetResult(rv)); |
| 13294 | |
| 13295 | // Another transaction to alternative. This is to test that the HTTP/1.1 |
| 13296 | // socket is still open and in the pool. |
| 13297 | scoped_ptr<HttpTransaction> trans3( |
| 13298 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 13299 | HttpRequestInfo request3; |
| 13300 | request3.method = "GET"; |
| 13301 | request3.url = GURL(alternative_url); |
| 13302 | request3.load_flags = 0; |
| 13303 | TestCompletionCallback callback3; |
| 13304 | |
| 13305 | rv = trans3->Start(&request3, callback3.callback(), BoundNetLog()); |
| 13306 | EXPECT_EQ(OK, callback3.GetResult(rv)); |
| 13307 | const HttpResponseInfo* response3 = trans3->GetResponseInfo(); |
| 13308 | ASSERT_TRUE(response3); |
| 13309 | ASSERT_TRUE(response3->headers.get()); |
| 13310 | EXPECT_EQ("HTTP/1.1 200 OK", response3->headers->GetStatusLine()); |
| 13311 | EXPECT_TRUE(response3->was_npn_negotiated); |
| 13312 | EXPECT_FALSE(response3->was_fetched_via_spdy); |
| 13313 | std::string response_data3; |
| 13314 | ASSERT_EQ(OK, ReadTransaction(trans3.get(), &response_data3)); |
| 13315 | EXPECT_EQ("second HTTP/1.1 response from alternative", response_data3); |
| 13316 | } |
| 13317 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13318 | TEST_P(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttpOverTunnel) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13319 | const std::string https_url = "https://www.example.org:8080/"; |
| 13320 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13321 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13322 | // Separate SPDY util instance for naked and wrapped requests. |
| 13323 | SpdyTestUtil spdy_util_wrapped(GetProtocol(), GetDependenciesFromPriority()); |
| 13324 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13325 | // SPDY GET for HTTPS URL (through CONNECT tunnel) |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13326 | const HostPortPair host_port_pair("www.example.org", 8080); |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 13327 | scoped_ptr<SpdyFrame> connect( |
| 13328 | spdy_util_.ConstructSpdyConnect(NULL, 0, 1, LOWEST, host_port_pair)); |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 13329 | scoped_ptr<SpdyFrame> req1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13330 | spdy_util_wrapped.ConstructSpdyGet(https_url.c_str(), false, 1, LOWEST)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13331 | scoped_ptr<SpdyFrame> wrapped_req1( |
| 13332 | spdy_util_.ConstructWrappedSpdyFrame(req1, 1)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 13333 | |
| 13334 | // SPDY GET for HTTP URL (through the proxy, but not the tunnel). |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 13335 | SpdyHeaderBlock req2_block; |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 13336 | spdy_util_.MaybeAddVersionHeader(&req2_block); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 13337 | req2_block[spdy_util_.GetMethodKey()] = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13338 | req2_block[spdy_util_.GetHostKey()] = "www.example.org:8080"; |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 13339 | req2_block[spdy_util_.GetSchemeKey()] = "http"; |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 13340 | req2_block[spdy_util_.GetPathKey()] = "/"; |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 13341 | scoped_ptr<SpdyFrame> req2( |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 13342 | spdy_util_.ConstructSpdySyn(3, req2_block, MEDIUM, false, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13343 | |
| 13344 | MockWrite writes1[] = { |
| 13345 | CreateMockWrite(*connect, 0), |
| 13346 | CreateMockWrite(*wrapped_req1, 2), |
| 13347 | CreateMockWrite(*req2, 5), |
| 13348 | }; |
| 13349 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13350 | scoped_ptr<SpdyFrame> conn_resp( |
| 13351 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 13352 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 13353 | scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 13354 | scoped_ptr<SpdyFrame> wrapped_resp1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13355 | spdy_util_wrapped.ConstructWrappedSpdyFrame(resp1, 1)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13356 | scoped_ptr<SpdyFrame> wrapped_body1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13357 | spdy_util_wrapped.ConstructWrappedSpdyFrame(body1, 1)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13358 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 13359 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13360 | MockRead reads1[] = { |
| 13361 | CreateMockRead(*conn_resp, 1), |
| 13362 | CreateMockRead(*wrapped_resp1, 3), |
| 13363 | CreateMockRead(*wrapped_body1, 4), |
| 13364 | CreateMockRead(*resp2, 6), |
| 13365 | CreateMockRead(*body2, 7), |
| 13366 | MockRead(ASYNC, ERR_IO_PENDING, 8) |
| 13367 | }; |
| 13368 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 13369 | DeterministicSocketData data1(reads1, arraysize(reads1), |
| 13370 | writes1, arraysize(writes1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13371 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 13372 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13373 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 13374 | session_deps_.proxy_service = |
| 13375 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 13376 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13377 | session_deps_.net_log = &log; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13378 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13379 | ssl1.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13380 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13381 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13382 | ssl2.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13383 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 13384 | session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13385 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 13386 | scoped_ptr<HttpNetworkSession> session( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13387 | SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13388 | |
| 13389 | // Start the first transaction to set up the SpdySession |
| 13390 | HttpRequestInfo request1; |
| 13391 | request1.method = "GET"; |
| 13392 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13393 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13394 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13395 | TestCompletionCallback callback1; |
| 13396 | EXPECT_EQ(ERR_IO_PENDING, |
| 13397 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 13398 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 13399 | data1.RunFor(4); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13400 | |
| 13401 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 13402 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 13403 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 13404 | LoadTimingInfo load_timing_info1; |
| 13405 | EXPECT_TRUE(trans1.GetLoadTimingInfo(&load_timing_info1)); |
| 13406 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 13407 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 13408 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13409 | // Now, start the HTTP request |
| 13410 | HttpRequestInfo request2; |
| 13411 | request2.method = "GET"; |
| 13412 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13413 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13414 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13415 | TestCompletionCallback callback2; |
| 13416 | EXPECT_EQ(ERR_IO_PENDING, |
| 13417 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 13418 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 13419 | data1.RunFor(3); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13420 | |
| 13421 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 13422 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 13423 | |
| 13424 | LoadTimingInfo load_timing_info2; |
| 13425 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
| 13426 | // The established SPDY sessions is considered reused by the HTTP request. |
| 13427 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 13428 | // HTTP requests over a SPDY session should have a different connection |
| 13429 | // socket_log_id than requests over a tunnel. |
| 13430 | 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] | 13431 | } |
| 13432 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13433 | // Test that in the case where we have a SPDY session to a SPDY proxy |
| 13434 | // that we do not pool other origins that resolve to the same IP when |
| 13435 | // the certificate does not match the new origin. |
| 13436 | // http://crbug.com/134690 |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13437 | TEST_P(HttpNetworkTransactionTest, DoNotUseSpdySessionIfCertDoesNotMatch) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13438 | const std::string url1 = "http://www.example.org/"; |
| 13439 | const std::string url2 = "https://news.example.org/"; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13440 | const std::string ip_addr = "1.2.3.4"; |
| 13441 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13442 | // Second SpdyTestUtil instance for the second socket. |
| 13443 | SpdyTestUtil spdy_util_secure(GetProtocol(), GetDependenciesFromPriority()); |
| 13444 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13445 | // SPDY GET for HTTP URL (through SPDY proxy) |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13446 | scoped_ptr<SpdyHeaderBlock> headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13447 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 13448 | scoped_ptr<SpdyFrame> req1( |
| 13449 | spdy_util_.ConstructSpdySyn(1, *headers, LOWEST, false, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13450 | |
| 13451 | MockWrite writes1[] = { |
| 13452 | CreateMockWrite(*req1, 0), |
| 13453 | }; |
| 13454 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13455 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 13456 | scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13457 | MockRead reads1[] = { |
bnc | b9e20fc6 | 2015-08-17 17:19:37 | [diff] [blame] | 13458 | CreateMockRead(*resp1, 1), |
| 13459 | CreateMockRead(*body1, 2), |
| 13460 | MockRead(ASYNC, OK, 3) // EOF |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13461 | }; |
| 13462 | |
| 13463 | scoped_ptr<DeterministicSocketData> data1( |
| 13464 | new DeterministicSocketData(reads1, arraysize(reads1), |
| 13465 | writes1, arraysize(writes1))); |
| 13466 | IPAddressNumber ip; |
| 13467 | ASSERT_TRUE(ParseIPLiteralToNumber(ip_addr, &ip)); |
| 13468 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 13469 | MockConnect connect_data1(ASYNC, OK, peer_addr); |
| 13470 | data1->set_connect_data(connect_data1); |
| 13471 | |
| 13472 | // SPDY GET for HTTPS URL (direct) |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 13473 | scoped_ptr<SpdyFrame> req2( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13474 | spdy_util_secure.ConstructSpdyGet(url2.c_str(), false, 1, MEDIUM)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13475 | |
| 13476 | MockWrite writes2[] = { |
| 13477 | CreateMockWrite(*req2, 0), |
| 13478 | }; |
| 13479 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13480 | scoped_ptr<SpdyFrame> resp2( |
| 13481 | spdy_util_secure.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 13482 | scoped_ptr<SpdyFrame> body2(spdy_util_secure.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13483 | MockRead reads2[] = { |
bnc | b9e20fc6 | 2015-08-17 17:19:37 | [diff] [blame] | 13484 | CreateMockRead(*resp2, 1), |
| 13485 | CreateMockRead(*body2, 2), |
| 13486 | MockRead(ASYNC, OK, 3) // EOF |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13487 | }; |
| 13488 | |
| 13489 | scoped_ptr<DeterministicSocketData> data2( |
| 13490 | new DeterministicSocketData(reads2, arraysize(reads2), |
| 13491 | writes2, arraysize(writes2))); |
| 13492 | MockConnect connect_data2(ASYNC, OK); |
| 13493 | data2->set_connect_data(connect_data2); |
| 13494 | |
| 13495 | // Set up a proxy config that sends HTTP requests to a proxy, and |
| 13496 | // all others direct. |
| 13497 | ProxyConfig proxy_config; |
| 13498 | proxy_config.proxy_rules().ParseFromString("http=https://proxy:443"); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13499 | session_deps_.proxy_service.reset(new ProxyService( |
csharrison | b7e3a08 | 2015-09-22 19:13:04 | [diff] [blame] | 13500 | make_scoped_ptr(new ProxyConfigServiceFixed(proxy_config)), nullptr, |
| 13501 | NULL)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13502 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13503 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13504 | ssl1.SetNextProto(GetProtocol()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13505 | // Load a valid cert. Note, that this does not need to |
| 13506 | // be valid for proxy because the MockSSLClientSocket does |
| 13507 | // not actually verify it. But SpdySession will use this |
| 13508 | // to see if it is valid for the new origin |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13509 | ssl1.cert = ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem"); |
| 13510 | ASSERT_TRUE(ssl1.cert.get()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13511 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 13512 | session_deps_.deterministic_socket_factory->AddSocketDataProvider( |
| 13513 | data1.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13514 | |
| 13515 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13516 | ssl2.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13517 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 13518 | session_deps_.deterministic_socket_factory->AddSocketDataProvider( |
| 13519 | data2.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13520 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13521 | session_deps_.host_resolver.reset(new MockCachingHostResolver()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13522 | session_deps_.host_resolver->rules()->AddRule("news.example.org", ip_addr); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13523 | session_deps_.host_resolver->rules()->AddRule("proxy", ip_addr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13524 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 13525 | scoped_ptr<HttpNetworkSession> session( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13526 | SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13527 | |
| 13528 | // Start the first transaction to set up the SpdySession |
| 13529 | HttpRequestInfo request1; |
| 13530 | request1.method = "GET"; |
| 13531 | request1.url = GURL(url1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13532 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13533 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13534 | TestCompletionCallback callback1; |
| 13535 | ASSERT_EQ(ERR_IO_PENDING, |
| 13536 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
| 13537 | data1->RunFor(3); |
| 13538 | |
| 13539 | ASSERT_TRUE(callback1.have_result()); |
| 13540 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 13541 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 13542 | |
| 13543 | // Now, start the HTTP request |
| 13544 | HttpRequestInfo request2; |
| 13545 | request2.method = "GET"; |
| 13546 | request2.url = GURL(url2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13547 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13548 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13549 | TestCompletionCallback callback2; |
| 13550 | EXPECT_EQ(ERR_IO_PENDING, |
| 13551 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 13552 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13553 | data2->RunFor(3); |
| 13554 | |
| 13555 | ASSERT_TRUE(callback2.have_result()); |
| 13556 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 13557 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 13558 | } |
| 13559 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13560 | // Test to verify that a failed socket read (due to an ERR_CONNECTION_CLOSED |
| 13561 | // error) in SPDY session, removes the socket from pool and closes the SPDY |
| 13562 | // session. Verify that new url's from the same HttpNetworkSession (and a new |
| 13563 | // SpdySession) do work. http://crbug.com/224701 |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13564 | TEST_P(HttpNetworkTransactionTest, ErrorSocketNotConnected) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13565 | const std::string https_url = "https://www.example.org/"; |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13566 | |
| 13567 | MockRead reads1[] = { |
| 13568 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED, 0) |
| 13569 | }; |
| 13570 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 13571 | SequencedSocketData data1(reads1, arraysize(reads1), NULL, 0); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13572 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 13573 | scoped_ptr<SpdyFrame> req2( |
| 13574 | spdy_util_.ConstructSpdyGet(https_url.c_str(), false, 1, MEDIUM)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13575 | MockWrite writes2[] = { |
| 13576 | CreateMockWrite(*req2, 0), |
| 13577 | }; |
| 13578 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13579 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 13580 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13581 | MockRead reads2[] = { |
| 13582 | CreateMockRead(*resp2, 1), |
| 13583 | CreateMockRead(*body2, 2), |
| 13584 | MockRead(ASYNC, OK, 3) // EOF |
| 13585 | }; |
| 13586 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 13587 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 13588 | arraysize(writes2)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13589 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13590 | SSLSocketDataProvider ssl1(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13591 | ssl1.SetNextProto(GetProtocol()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 13592 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 13593 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13594 | |
| 13595 | SSLSocketDataProvider ssl2(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13596 | ssl2.SetNextProto(GetProtocol()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 13597 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 13598 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13599 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 13600 | scoped_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 13601 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13602 | |
| 13603 | // Start the first transaction to set up the SpdySession and verify that |
| 13604 | // connection was closed. |
| 13605 | HttpRequestInfo request1; |
| 13606 | request1.method = "GET"; |
| 13607 | request1.url = GURL(https_url); |
| 13608 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13609 | HttpNetworkTransaction trans1(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13610 | TestCompletionCallback callback1; |
| 13611 | EXPECT_EQ(ERR_IO_PENDING, |
| 13612 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13613 | EXPECT_EQ(ERR_CONNECTION_CLOSED, callback1.WaitForResult()); |
| 13614 | |
| 13615 | // Now, start the second request and make sure it succeeds. |
| 13616 | HttpRequestInfo request2; |
| 13617 | request2.method = "GET"; |
| 13618 | request2.url = GURL(https_url); |
| 13619 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13620 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13621 | TestCompletionCallback callback2; |
| 13622 | EXPECT_EQ(ERR_IO_PENDING, |
| 13623 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13624 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 13625 | ASSERT_EQ(OK, callback2.WaitForResult()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13626 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 13627 | } |
| 13628 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13629 | TEST_P(HttpNetworkTransactionTest, CloseIdleSpdySessionToOpenNewOne) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 13630 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13631 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 13632 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 13633 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 13634 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 13635 | |
| 13636 | // Use two different hosts with different IPs so they don't get pooled. |
| 13637 | session_deps_.host_resolver->rules()->AddRule("www.a.com", "10.0.0.1"); |
| 13638 | session_deps_.host_resolver->rules()->AddRule("www.b.com", "10.0.0.2"); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 13639 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13640 | |
| 13641 | SSLSocketDataProvider ssl1(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13642 | ssl1.SetNextProto(GetProtocol()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13643 | SSLSocketDataProvider ssl2(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13644 | ssl2.SetNextProto(GetProtocol()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13645 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 13646 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 13647 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 13648 | scoped_ptr<SpdyFrame> host1_req(spdy_util_.ConstructSpdyGet( |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13649 | "https://www.a.com", false, 1, DEFAULT_PRIORITY)); |
| 13650 | MockWrite spdy1_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13651 | CreateMockWrite(*host1_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13652 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13653 | scoped_ptr<SpdyFrame> host1_resp( |
| 13654 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 13655 | scoped_ptr<SpdyFrame> host1_resp_body( |
| 13656 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13657 | MockRead spdy1_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13658 | CreateMockRead(*host1_resp, 1), |
| 13659 | CreateMockRead(*host1_resp_body, 2), |
| 13660 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13661 | }; |
| 13662 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13663 | // Use a separate test instance for the separate SpdySession that will be |
| 13664 | // created. |
| 13665 | SpdyTestUtil spdy_util_2(GetProtocol(), GetDependenciesFromPriority()); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13666 | scoped_ptr<SequencedSocketData> spdy1_data( |
| 13667 | new SequencedSocketData(spdy1_reads, arraysize(spdy1_reads), spdy1_writes, |
| 13668 | arraysize(spdy1_writes))); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13669 | session_deps_.socket_factory->AddSocketDataProvider(spdy1_data.get()); |
| 13670 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13671 | scoped_ptr<SpdyFrame> host2_req(spdy_util_2.ConstructSpdyGet( |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13672 | "https://www.b.com", false, 1, DEFAULT_PRIORITY)); |
| 13673 | MockWrite spdy2_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13674 | CreateMockWrite(*host2_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13675 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13676 | scoped_ptr<SpdyFrame> host2_resp( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13677 | spdy_util_2.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13678 | scoped_ptr<SpdyFrame> host2_resp_body( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13679 | spdy_util_2.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13680 | MockRead spdy2_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13681 | CreateMockRead(*host2_resp, 1), |
| 13682 | CreateMockRead(*host2_resp_body, 2), |
| 13683 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13684 | }; |
| 13685 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13686 | scoped_ptr<SequencedSocketData> spdy2_data( |
| 13687 | new SequencedSocketData(spdy2_reads, arraysize(spdy2_reads), spdy2_writes, |
| 13688 | arraysize(spdy2_writes))); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13689 | session_deps_.socket_factory->AddSocketDataProvider(spdy2_data.get()); |
| 13690 | |
| 13691 | MockWrite http_write[] = { |
| 13692 | MockWrite("GET / HTTP/1.1\r\n" |
| 13693 | "Host: www.a.com\r\n" |
| 13694 | "Connection: keep-alive\r\n\r\n"), |
| 13695 | }; |
| 13696 | |
| 13697 | MockRead http_read[] = { |
| 13698 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13699 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 13700 | MockRead("Content-Length: 6\r\n\r\n"), |
| 13701 | MockRead("hello!"), |
| 13702 | }; |
| 13703 | StaticSocketDataProvider http_data(http_read, arraysize(http_read), |
| 13704 | http_write, arraysize(http_write)); |
| 13705 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 13706 | |
| 13707 | HostPortPair host_port_pair_a("www.a.com", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 13708 | SpdySessionKey spdy_session_key_a( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 13709 | host_port_pair_a, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13710 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13711 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13712 | |
| 13713 | TestCompletionCallback callback; |
| 13714 | HttpRequestInfo request1; |
| 13715 | request1.method = "GET"; |
| 13716 | request1.url = GURL("https://www.a.com/"); |
| 13717 | request1.load_flags = 0; |
| 13718 | scoped_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13719 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13720 | |
| 13721 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
| 13722 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13723 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 13724 | |
| 13725 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 13726 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13727 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame^] | 13728 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13729 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 13730 | EXPECT_TRUE(response->was_npn_negotiated); |
| 13731 | |
| 13732 | std::string response_data; |
| 13733 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 13734 | EXPECT_EQ("hello!", response_data); |
| 13735 | trans.reset(); |
| 13736 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13737 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13738 | |
| 13739 | HostPortPair host_port_pair_b("www.b.com", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 13740 | SpdySessionKey spdy_session_key_b( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 13741 | host_port_pair_b, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13742 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13743 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13744 | HttpRequestInfo request2; |
| 13745 | request2.method = "GET"; |
| 13746 | request2.url = GURL("https://www.b.com/"); |
| 13747 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13748 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13749 | |
| 13750 | rv = trans->Start(&request2, callback.callback(), BoundNetLog()); |
| 13751 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13752 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 13753 | |
| 13754 | response = trans->GetResponseInfo(); |
| 13755 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13756 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame^] | 13757 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13758 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 13759 | EXPECT_TRUE(response->was_npn_negotiated); |
| 13760 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 13761 | EXPECT_EQ("hello!", response_data); |
| 13762 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13763 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13764 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13765 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13766 | |
| 13767 | HostPortPair host_port_pair_a1("www.a.com", 80); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 13768 | SpdySessionKey spdy_session_key_a1( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 13769 | host_port_pair_a1, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13770 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13771 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a1)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13772 | HttpRequestInfo request3; |
| 13773 | request3.method = "GET"; |
| 13774 | request3.url = GURL("http://www.a.com/"); |
| 13775 | request3.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13776 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13777 | |
| 13778 | rv = trans->Start(&request3, callback.callback(), BoundNetLog()); |
| 13779 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13780 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 13781 | |
| 13782 | response = trans->GetResponseInfo(); |
| 13783 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13784 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13785 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13786 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 13787 | EXPECT_FALSE(response->was_npn_negotiated); |
| 13788 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 13789 | EXPECT_EQ("hello!", response_data); |
| 13790 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13791 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13792 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13793 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13794 | } |
| 13795 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13796 | TEST_P(HttpNetworkTransactionTest, HttpSyncConnectError) { |
| 13797 | HttpRequestInfo request; |
| 13798 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13799 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13800 | request.load_flags = 0; |
| 13801 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 13802 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13803 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13804 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13805 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 13806 | MockConnect mock_connect(SYNCHRONOUS, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13807 | StaticSocketDataProvider data; |
| 13808 | data.set_connect_data(mock_connect); |
| 13809 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13810 | |
| 13811 | TestCompletionCallback callback; |
| 13812 | |
| 13813 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13814 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13815 | |
| 13816 | rv = callback.WaitForResult(); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 13817 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, rv); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13818 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13819 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 13820 | HttpRequestHeaders request_headers; |
| 13821 | trans->GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 13822 | |
| 13823 | ConnectionAttempts attempts; |
| 13824 | trans->GetConnectionAttempts(&attempts); |
| 13825 | ASSERT_EQ(1u, attempts.size()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 13826 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, attempts[0].result); |
| 13827 | |
| 13828 | IPEndPoint endpoint; |
| 13829 | EXPECT_FALSE(trans->GetRemoteEndpoint(&endpoint)); |
| 13830 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13831 | } |
| 13832 | |
| 13833 | TEST_P(HttpNetworkTransactionTest, HttpAsyncConnectError) { |
| 13834 | HttpRequestInfo request; |
| 13835 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13836 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13837 | request.load_flags = 0; |
| 13838 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 13839 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13840 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13841 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13842 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 13843 | MockConnect mock_connect(ASYNC, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13844 | StaticSocketDataProvider data; |
| 13845 | data.set_connect_data(mock_connect); |
| 13846 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13847 | |
| 13848 | TestCompletionCallback callback; |
| 13849 | |
| 13850 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13851 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13852 | |
| 13853 | rv = callback.WaitForResult(); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 13854 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, rv); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13855 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13856 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 13857 | HttpRequestHeaders request_headers; |
| 13858 | trans->GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 13859 | |
| 13860 | ConnectionAttempts attempts; |
| 13861 | trans->GetConnectionAttempts(&attempts); |
| 13862 | ASSERT_EQ(1u, attempts.size()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 13863 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, attempts[0].result); |
| 13864 | |
| 13865 | IPEndPoint endpoint; |
| 13866 | EXPECT_FALSE(trans->GetRemoteEndpoint(&endpoint)); |
| 13867 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13868 | } |
| 13869 | |
| 13870 | TEST_P(HttpNetworkTransactionTest, HttpSyncWriteError) { |
| 13871 | HttpRequestInfo request; |
| 13872 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13873 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13874 | request.load_flags = 0; |
| 13875 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 13876 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13877 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13878 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13879 | |
| 13880 | MockWrite data_writes[] = { |
| 13881 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 13882 | }; |
| 13883 | MockRead data_reads[] = { |
| 13884 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 13885 | }; |
| 13886 | |
| 13887 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 13888 | data_writes, arraysize(data_writes)); |
| 13889 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13890 | |
| 13891 | TestCompletionCallback callback; |
| 13892 | |
| 13893 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13894 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13895 | |
| 13896 | rv = callback.WaitForResult(); |
| 13897 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 13898 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13899 | HttpRequestHeaders request_headers; |
| 13900 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 13901 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 13902 | } |
| 13903 | |
| 13904 | TEST_P(HttpNetworkTransactionTest, HttpAsyncWriteError) { |
| 13905 | HttpRequestInfo request; |
| 13906 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13907 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13908 | request.load_flags = 0; |
| 13909 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 13910 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13911 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13912 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13913 | |
| 13914 | MockWrite data_writes[] = { |
| 13915 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
| 13916 | }; |
| 13917 | MockRead data_reads[] = { |
| 13918 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 13919 | }; |
| 13920 | |
| 13921 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 13922 | data_writes, arraysize(data_writes)); |
| 13923 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13924 | |
| 13925 | TestCompletionCallback callback; |
| 13926 | |
| 13927 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13928 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13929 | |
| 13930 | rv = callback.WaitForResult(); |
| 13931 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 13932 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13933 | HttpRequestHeaders request_headers; |
| 13934 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 13935 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 13936 | } |
| 13937 | |
| 13938 | TEST_P(HttpNetworkTransactionTest, HttpSyncReadError) { |
| 13939 | HttpRequestInfo request; |
| 13940 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13941 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13942 | request.load_flags = 0; |
| 13943 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 13944 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13945 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13946 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13947 | |
| 13948 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13949 | MockWrite( |
| 13950 | "GET / HTTP/1.1\r\n" |
| 13951 | "Host: www.example.org\r\n" |
| 13952 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13953 | }; |
| 13954 | MockRead data_reads[] = { |
| 13955 | MockRead(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 13956 | }; |
| 13957 | |
| 13958 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 13959 | data_writes, arraysize(data_writes)); |
| 13960 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13961 | |
| 13962 | TestCompletionCallback callback; |
| 13963 | |
| 13964 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13965 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13966 | |
| 13967 | rv = callback.WaitForResult(); |
| 13968 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 13969 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13970 | HttpRequestHeaders request_headers; |
| 13971 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 13972 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 13973 | } |
| 13974 | |
| 13975 | TEST_P(HttpNetworkTransactionTest, HttpAsyncReadError) { |
| 13976 | HttpRequestInfo request; |
| 13977 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13978 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13979 | request.load_flags = 0; |
| 13980 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 13981 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13982 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13983 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13984 | |
| 13985 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13986 | MockWrite( |
| 13987 | "GET / HTTP/1.1\r\n" |
| 13988 | "Host: www.example.org\r\n" |
| 13989 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13990 | }; |
| 13991 | MockRead data_reads[] = { |
| 13992 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
| 13993 | }; |
| 13994 | |
| 13995 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 13996 | data_writes, arraysize(data_writes)); |
| 13997 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13998 | |
| 13999 | TestCompletionCallback callback; |
| 14000 | |
| 14001 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14002 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14003 | |
| 14004 | rv = callback.WaitForResult(); |
| 14005 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 14006 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14007 | HttpRequestHeaders request_headers; |
| 14008 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 14009 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 14010 | } |
| 14011 | |
| 14012 | TEST_P(HttpNetworkTransactionTest, GetFullRequestHeadersIncludesExtraHeader) { |
| 14013 | HttpRequestInfo request; |
| 14014 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14015 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14016 | request.load_flags = 0; |
| 14017 | request.extra_headers.SetHeader("X-Foo", "bar"); |
| 14018 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14019 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14020 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14021 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14022 | |
| 14023 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14024 | MockWrite( |
| 14025 | "GET / HTTP/1.1\r\n" |
| 14026 | "Host: www.example.org\r\n" |
| 14027 | "Connection: keep-alive\r\n" |
| 14028 | "X-Foo: bar\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14029 | }; |
| 14030 | MockRead data_reads[] = { |
| 14031 | MockRead("HTTP/1.1 200 OK\r\n" |
| 14032 | "Content-Length: 5\r\n\r\n" |
| 14033 | "hello"), |
| 14034 | MockRead(ASYNC, ERR_UNEXPECTED), |
| 14035 | }; |
| 14036 | |
| 14037 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 14038 | data_writes, arraysize(data_writes)); |
| 14039 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14040 | |
| 14041 | TestCompletionCallback callback; |
| 14042 | |
| 14043 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14044 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14045 | |
| 14046 | rv = callback.WaitForResult(); |
| 14047 | EXPECT_EQ(OK, rv); |
| 14048 | |
| 14049 | HttpRequestHeaders request_headers; |
| 14050 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 14051 | std::string foo; |
| 14052 | EXPECT_TRUE(request_headers.GetHeader("X-Foo", &foo)); |
| 14053 | EXPECT_EQ("bar", foo); |
| 14054 | } |
| 14055 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14056 | namespace { |
| 14057 | |
yhirano | a7e05bb | 2014-11-06 05:40:39 | [diff] [blame] | 14058 | // Fake HttpStream that simply records calls to SetPriority(). |
| 14059 | class FakeStream : public HttpStream, |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14060 | public base::SupportsWeakPtr<FakeStream> { |
| 14061 | public: |
| 14062 | explicit FakeStream(RequestPriority priority) : priority_(priority) {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14063 | ~FakeStream() override {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14064 | |
| 14065 | RequestPriority priority() const { return priority_; } |
| 14066 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14067 | int InitializeStream(const HttpRequestInfo* request_info, |
| 14068 | RequestPriority priority, |
| 14069 | const BoundNetLog& net_log, |
| 14070 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14071 | return ERR_IO_PENDING; |
| 14072 | } |
| 14073 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14074 | int SendRequest(const HttpRequestHeaders& request_headers, |
| 14075 | HttpResponseInfo* response, |
| 14076 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14077 | ADD_FAILURE(); |
| 14078 | return ERR_UNEXPECTED; |
| 14079 | } |
| 14080 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14081 | int ReadResponseHeaders(const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14082 | ADD_FAILURE(); |
| 14083 | return ERR_UNEXPECTED; |
| 14084 | } |
| 14085 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14086 | int ReadResponseBody(IOBuffer* buf, |
| 14087 | int buf_len, |
| 14088 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14089 | ADD_FAILURE(); |
| 14090 | return ERR_UNEXPECTED; |
| 14091 | } |
| 14092 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14093 | void Close(bool not_reusable) override {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14094 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14095 | bool IsResponseBodyComplete() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14096 | ADD_FAILURE(); |
| 14097 | return false; |
| 14098 | } |
| 14099 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14100 | bool IsConnectionReused() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14101 | ADD_FAILURE(); |
| 14102 | return false; |
| 14103 | } |
| 14104 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14105 | void SetConnectionReused() override { ADD_FAILURE(); } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14106 | |
mmenke | bd84c39 | 2015-09-02 14:12:34 | [diff] [blame] | 14107 | bool CanReuseConnection() const override { return false; } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14108 | |
sclittle | 4de1bab9 | 2015-09-22 21:28:24 | [diff] [blame] | 14109 | int64_t GetTotalReceivedBytes() const override { |
[email protected] | bc92bc97 | 2013-12-13 08:32:59 | [diff] [blame] | 14110 | ADD_FAILURE(); |
| 14111 | return 0; |
| 14112 | } |
| 14113 | |
sclittle | be1ccf6 | 2015-09-02 19:40:36 | [diff] [blame] | 14114 | int64_t GetTotalSentBytes() const override { |
| 14115 | ADD_FAILURE(); |
| 14116 | return 0; |
| 14117 | } |
| 14118 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14119 | bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14120 | ADD_FAILURE(); |
| 14121 | return false; |
| 14122 | } |
| 14123 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14124 | void GetSSLInfo(SSLInfo* ssl_info) override { ADD_FAILURE(); } |
| 14125 | |
| 14126 | void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14127 | ADD_FAILURE(); |
| 14128 | } |
| 14129 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14130 | bool GetRemoteEndpoint(IPEndPoint* endpoint) override { return false; } |
| 14131 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14132 | void Drain(HttpNetworkSession* session) override { ADD_FAILURE(); } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14133 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14134 | void SetPriority(RequestPriority priority) override { priority_ = priority; } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14135 | |
yhirano | a7e05bb | 2014-11-06 05:40:39 | [diff] [blame] | 14136 | UploadProgress GetUploadProgress() const override { return UploadProgress(); } |
| 14137 | |
| 14138 | HttpStream* RenewStreamForAuth() override { return NULL; } |
| 14139 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14140 | private: |
| 14141 | RequestPriority priority_; |
| 14142 | |
| 14143 | DISALLOW_COPY_AND_ASSIGN(FakeStream); |
| 14144 | }; |
| 14145 | |
| 14146 | // Fake HttpStreamRequest that simply records calls to SetPriority() |
| 14147 | // and vends FakeStreams with its current priority. |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14148 | class FakeStreamRequest : public HttpStreamRequest, |
| 14149 | public base::SupportsWeakPtr<FakeStreamRequest> { |
| 14150 | public: |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14151 | FakeStreamRequest(RequestPriority priority, |
| 14152 | HttpStreamRequest::Delegate* delegate) |
| 14153 | : priority_(priority), |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14154 | delegate_(delegate), |
| 14155 | websocket_stream_create_helper_(NULL) {} |
| 14156 | |
| 14157 | FakeStreamRequest(RequestPriority priority, |
| 14158 | HttpStreamRequest::Delegate* delegate, |
| 14159 | WebSocketHandshakeStreamBase::CreateHelper* create_helper) |
| 14160 | : priority_(priority), |
| 14161 | delegate_(delegate), |
| 14162 | websocket_stream_create_helper_(create_helper) {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14163 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14164 | ~FakeStreamRequest() override {} |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14165 | |
| 14166 | RequestPriority priority() const { return priority_; } |
| 14167 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14168 | const WebSocketHandshakeStreamBase::CreateHelper* |
| 14169 | websocket_stream_create_helper() const { |
| 14170 | return websocket_stream_create_helper_; |
| 14171 | } |
| 14172 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14173 | // Create a new FakeStream and pass it to the request's |
| 14174 | // delegate. Returns a weak pointer to the FakeStream. |
| 14175 | base::WeakPtr<FakeStream> FinishStreamRequest() { |
| 14176 | FakeStream* fake_stream = new FakeStream(priority_); |
| 14177 | // Do this before calling OnStreamReady() as OnStreamReady() may |
| 14178 | // immediately delete |fake_stream|. |
| 14179 | base::WeakPtr<FakeStream> weak_stream = fake_stream->AsWeakPtr(); |
| 14180 | delegate_->OnStreamReady(SSLConfig(), ProxyInfo(), fake_stream); |
| 14181 | return weak_stream; |
| 14182 | } |
| 14183 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14184 | int RestartTunnelWithProxyAuth(const AuthCredentials& credentials) override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14185 | ADD_FAILURE(); |
| 14186 | return ERR_UNEXPECTED; |
| 14187 | } |
| 14188 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14189 | LoadState GetLoadState() const override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14190 | ADD_FAILURE(); |
| 14191 | return LoadState(); |
| 14192 | } |
| 14193 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14194 | void SetPriority(RequestPriority priority) override { priority_ = priority; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14195 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14196 | bool was_npn_negotiated() const override { return false; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14197 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14198 | NextProto protocol_negotiated() const override { return kProtoUnknown; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14199 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14200 | bool using_spdy() const override { return false; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14201 | |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 14202 | const ConnectionAttempts& connection_attempts() const override { |
| 14203 | static ConnectionAttempts no_attempts; |
| 14204 | return no_attempts; |
| 14205 | } |
| 14206 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14207 | private: |
| 14208 | RequestPriority priority_; |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14209 | HttpStreamRequest::Delegate* const delegate_; |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14210 | WebSocketHandshakeStreamBase::CreateHelper* websocket_stream_create_helper_; |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14211 | |
| 14212 | DISALLOW_COPY_AND_ASSIGN(FakeStreamRequest); |
| 14213 | }; |
| 14214 | |
| 14215 | // Fake HttpStreamFactory that vends FakeStreamRequests. |
| 14216 | class FakeStreamFactory : public HttpStreamFactory { |
| 14217 | public: |
| 14218 | FakeStreamFactory() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14219 | ~FakeStreamFactory() override {} |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14220 | |
| 14221 | // Returns a WeakPtr<> to the last HttpStreamRequest returned by |
| 14222 | // RequestStream() (which may be NULL if it was destroyed already). |
| 14223 | base::WeakPtr<FakeStreamRequest> last_stream_request() { |
| 14224 | return last_stream_request_; |
| 14225 | } |
| 14226 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14227 | HttpStreamRequest* RequestStream(const HttpRequestInfo& info, |
| 14228 | RequestPriority priority, |
| 14229 | const SSLConfig& server_ssl_config, |
| 14230 | const SSLConfig& proxy_ssl_config, |
| 14231 | HttpStreamRequest::Delegate* delegate, |
| 14232 | const BoundNetLog& net_log) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14233 | FakeStreamRequest* fake_request = new FakeStreamRequest(priority, delegate); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14234 | last_stream_request_ = fake_request->AsWeakPtr(); |
| 14235 | return fake_request; |
| 14236 | } |
| 14237 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14238 | HttpStreamRequest* RequestWebSocketHandshakeStream( |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14239 | const HttpRequestInfo& info, |
| 14240 | RequestPriority priority, |
| 14241 | const SSLConfig& server_ssl_config, |
| 14242 | const SSLConfig& proxy_ssl_config, |
| 14243 | HttpStreamRequest::Delegate* delegate, |
[email protected] | 467086b | 2013-11-12 08:19:46 | [diff] [blame] | 14244 | WebSocketHandshakeStreamBase::CreateHelper* create_helper, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 14245 | const BoundNetLog& net_log) override { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14246 | FakeStreamRequest* fake_request = |
| 14247 | new FakeStreamRequest(priority, delegate, create_helper); |
| 14248 | last_stream_request_ = fake_request->AsWeakPtr(); |
| 14249 | return fake_request; |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14250 | } |
| 14251 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14252 | void PreconnectStreams(int num_streams, |
| 14253 | const HttpRequestInfo& info, |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14254 | const SSLConfig& server_ssl_config, |
| 14255 | const SSLConfig& proxy_ssl_config) override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14256 | ADD_FAILURE(); |
| 14257 | } |
| 14258 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14259 | const HostMappingRules* GetHostMappingRules() const override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14260 | ADD_FAILURE(); |
| 14261 | return NULL; |
| 14262 | } |
| 14263 | |
| 14264 | private: |
| 14265 | base::WeakPtr<FakeStreamRequest> last_stream_request_; |
| 14266 | |
| 14267 | DISALLOW_COPY_AND_ASSIGN(FakeStreamFactory); |
| 14268 | }; |
| 14269 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14270 | // TODO(ricea): Maybe unify this with the one in |
| 14271 | // url_request_http_job_unittest.cc ? |
| 14272 | class FakeWebSocketBasicHandshakeStream : public WebSocketHandshakeStreamBase { |
| 14273 | public: |
| 14274 | FakeWebSocketBasicHandshakeStream(scoped_ptr<ClientSocketHandle> connection, |
| 14275 | bool using_proxy) |
| 14276 | : state_(connection.release(), using_proxy) {} |
| 14277 | |
| 14278 | // Fake implementation of HttpStreamBase methods. |
| 14279 | // This ends up being quite "real" because this object has to really send data |
| 14280 | // on the mock socket. It might be easier to use the real implementation, but |
| 14281 | // the fact that the WebSocket code is not compiled on iOS makes that |
| 14282 | // difficult. |
| 14283 | int InitializeStream(const HttpRequestInfo* request_info, |
| 14284 | RequestPriority priority, |
| 14285 | const BoundNetLog& net_log, |
| 14286 | const CompletionCallback& callback) override { |
| 14287 | state_.Initialize(request_info, priority, net_log, callback); |
| 14288 | return OK; |
| 14289 | } |
| 14290 | |
| 14291 | int SendRequest(const HttpRequestHeaders& request_headers, |
| 14292 | HttpResponseInfo* response, |
| 14293 | const CompletionCallback& callback) override { |
| 14294 | return parser()->SendRequest(state_.GenerateRequestLine(), request_headers, |
| 14295 | response, callback); |
| 14296 | } |
| 14297 | |
| 14298 | int ReadResponseHeaders(const CompletionCallback& callback) override { |
| 14299 | return parser()->ReadResponseHeaders(callback); |
| 14300 | } |
| 14301 | |
| 14302 | int ReadResponseBody(IOBuffer* buf, |
| 14303 | int buf_len, |
| 14304 | const CompletionCallback& callback) override { |
| 14305 | NOTREACHED(); |
| 14306 | return ERR_IO_PENDING; |
| 14307 | } |
| 14308 | |
| 14309 | void Close(bool not_reusable) override { |
| 14310 | if (parser()) |
| 14311 | parser()->Close(true); |
| 14312 | } |
| 14313 | |
| 14314 | bool IsResponseBodyComplete() const override { |
| 14315 | NOTREACHED(); |
| 14316 | return false; |
| 14317 | } |
| 14318 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14319 | bool IsConnectionReused() const override { |
| 14320 | NOTREACHED(); |
| 14321 | return false; |
| 14322 | } |
| 14323 | void SetConnectionReused() override { NOTREACHED(); } |
| 14324 | |
mmenke | bd84c39 | 2015-09-02 14:12:34 | [diff] [blame] | 14325 | bool CanReuseConnection() const override { return false; } |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14326 | |
sclittle | 4de1bab9 | 2015-09-22 21:28:24 | [diff] [blame] | 14327 | int64_t GetTotalReceivedBytes() const override { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14328 | NOTREACHED(); |
| 14329 | return 0; |
| 14330 | } |
| 14331 | |
sclittle | be1ccf6 | 2015-09-02 19:40:36 | [diff] [blame] | 14332 | int64_t GetTotalSentBytes() const override { |
| 14333 | NOTREACHED(); |
| 14334 | return 0; |
| 14335 | } |
| 14336 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14337 | bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override { |
| 14338 | NOTREACHED(); |
| 14339 | return false; |
| 14340 | } |
| 14341 | |
Adam Rice | cb76ac6 | 2015-02-20 05:33:25 | [diff] [blame] | 14342 | void GetSSLInfo(SSLInfo* ssl_info) override {} |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14343 | |
| 14344 | void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override { |
| 14345 | NOTREACHED(); |
| 14346 | } |
| 14347 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14348 | bool GetRemoteEndpoint(IPEndPoint* endpoint) override { return false; } |
| 14349 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14350 | void Drain(HttpNetworkSession* session) override { NOTREACHED(); } |
| 14351 | |
| 14352 | void SetPriority(RequestPriority priority) override { NOTREACHED(); } |
| 14353 | |
| 14354 | UploadProgress GetUploadProgress() const override { |
| 14355 | NOTREACHED(); |
| 14356 | return UploadProgress(); |
| 14357 | } |
| 14358 | |
| 14359 | HttpStream* RenewStreamForAuth() override { |
| 14360 | NOTREACHED(); |
| 14361 | return nullptr; |
| 14362 | } |
| 14363 | |
| 14364 | // Fake implementation of WebSocketHandshakeStreamBase method(s) |
| 14365 | scoped_ptr<WebSocketStream> Upgrade() override { |
| 14366 | NOTREACHED(); |
| 14367 | return scoped_ptr<WebSocketStream>(); |
| 14368 | } |
| 14369 | |
| 14370 | private: |
| 14371 | HttpStreamParser* parser() const { return state_.parser(); } |
| 14372 | HttpBasicState state_; |
| 14373 | |
| 14374 | DISALLOW_COPY_AND_ASSIGN(FakeWebSocketBasicHandshakeStream); |
| 14375 | }; |
| 14376 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14377 | // TODO(yhirano): Split this class out into a net/websockets file, if it is |
| 14378 | // worth doing. |
| 14379 | class FakeWebSocketStreamCreateHelper : |
| 14380 | public WebSocketHandshakeStreamBase::CreateHelper { |
| 14381 | public: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14382 | WebSocketHandshakeStreamBase* CreateBasicStream( |
[email protected] | 7e841a5 | 2013-11-22 09:04:21 | [diff] [blame] | 14383 | scoped_ptr<ClientSocketHandle> connection, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 14384 | bool using_proxy) override { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14385 | return new FakeWebSocketBasicHandshakeStream(connection.Pass(), |
| 14386 | using_proxy); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14387 | } |
| 14388 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14389 | WebSocketHandshakeStreamBase* CreateSpdyStream( |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14390 | const base::WeakPtr<SpdySession>& session, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 14391 | bool use_relative_url) override { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14392 | NOTREACHED(); |
| 14393 | return NULL; |
| 14394 | }; |
| 14395 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14396 | ~FakeWebSocketStreamCreateHelper() override {} |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14397 | |
| 14398 | virtual scoped_ptr<WebSocketStream> Upgrade() { |
| 14399 | NOTREACHED(); |
| 14400 | return scoped_ptr<WebSocketStream>(); |
| 14401 | } |
| 14402 | }; |
| 14403 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14404 | } // namespace |
| 14405 | |
| 14406 | // Make sure that HttpNetworkTransaction passes on its priority to its |
| 14407 | // stream request on start. |
| 14408 | TEST_P(HttpNetworkTransactionTest, SetStreamRequestPriorityOnStart) { |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14409 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14410 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14411 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14412 | peer.SetHttpStreamFactory(scoped_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14413 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14414 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14415 | |
| 14416 | ASSERT_TRUE(fake_factory->last_stream_request() == NULL); |
| 14417 | |
| 14418 | HttpRequestInfo request; |
| 14419 | TestCompletionCallback callback; |
| 14420 | EXPECT_EQ(ERR_IO_PENDING, |
| 14421 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 14422 | |
| 14423 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 14424 | fake_factory->last_stream_request(); |
| 14425 | ASSERT_TRUE(fake_request != NULL); |
| 14426 | EXPECT_EQ(LOW, fake_request->priority()); |
| 14427 | } |
| 14428 | |
| 14429 | // Make sure that HttpNetworkTransaction passes on its priority |
| 14430 | // updates to its stream request. |
| 14431 | TEST_P(HttpNetworkTransactionTest, SetStreamRequestPriority) { |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14432 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14433 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14434 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14435 | peer.SetHttpStreamFactory(scoped_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14436 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14437 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14438 | |
| 14439 | HttpRequestInfo request; |
| 14440 | TestCompletionCallback callback; |
| 14441 | EXPECT_EQ(ERR_IO_PENDING, |
| 14442 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 14443 | |
| 14444 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 14445 | fake_factory->last_stream_request(); |
| 14446 | ASSERT_TRUE(fake_request != NULL); |
| 14447 | EXPECT_EQ(LOW, fake_request->priority()); |
| 14448 | |
| 14449 | trans.SetPriority(LOWEST); |
| 14450 | ASSERT_TRUE(fake_request != NULL); |
| 14451 | EXPECT_EQ(LOWEST, fake_request->priority()); |
| 14452 | } |
| 14453 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14454 | // Make sure that HttpNetworkTransaction passes on its priority |
| 14455 | // updates to its stream. |
| 14456 | TEST_P(HttpNetworkTransactionTest, SetStreamPriority) { |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14457 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14458 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14459 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14460 | peer.SetHttpStreamFactory(scoped_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14461 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14462 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14463 | |
| 14464 | HttpRequestInfo request; |
| 14465 | TestCompletionCallback callback; |
| 14466 | EXPECT_EQ(ERR_IO_PENDING, |
| 14467 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 14468 | |
| 14469 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 14470 | fake_factory->last_stream_request(); |
| 14471 | ASSERT_TRUE(fake_request != NULL); |
| 14472 | base::WeakPtr<FakeStream> fake_stream = fake_request->FinishStreamRequest(); |
| 14473 | ASSERT_TRUE(fake_stream != NULL); |
| 14474 | EXPECT_EQ(LOW, fake_stream->priority()); |
| 14475 | |
| 14476 | trans.SetPriority(LOWEST); |
| 14477 | EXPECT_EQ(LOWEST, fake_stream->priority()); |
| 14478 | } |
| 14479 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14480 | TEST_P(HttpNetworkTransactionTest, CreateWebSocketHandshakeStream) { |
| 14481 | // The same logic needs to be tested for both ws: and wss: schemes, but this |
| 14482 | // test is already parameterised on NextProto, so it uses a loop to verify |
| 14483 | // that the different schemes work. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14484 | std::string test_cases[] = {"ws://www.example.org/", |
| 14485 | "wss://www.example.org/"}; |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14486 | for (size_t i = 0; i < arraysize(test_cases); ++i) { |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14487 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14488 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14489 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
| 14490 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
[email protected] | 0191b51c | 2013-11-18 10:55:23 | [diff] [blame] | 14491 | peer.SetHttpStreamFactoryForWebSocket( |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14492 | scoped_ptr<HttpStreamFactory>(fake_factory)); |
| 14493 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14494 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14495 | trans.SetWebSocketHandshakeStreamCreateHelper( |
| 14496 | &websocket_stream_create_helper); |
| 14497 | |
| 14498 | HttpRequestInfo request; |
| 14499 | TestCompletionCallback callback; |
| 14500 | request.method = "GET"; |
| 14501 | request.url = GURL(test_cases[i]); |
| 14502 | |
| 14503 | EXPECT_EQ(ERR_IO_PENDING, |
| 14504 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 14505 | |
| 14506 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 14507 | fake_factory->last_stream_request(); |
| 14508 | ASSERT_TRUE(fake_request != NULL); |
| 14509 | EXPECT_EQ(&websocket_stream_create_helper, |
| 14510 | fake_request->websocket_stream_create_helper()); |
| 14511 | } |
| 14512 | } |
| 14513 | |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14514 | // Tests that when a used socket is returned to the SSL socket pool, it's closed |
| 14515 | // if the transport socket pool is stalled on the global socket limit. |
| 14516 | TEST_P(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest) { |
| 14517 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 14518 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 14519 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 14520 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 14521 | |
| 14522 | // Set up SSL request. |
| 14523 | |
| 14524 | HttpRequestInfo ssl_request; |
| 14525 | ssl_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14526 | ssl_request.url = GURL("https://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14527 | |
| 14528 | MockWrite ssl_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14529 | MockWrite( |
| 14530 | "GET / HTTP/1.1\r\n" |
| 14531 | "Host: www.example.org\r\n" |
| 14532 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14533 | }; |
| 14534 | MockRead ssl_reads[] = { |
| 14535 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14536 | MockRead("Content-Length: 11\r\n\r\n"), |
| 14537 | MockRead("hello world"), |
| 14538 | MockRead(SYNCHRONOUS, OK), |
| 14539 | }; |
| 14540 | StaticSocketDataProvider ssl_data(ssl_reads, arraysize(ssl_reads), |
| 14541 | ssl_writes, arraysize(ssl_writes)); |
| 14542 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 14543 | |
| 14544 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 14545 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 14546 | |
| 14547 | // Set up HTTP request. |
| 14548 | |
| 14549 | HttpRequestInfo http_request; |
| 14550 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14551 | http_request.url = GURL("http://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14552 | |
| 14553 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14554 | MockWrite( |
| 14555 | "GET / HTTP/1.1\r\n" |
| 14556 | "Host: www.example.org\r\n" |
| 14557 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14558 | }; |
| 14559 | MockRead http_reads[] = { |
| 14560 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14561 | MockRead("Content-Length: 7\r\n\r\n"), |
| 14562 | MockRead("falafel"), |
| 14563 | MockRead(SYNCHRONOUS, OK), |
| 14564 | }; |
| 14565 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 14566 | http_writes, arraysize(http_writes)); |
| 14567 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 14568 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14569 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14570 | |
| 14571 | // Start the SSL request. |
| 14572 | TestCompletionCallback ssl_callback; |
| 14573 | scoped_ptr<HttpTransaction> ssl_trans( |
| 14574 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 14575 | ASSERT_EQ(ERR_IO_PENDING, |
| 14576 | ssl_trans->Start(&ssl_request, ssl_callback.callback(), |
| 14577 | BoundNetLog())); |
| 14578 | |
| 14579 | // Start the HTTP request. Pool should stall. |
| 14580 | TestCompletionCallback http_callback; |
| 14581 | scoped_ptr<HttpTransaction> http_trans( |
| 14582 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 14583 | ASSERT_EQ(ERR_IO_PENDING, |
| 14584 | http_trans->Start(&http_request, http_callback.callback(), |
| 14585 | BoundNetLog())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14586 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14587 | |
| 14588 | // Wait for response from SSL request. |
| 14589 | ASSERT_EQ(OK, ssl_callback.WaitForResult()); |
| 14590 | std::string response_data; |
| 14591 | ASSERT_EQ(OK, ReadTransaction(ssl_trans.get(), &response_data)); |
| 14592 | EXPECT_EQ("hello world", response_data); |
| 14593 | |
| 14594 | // The SSL socket should automatically be closed, so the HTTP request can |
| 14595 | // start. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14596 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 14597 | ASSERT_FALSE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14598 | |
| 14599 | // The HTTP request can now complete. |
| 14600 | ASSERT_EQ(OK, http_callback.WaitForResult()); |
| 14601 | ASSERT_EQ(OK, ReadTransaction(http_trans.get(), &response_data)); |
| 14602 | EXPECT_EQ("falafel", response_data); |
| 14603 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14604 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14605 | } |
| 14606 | |
| 14607 | // Tests that when a SSL connection is established but there's no corresponding |
| 14608 | // request that needs it, the new socket is closed if the transport socket pool |
| 14609 | // is stalled on the global socket limit. |
| 14610 | TEST_P(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest2) { |
| 14611 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 14612 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 14613 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 14614 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 14615 | |
| 14616 | // Set up an ssl request. |
| 14617 | |
| 14618 | HttpRequestInfo ssl_request; |
| 14619 | ssl_request.method = "GET"; |
| 14620 | ssl_request.url = GURL("https://www.foopy.com/"); |
| 14621 | |
| 14622 | // No data will be sent on the SSL socket. |
| 14623 | StaticSocketDataProvider ssl_data; |
| 14624 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 14625 | |
| 14626 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 14627 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 14628 | |
| 14629 | // Set up HTTP request. |
| 14630 | |
| 14631 | HttpRequestInfo http_request; |
| 14632 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14633 | http_request.url = GURL("http://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14634 | |
| 14635 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14636 | MockWrite( |
| 14637 | "GET / HTTP/1.1\r\n" |
| 14638 | "Host: www.example.org\r\n" |
| 14639 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14640 | }; |
| 14641 | MockRead http_reads[] = { |
| 14642 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14643 | MockRead("Content-Length: 7\r\n\r\n"), |
| 14644 | MockRead("falafel"), |
| 14645 | MockRead(SYNCHRONOUS, OK), |
| 14646 | }; |
| 14647 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 14648 | http_writes, arraysize(http_writes)); |
| 14649 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 14650 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14651 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14652 | |
| 14653 | // Preconnect an SSL socket. A preconnect is needed because connect jobs are |
| 14654 | // cancelled when a normal transaction is cancelled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14655 | HttpStreamFactory* http_stream_factory = session->http_stream_factory(); |
| 14656 | SSLConfig ssl_config; |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14657 | session->ssl_config_service()->GetSSLConfig(&ssl_config); |
mmenke | d1205bd | 2015-07-15 22:26:35 | [diff] [blame] | 14658 | http_stream_factory->PreconnectStreams(1, ssl_request, ssl_config, |
| 14659 | ssl_config); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14660 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14661 | |
| 14662 | // Start the HTTP request. Pool should stall. |
| 14663 | TestCompletionCallback http_callback; |
| 14664 | scoped_ptr<HttpTransaction> http_trans( |
| 14665 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 14666 | ASSERT_EQ(ERR_IO_PENDING, |
| 14667 | http_trans->Start(&http_request, http_callback.callback(), |
| 14668 | BoundNetLog())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14669 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14670 | |
| 14671 | // The SSL connection will automatically be closed once the connection is |
| 14672 | // established, to let the HTTP request start. |
| 14673 | ASSERT_EQ(OK, http_callback.WaitForResult()); |
| 14674 | std::string response_data; |
| 14675 | ASSERT_EQ(OK, ReadTransaction(http_trans.get(), &response_data)); |
| 14676 | EXPECT_EQ("falafel", response_data); |
| 14677 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14678 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14679 | } |
| 14680 | |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14681 | TEST_P(HttpNetworkTransactionTest, PostReadsErrorResponseAfterReset) { |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 14682 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 14683 | element_readers.push_back( |
| 14684 | make_scoped_ptr(new UploadBytesElementReader("foo", 3))); |
| 14685 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14686 | |
| 14687 | HttpRequestInfo request; |
| 14688 | request.method = "POST"; |
| 14689 | request.url = GURL("http://www.foo.com/"); |
| 14690 | request.upload_data_stream = &upload_data_stream; |
| 14691 | request.load_flags = 0; |
| 14692 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14693 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14694 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14695 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14696 | // Send headers successfully, but get an error while sending the body. |
| 14697 | MockWrite data_writes[] = { |
| 14698 | MockWrite("POST / HTTP/1.1\r\n" |
| 14699 | "Host: www.foo.com\r\n" |
| 14700 | "Connection: keep-alive\r\n" |
| 14701 | "Content-Length: 3\r\n\r\n"), |
| 14702 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14703 | }; |
| 14704 | |
| 14705 | MockRead data_reads[] = { |
| 14706 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 14707 | MockRead("hello world"), |
| 14708 | MockRead(SYNCHRONOUS, OK), |
| 14709 | }; |
| 14710 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14711 | arraysize(data_writes)); |
| 14712 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14713 | |
| 14714 | TestCompletionCallback callback; |
| 14715 | |
| 14716 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14717 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14718 | |
| 14719 | rv = callback.WaitForResult(); |
| 14720 | EXPECT_EQ(OK, rv); |
| 14721 | |
| 14722 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 14723 | ASSERT_TRUE(response != NULL); |
| 14724 | |
| 14725 | EXPECT_TRUE(response->headers.get() != NULL); |
| 14726 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 14727 | |
| 14728 | std::string response_data; |
| 14729 | rv = ReadTransaction(trans.get(), &response_data); |
| 14730 | EXPECT_EQ(OK, rv); |
| 14731 | EXPECT_EQ("hello world", response_data); |
| 14732 | } |
| 14733 | |
| 14734 | // This test makes sure the retry logic doesn't trigger when reading an error |
| 14735 | // response from a server that rejected a POST with a CONNECTION_RESET. |
| 14736 | TEST_P(HttpNetworkTransactionTest, |
| 14737 | PostReadsErrorResponseAfterResetOnReusedSocket) { |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14738 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14739 | MockWrite data_writes[] = { |
| 14740 | MockWrite("GET / HTTP/1.1\r\n" |
| 14741 | "Host: www.foo.com\r\n" |
| 14742 | "Connection: keep-alive\r\n\r\n"), |
| 14743 | MockWrite("POST / HTTP/1.1\r\n" |
| 14744 | "Host: www.foo.com\r\n" |
| 14745 | "Connection: keep-alive\r\n" |
| 14746 | "Content-Length: 3\r\n\r\n"), |
| 14747 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14748 | }; |
| 14749 | |
| 14750 | MockRead data_reads[] = { |
| 14751 | MockRead("HTTP/1.1 200 Peachy\r\n" |
| 14752 | "Content-Length: 14\r\n\r\n"), |
| 14753 | MockRead("first response"), |
| 14754 | MockRead("HTTP/1.1 400 Not OK\r\n" |
| 14755 | "Content-Length: 15\r\n\r\n"), |
| 14756 | MockRead("second response"), |
| 14757 | MockRead(SYNCHRONOUS, OK), |
| 14758 | }; |
| 14759 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14760 | arraysize(data_writes)); |
| 14761 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14762 | |
| 14763 | TestCompletionCallback callback; |
| 14764 | HttpRequestInfo request1; |
| 14765 | request1.method = "GET"; |
| 14766 | request1.url = GURL("http://www.foo.com/"); |
| 14767 | request1.load_flags = 0; |
| 14768 | |
| 14769 | scoped_ptr<HttpTransaction> trans1( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14770 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14771 | int rv = trans1->Start(&request1, callback.callback(), BoundNetLog()); |
| 14772 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14773 | |
| 14774 | rv = callback.WaitForResult(); |
| 14775 | EXPECT_EQ(OK, rv); |
| 14776 | |
| 14777 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 14778 | ASSERT_TRUE(response1 != NULL); |
| 14779 | |
| 14780 | EXPECT_TRUE(response1->headers.get() != NULL); |
| 14781 | EXPECT_EQ("HTTP/1.1 200 Peachy", response1->headers->GetStatusLine()); |
| 14782 | |
| 14783 | std::string response_data1; |
| 14784 | rv = ReadTransaction(trans1.get(), &response_data1); |
| 14785 | EXPECT_EQ(OK, rv); |
| 14786 | EXPECT_EQ("first response", response_data1); |
| 14787 | // Delete the transaction to release the socket back into the socket pool. |
| 14788 | trans1.reset(); |
| 14789 | |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 14790 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 14791 | element_readers.push_back( |
| 14792 | make_scoped_ptr(new UploadBytesElementReader("foo", 3))); |
| 14793 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14794 | |
| 14795 | HttpRequestInfo request2; |
| 14796 | request2.method = "POST"; |
| 14797 | request2.url = GURL("http://www.foo.com/"); |
| 14798 | request2.upload_data_stream = &upload_data_stream; |
| 14799 | request2.load_flags = 0; |
| 14800 | |
| 14801 | scoped_ptr<HttpTransaction> trans2( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14802 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14803 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
| 14804 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14805 | |
| 14806 | rv = callback.WaitForResult(); |
| 14807 | EXPECT_EQ(OK, rv); |
| 14808 | |
| 14809 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 14810 | ASSERT_TRUE(response2 != NULL); |
| 14811 | |
| 14812 | EXPECT_TRUE(response2->headers.get() != NULL); |
| 14813 | EXPECT_EQ("HTTP/1.1 400 Not OK", response2->headers->GetStatusLine()); |
| 14814 | |
| 14815 | std::string response_data2; |
| 14816 | rv = ReadTransaction(trans2.get(), &response_data2); |
| 14817 | EXPECT_EQ(OK, rv); |
| 14818 | EXPECT_EQ("second response", response_data2); |
| 14819 | } |
| 14820 | |
| 14821 | TEST_P(HttpNetworkTransactionTest, |
| 14822 | PostReadsErrorResponseAfterResetPartialBodySent) { |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 14823 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 14824 | element_readers.push_back( |
| 14825 | make_scoped_ptr(new UploadBytesElementReader("foo", 3))); |
| 14826 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14827 | |
| 14828 | HttpRequestInfo request; |
| 14829 | request.method = "POST"; |
| 14830 | request.url = GURL("http://www.foo.com/"); |
| 14831 | request.upload_data_stream = &upload_data_stream; |
| 14832 | request.load_flags = 0; |
| 14833 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14834 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14835 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14836 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14837 | // Send headers successfully, but get an error while sending the body. |
| 14838 | MockWrite data_writes[] = { |
| 14839 | MockWrite("POST / HTTP/1.1\r\n" |
| 14840 | "Host: www.foo.com\r\n" |
| 14841 | "Connection: keep-alive\r\n" |
| 14842 | "Content-Length: 3\r\n\r\n" |
| 14843 | "fo"), |
| 14844 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14845 | }; |
| 14846 | |
| 14847 | MockRead data_reads[] = { |
| 14848 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 14849 | MockRead("hello world"), |
| 14850 | MockRead(SYNCHRONOUS, OK), |
| 14851 | }; |
| 14852 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14853 | arraysize(data_writes)); |
| 14854 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14855 | |
| 14856 | TestCompletionCallback callback; |
| 14857 | |
| 14858 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14859 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14860 | |
| 14861 | rv = callback.WaitForResult(); |
| 14862 | EXPECT_EQ(OK, rv); |
| 14863 | |
| 14864 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 14865 | ASSERT_TRUE(response != NULL); |
| 14866 | |
| 14867 | EXPECT_TRUE(response->headers.get() != NULL); |
| 14868 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 14869 | |
| 14870 | std::string response_data; |
| 14871 | rv = ReadTransaction(trans.get(), &response_data); |
| 14872 | EXPECT_EQ(OK, rv); |
| 14873 | EXPECT_EQ("hello world", response_data); |
| 14874 | } |
| 14875 | |
| 14876 | // This tests the more common case than the previous test, where headers and |
| 14877 | // body are not merged into a single request. |
| 14878 | TEST_P(HttpNetworkTransactionTest, ChunkedPostReadsErrorResponseAfterReset) { |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 14879 | ChunkedUploadDataStream upload_data_stream(0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14880 | |
| 14881 | HttpRequestInfo request; |
| 14882 | request.method = "POST"; |
| 14883 | request.url = GURL("http://www.foo.com/"); |
| 14884 | request.upload_data_stream = &upload_data_stream; |
| 14885 | request.load_flags = 0; |
| 14886 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14887 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14888 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14889 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14890 | // Send headers successfully, but get an error while sending the body. |
| 14891 | MockWrite data_writes[] = { |
| 14892 | MockWrite("POST / HTTP/1.1\r\n" |
| 14893 | "Host: www.foo.com\r\n" |
| 14894 | "Connection: keep-alive\r\n" |
| 14895 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 14896 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14897 | }; |
| 14898 | |
| 14899 | MockRead data_reads[] = { |
| 14900 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 14901 | MockRead("hello world"), |
| 14902 | MockRead(SYNCHRONOUS, OK), |
| 14903 | }; |
| 14904 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14905 | arraysize(data_writes)); |
| 14906 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14907 | |
| 14908 | TestCompletionCallback callback; |
| 14909 | |
| 14910 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14911 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14912 | // Make sure the headers are sent before adding a chunk. This ensures that |
| 14913 | // they can't be merged with the body in a single send. Not currently |
| 14914 | // necessary since a chunked body is never merged with headers, but this makes |
| 14915 | // the test more future proof. |
| 14916 | base::RunLoop().RunUntilIdle(); |
| 14917 | |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 14918 | upload_data_stream.AppendData("last chunk", 10, true); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14919 | |
| 14920 | rv = callback.WaitForResult(); |
| 14921 | EXPECT_EQ(OK, rv); |
| 14922 | |
| 14923 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 14924 | ASSERT_TRUE(response != NULL); |
| 14925 | |
| 14926 | EXPECT_TRUE(response->headers.get() != NULL); |
| 14927 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 14928 | |
| 14929 | std::string response_data; |
| 14930 | rv = ReadTransaction(trans.get(), &response_data); |
| 14931 | EXPECT_EQ(OK, rv); |
| 14932 | EXPECT_EQ("hello world", response_data); |
| 14933 | } |
| 14934 | |
| 14935 | TEST_P(HttpNetworkTransactionTest, PostReadsErrorResponseAfterResetAnd100) { |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 14936 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 14937 | element_readers.push_back( |
| 14938 | make_scoped_ptr(new UploadBytesElementReader("foo", 3))); |
| 14939 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14940 | |
| 14941 | HttpRequestInfo request; |
| 14942 | request.method = "POST"; |
| 14943 | request.url = GURL("http://www.foo.com/"); |
| 14944 | request.upload_data_stream = &upload_data_stream; |
| 14945 | request.load_flags = 0; |
| 14946 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14947 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14948 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14949 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14950 | |
| 14951 | MockWrite data_writes[] = { |
| 14952 | MockWrite("POST / HTTP/1.1\r\n" |
| 14953 | "Host: www.foo.com\r\n" |
| 14954 | "Connection: keep-alive\r\n" |
| 14955 | "Content-Length: 3\r\n\r\n"), |
| 14956 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14957 | }; |
| 14958 | |
| 14959 | MockRead data_reads[] = { |
| 14960 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 14961 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 14962 | MockRead("hello world"), |
| 14963 | MockRead(SYNCHRONOUS, OK), |
| 14964 | }; |
| 14965 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14966 | arraysize(data_writes)); |
| 14967 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14968 | |
| 14969 | TestCompletionCallback callback; |
| 14970 | |
| 14971 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14972 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14973 | |
| 14974 | rv = callback.WaitForResult(); |
| 14975 | EXPECT_EQ(OK, rv); |
| 14976 | |
| 14977 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 14978 | ASSERT_TRUE(response != NULL); |
| 14979 | |
| 14980 | EXPECT_TRUE(response->headers.get() != NULL); |
| 14981 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 14982 | |
| 14983 | std::string response_data; |
| 14984 | rv = ReadTransaction(trans.get(), &response_data); |
| 14985 | EXPECT_EQ(OK, rv); |
| 14986 | EXPECT_EQ("hello world", response_data); |
| 14987 | } |
| 14988 | |
| 14989 | TEST_P(HttpNetworkTransactionTest, PostIgnoresNonErrorResponseAfterReset) { |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 14990 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 14991 | element_readers.push_back( |
| 14992 | make_scoped_ptr(new UploadBytesElementReader("foo", 3))); |
| 14993 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14994 | |
| 14995 | HttpRequestInfo request; |
| 14996 | request.method = "POST"; |
| 14997 | request.url = GURL("http://www.foo.com/"); |
| 14998 | request.upload_data_stream = &upload_data_stream; |
| 14999 | request.load_flags = 0; |
| 15000 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15001 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15002 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15003 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15004 | // Send headers successfully, but get an error while sending the body. |
| 15005 | MockWrite data_writes[] = { |
| 15006 | MockWrite("POST / HTTP/1.1\r\n" |
| 15007 | "Host: www.foo.com\r\n" |
| 15008 | "Connection: keep-alive\r\n" |
| 15009 | "Content-Length: 3\r\n\r\n"), |
| 15010 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15011 | }; |
| 15012 | |
| 15013 | MockRead data_reads[] = { |
| 15014 | MockRead("HTTP/1.0 200 Just Dandy\r\n\r\n"), |
| 15015 | MockRead("hello world"), |
| 15016 | MockRead(SYNCHRONOUS, OK), |
| 15017 | }; |
| 15018 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15019 | arraysize(data_writes)); |
| 15020 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15021 | |
| 15022 | TestCompletionCallback callback; |
| 15023 | |
| 15024 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 15025 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 15026 | |
| 15027 | rv = callback.WaitForResult(); |
| 15028 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15029 | } |
| 15030 | |
| 15031 | TEST_P(HttpNetworkTransactionTest, |
| 15032 | PostIgnoresNonErrorResponseAfterResetAnd100) { |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15033 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 15034 | element_readers.push_back( |
| 15035 | make_scoped_ptr(new UploadBytesElementReader("foo", 3))); |
| 15036 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15037 | |
| 15038 | HttpRequestInfo request; |
| 15039 | request.method = "POST"; |
| 15040 | request.url = GURL("http://www.foo.com/"); |
| 15041 | request.upload_data_stream = &upload_data_stream; |
| 15042 | request.load_flags = 0; |
| 15043 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15044 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15045 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15046 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15047 | // Send headers successfully, but get an error while sending the body. |
| 15048 | MockWrite data_writes[] = { |
| 15049 | MockWrite("POST / HTTP/1.1\r\n" |
| 15050 | "Host: www.foo.com\r\n" |
| 15051 | "Connection: keep-alive\r\n" |
| 15052 | "Content-Length: 3\r\n\r\n"), |
| 15053 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15054 | }; |
| 15055 | |
| 15056 | MockRead data_reads[] = { |
| 15057 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 15058 | MockRead("HTTP/1.0 302 Redirect\r\n"), |
| 15059 | MockRead("Location: http://somewhere-else.com/\r\n"), |
| 15060 | MockRead("Content-Length: 0\r\n\r\n"), |
| 15061 | MockRead(SYNCHRONOUS, OK), |
| 15062 | }; |
| 15063 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15064 | arraysize(data_writes)); |
| 15065 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15066 | |
| 15067 | TestCompletionCallback callback; |
| 15068 | |
| 15069 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 15070 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 15071 | |
| 15072 | rv = callback.WaitForResult(); |
| 15073 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15074 | } |
| 15075 | |
| 15076 | TEST_P(HttpNetworkTransactionTest, PostIgnoresHttp09ResponseAfterReset) { |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15077 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 15078 | element_readers.push_back( |
| 15079 | make_scoped_ptr(new UploadBytesElementReader("foo", 3))); |
| 15080 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15081 | |
| 15082 | HttpRequestInfo request; |
| 15083 | request.method = "POST"; |
| 15084 | request.url = GURL("http://www.foo.com/"); |
| 15085 | request.upload_data_stream = &upload_data_stream; |
| 15086 | request.load_flags = 0; |
| 15087 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15088 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15089 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15090 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15091 | // Send headers successfully, but get an error while sending the body. |
| 15092 | MockWrite data_writes[] = { |
| 15093 | MockWrite("POST / HTTP/1.1\r\n" |
| 15094 | "Host: www.foo.com\r\n" |
| 15095 | "Connection: keep-alive\r\n" |
| 15096 | "Content-Length: 3\r\n\r\n"), |
| 15097 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15098 | }; |
| 15099 | |
| 15100 | MockRead data_reads[] = { |
| 15101 | MockRead("HTTP 0.9 rocks!"), |
| 15102 | MockRead(SYNCHRONOUS, OK), |
| 15103 | }; |
| 15104 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15105 | arraysize(data_writes)); |
| 15106 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15107 | |
| 15108 | TestCompletionCallback callback; |
| 15109 | |
| 15110 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 15111 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 15112 | |
| 15113 | rv = callback.WaitForResult(); |
| 15114 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15115 | } |
| 15116 | |
| 15117 | TEST_P(HttpNetworkTransactionTest, PostIgnoresPartial400HeadersAfterReset) { |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15118 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 15119 | element_readers.push_back( |
| 15120 | make_scoped_ptr(new UploadBytesElementReader("foo", 3))); |
| 15121 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15122 | |
| 15123 | HttpRequestInfo request; |
| 15124 | request.method = "POST"; |
| 15125 | request.url = GURL("http://www.foo.com/"); |
| 15126 | request.upload_data_stream = &upload_data_stream; |
| 15127 | request.load_flags = 0; |
| 15128 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15129 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15130 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15131 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15132 | // Send headers successfully, but get an error while sending the body. |
| 15133 | MockWrite data_writes[] = { |
| 15134 | MockWrite("POST / HTTP/1.1\r\n" |
| 15135 | "Host: www.foo.com\r\n" |
| 15136 | "Connection: keep-alive\r\n" |
| 15137 | "Content-Length: 3\r\n\r\n"), |
| 15138 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15139 | }; |
| 15140 | |
| 15141 | MockRead data_reads[] = { |
| 15142 | MockRead("HTTP/1.0 400 Not a Full Response\r\n"), |
| 15143 | MockRead(SYNCHRONOUS, OK), |
| 15144 | }; |
| 15145 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15146 | arraysize(data_writes)); |
| 15147 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15148 | |
| 15149 | TestCompletionCallback callback; |
| 15150 | |
| 15151 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 15152 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 15153 | |
| 15154 | rv = callback.WaitForResult(); |
| 15155 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15156 | } |
| 15157 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15158 | // Verify that proxy headers are not sent to the destination server when |
| 15159 | // establishing a tunnel for a secure WebSocket connection. |
| 15160 | TEST_P(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWssTunnel) { |
| 15161 | HttpRequestInfo request; |
| 15162 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15163 | request.url = GURL("wss://www.example.org/"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15164 | AddWebSocketHeaders(&request.extra_headers); |
| 15165 | |
| 15166 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 15167 | session_deps_.proxy_service = |
| 15168 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15169 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15170 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15171 | |
| 15172 | // Since a proxy is configured, try to establish a tunnel. |
| 15173 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15174 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 15175 | "Host: www.example.org:443\r\n" |
| 15176 | "Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15177 | |
| 15178 | // After calling trans->RestartWithAuth(), this is the request we should |
| 15179 | // be issuing -- the final header line contains the credentials. |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15180 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 15181 | "Host: www.example.org:443\r\n" |
| 15182 | "Proxy-Connection: keep-alive\r\n" |
| 15183 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15184 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15185 | MockWrite("GET / HTTP/1.1\r\n" |
| 15186 | "Host: www.example.org\r\n" |
| 15187 | "Connection: Upgrade\r\n" |
| 15188 | "Upgrade: websocket\r\n" |
| 15189 | "Origin: http://www.example.org\r\n" |
| 15190 | "Sec-WebSocket-Version: 13\r\n" |
| 15191 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15192 | }; |
| 15193 | |
| 15194 | // The proxy responds to the connect with a 407, using a persistent |
| 15195 | // connection. |
| 15196 | MockRead data_reads[] = { |
| 15197 | // No credentials. |
| 15198 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 15199 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 15200 | MockRead("Content-Length: 0\r\n"), |
| 15201 | MockRead("Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15202 | |
| 15203 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 15204 | |
| 15205 | MockRead("HTTP/1.1 101 Switching Protocols\r\n"), |
| 15206 | MockRead("Upgrade: websocket\r\n"), |
| 15207 | MockRead("Connection: Upgrade\r\n"), |
| 15208 | MockRead("Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n"), |
| 15209 | }; |
| 15210 | |
| 15211 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15212 | arraysize(data_writes)); |
| 15213 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15214 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 15215 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 15216 | |
| 15217 | scoped_ptr<HttpTransaction> trans( |
| 15218 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 15219 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
| 15220 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 15221 | &websocket_stream_create_helper); |
| 15222 | |
| 15223 | { |
| 15224 | TestCompletionCallback callback; |
| 15225 | |
| 15226 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 15227 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 15228 | |
| 15229 | rv = callback.WaitForResult(); |
| 15230 | EXPECT_EQ(OK, rv); |
| 15231 | } |
| 15232 | |
| 15233 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 15234 | ASSERT_TRUE(response); |
| 15235 | ASSERT_TRUE(response->headers.get()); |
| 15236 | EXPECT_EQ(407, response->headers->response_code()); |
| 15237 | |
| 15238 | { |
| 15239 | TestCompletionCallback callback; |
| 15240 | |
| 15241 | int rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 15242 | callback.callback()); |
| 15243 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 15244 | |
| 15245 | rv = callback.WaitForResult(); |
| 15246 | EXPECT_EQ(OK, rv); |
| 15247 | } |
| 15248 | |
| 15249 | response = trans->GetResponseInfo(); |
| 15250 | ASSERT_TRUE(response); |
| 15251 | ASSERT_TRUE(response->headers.get()); |
| 15252 | |
| 15253 | EXPECT_EQ(101, response->headers->response_code()); |
| 15254 | |
| 15255 | trans.reset(); |
| 15256 | session->CloseAllConnections(); |
| 15257 | } |
| 15258 | |
| 15259 | // Verify that proxy headers are not sent to the destination server when |
| 15260 | // establishing a tunnel for an insecure WebSocket connection. |
| 15261 | // This requires the authentication info to be injected into the auth cache |
| 15262 | // due to crbug.com/395064 |
| 15263 | // TODO(ricea): Change to use a 407 response once issue 395064 is fixed. |
| 15264 | TEST_P(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWsTunnel) { |
| 15265 | HttpRequestInfo request; |
| 15266 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15267 | request.url = GURL("ws://www.example.org/"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15268 | AddWebSocketHeaders(&request.extra_headers); |
| 15269 | |
| 15270 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 15271 | session_deps_.proxy_service = |
| 15272 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15273 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15274 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15275 | |
| 15276 | MockWrite data_writes[] = { |
| 15277 | // Try to establish a tunnel for the WebSocket connection, with |
| 15278 | // credentials. Because WebSockets have a separate set of socket pools, |
| 15279 | // they cannot and will not use the same TCP/IP connection as the |
| 15280 | // preflight HTTP request. |
| 15281 | MockWrite( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15282 | "CONNECT www.example.org:80 HTTP/1.1\r\n" |
| 15283 | "Host: www.example.org:80\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15284 | "Proxy-Connection: keep-alive\r\n" |
| 15285 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 15286 | |
| 15287 | MockWrite( |
| 15288 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15289 | "Host: www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15290 | "Connection: Upgrade\r\n" |
| 15291 | "Upgrade: websocket\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15292 | "Origin: http://www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15293 | "Sec-WebSocket-Version: 13\r\n" |
| 15294 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n\r\n"), |
| 15295 | }; |
| 15296 | |
| 15297 | MockRead data_reads[] = { |
| 15298 | // HTTP CONNECT with credentials. |
| 15299 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 15300 | |
| 15301 | // WebSocket connection established inside tunnel. |
| 15302 | MockRead("HTTP/1.1 101 Switching Protocols\r\n"), |
| 15303 | MockRead("Upgrade: websocket\r\n"), |
| 15304 | MockRead("Connection: Upgrade\r\n"), |
| 15305 | MockRead("Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n"), |
| 15306 | }; |
| 15307 | |
| 15308 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15309 | arraysize(data_writes)); |
| 15310 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15311 | |
| 15312 | session->http_auth_cache()->Add( |
| 15313 | GURL("http://myproxy:70/"), "MyRealm1", HttpAuth::AUTH_SCHEME_BASIC, |
| 15314 | "Basic realm=MyRealm1", AuthCredentials(kFoo, kBar), "/"); |
| 15315 | |
| 15316 | scoped_ptr<HttpTransaction> trans( |
| 15317 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 15318 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
| 15319 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 15320 | &websocket_stream_create_helper); |
| 15321 | |
| 15322 | TestCompletionCallback callback; |
| 15323 | |
| 15324 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 15325 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 15326 | |
| 15327 | rv = callback.WaitForResult(); |
| 15328 | EXPECT_EQ(OK, rv); |
| 15329 | |
| 15330 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 15331 | ASSERT_TRUE(response); |
| 15332 | ASSERT_TRUE(response->headers.get()); |
| 15333 | |
| 15334 | EXPECT_EQ(101, response->headers->response_code()); |
| 15335 | |
| 15336 | trans.reset(); |
| 15337 | session->CloseAllConnections(); |
| 15338 | } |
| 15339 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15340 | TEST_P(HttpNetworkTransactionTest, TotalNetworkBytesPost) { |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15341 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 15342 | element_readers.push_back( |
| 15343 | make_scoped_ptr(new UploadBytesElementReader("foo", 3))); |
| 15344 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15345 | |
| 15346 | HttpRequestInfo request; |
| 15347 | request.method = "POST"; |
| 15348 | request.url = GURL("http://www.foo.com/"); |
| 15349 | request.upload_data_stream = &upload_data_stream; |
| 15350 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15351 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15352 | scoped_ptr<HttpTransaction> trans( |
| 15353 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 15354 | MockWrite data_writes[] = { |
| 15355 | MockWrite("POST / HTTP/1.1\r\n" |
| 15356 | "Host: www.foo.com\r\n" |
| 15357 | "Connection: keep-alive\r\n" |
| 15358 | "Content-Length: 3\r\n\r\n"), |
| 15359 | MockWrite("foo"), |
| 15360 | }; |
| 15361 | |
| 15362 | MockRead data_reads[] = { |
| 15363 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 15364 | MockRead(SYNCHRONOUS, OK), |
| 15365 | }; |
| 15366 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15367 | arraysize(data_writes)); |
| 15368 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15369 | |
| 15370 | TestCompletionCallback callback; |
| 15371 | |
| 15372 | EXPECT_EQ(ERR_IO_PENDING, |
| 15373 | trans->Start(&request, callback.callback(), BoundNetLog())); |
| 15374 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 15375 | |
| 15376 | std::string response_data; |
| 15377 | EXPECT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 15378 | |
| 15379 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
| 15380 | trans->GetTotalSentBytes()); |
| 15381 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
| 15382 | trans->GetTotalReceivedBytes()); |
| 15383 | } |
| 15384 | |
| 15385 | TEST_P(HttpNetworkTransactionTest, TotalNetworkBytesPost100Continue) { |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15386 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 15387 | element_readers.push_back( |
| 15388 | make_scoped_ptr(new UploadBytesElementReader("foo", 3))); |
| 15389 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15390 | |
| 15391 | HttpRequestInfo request; |
| 15392 | request.method = "POST"; |
| 15393 | request.url = GURL("http://www.foo.com/"); |
| 15394 | request.upload_data_stream = &upload_data_stream; |
| 15395 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15396 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15397 | scoped_ptr<HttpTransaction> trans( |
| 15398 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 15399 | MockWrite data_writes[] = { |
| 15400 | MockWrite("POST / HTTP/1.1\r\n" |
| 15401 | "Host: www.foo.com\r\n" |
| 15402 | "Connection: keep-alive\r\n" |
| 15403 | "Content-Length: 3\r\n\r\n"), |
| 15404 | MockWrite("foo"), |
| 15405 | }; |
| 15406 | |
| 15407 | MockRead data_reads[] = { |
| 15408 | MockRead("HTTP/1.1 100 Continue\r\n\r\n"), |
| 15409 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 15410 | MockRead(SYNCHRONOUS, OK), |
| 15411 | }; |
| 15412 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15413 | arraysize(data_writes)); |
| 15414 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15415 | |
| 15416 | TestCompletionCallback callback; |
| 15417 | |
| 15418 | EXPECT_EQ(ERR_IO_PENDING, |
| 15419 | trans->Start(&request, callback.callback(), BoundNetLog())); |
| 15420 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 15421 | |
| 15422 | std::string response_data; |
| 15423 | EXPECT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 15424 | |
| 15425 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
| 15426 | trans->GetTotalSentBytes()); |
| 15427 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
| 15428 | trans->GetTotalReceivedBytes()); |
| 15429 | } |
| 15430 | |
| 15431 | TEST_P(HttpNetworkTransactionTest, TotalNetworkBytesChunkedPost) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15432 | ChunkedUploadDataStream upload_data_stream(0); |
| 15433 | |
| 15434 | HttpRequestInfo request; |
| 15435 | request.method = "POST"; |
| 15436 | request.url = GURL("http://www.foo.com/"); |
| 15437 | request.upload_data_stream = &upload_data_stream; |
| 15438 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15439 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15440 | scoped_ptr<HttpTransaction> trans( |
| 15441 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 15442 | // Send headers successfully, but get an error while sending the body. |
| 15443 | MockWrite data_writes[] = { |
| 15444 | MockWrite("POST / HTTP/1.1\r\n" |
| 15445 | "Host: www.foo.com\r\n" |
| 15446 | "Connection: keep-alive\r\n" |
| 15447 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 15448 | MockWrite("1\r\nf\r\n"), MockWrite("2\r\noo\r\n"), MockWrite("0\r\n\r\n"), |
| 15449 | }; |
| 15450 | |
| 15451 | MockRead data_reads[] = { |
| 15452 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 15453 | MockRead(SYNCHRONOUS, OK), |
| 15454 | }; |
| 15455 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15456 | arraysize(data_writes)); |
| 15457 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15458 | |
| 15459 | TestCompletionCallback callback; |
| 15460 | |
| 15461 | EXPECT_EQ(ERR_IO_PENDING, |
| 15462 | trans->Start(&request, callback.callback(), BoundNetLog())); |
| 15463 | |
| 15464 | base::RunLoop().RunUntilIdle(); |
| 15465 | upload_data_stream.AppendData("f", 1, false); |
| 15466 | |
| 15467 | base::RunLoop().RunUntilIdle(); |
| 15468 | upload_data_stream.AppendData("oo", 2, true); |
| 15469 | |
| 15470 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 15471 | |
| 15472 | std::string response_data; |
| 15473 | EXPECT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 15474 | |
| 15475 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
| 15476 | trans->GetTotalSentBytes()); |
| 15477 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
| 15478 | trans->GetTotalReceivedBytes()); |
| 15479 | } |
| 15480 | |
bnc | f458840 | 2015-11-24 13:33:18 | [diff] [blame] | 15481 | TEST_P(HttpNetworkTransactionTest, EnableNPN) { |
| 15482 | session_deps_.next_protos = NextProtosDefaults(); |
| 15483 | session_deps_.enable_npn = true; |
| 15484 | |
| 15485 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 15486 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 15487 | |
| 15488 | EXPECT_THAT(trans.server_ssl_config_.alpn_protos, |
| 15489 | testing::ElementsAre(kProtoHTTP2, kProtoSPDY31, kProtoHTTP11)); |
| 15490 | EXPECT_THAT(trans.server_ssl_config_.npn_protos, |
| 15491 | testing::ElementsAre(kProtoHTTP2, kProtoSPDY31, kProtoHTTP11)); |
| 15492 | } |
| 15493 | |
| 15494 | TEST_P(HttpNetworkTransactionTest, DisableNPN) { |
| 15495 | session_deps_.next_protos = NextProtosDefaults(); |
| 15496 | session_deps_.enable_npn = false; |
| 15497 | |
| 15498 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 15499 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 15500 | |
| 15501 | EXPECT_THAT(trans.server_ssl_config_.alpn_protos, |
| 15502 | testing::ElementsAre(kProtoHTTP2, kProtoSPDY31, kProtoHTTP11)); |
| 15503 | EXPECT_TRUE(trans.server_ssl_config_.npn_protos.empty()); |
| 15504 | } |
| 15505 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 15506 | } // namespace net |