[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" |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame^] | 46 | #include "net/http/http_auth_scheme.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 47 | #include "net/http/http_basic_state.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 48 | #include "net/http/http_basic_stream.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 49 | #include "net/http/http_network_session.h" |
[email protected] | 87bfa3f | 2010-09-30 14:54:56 | [diff] [blame] | 50 | #include "net/http/http_network_session_peer.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 51 | #include "net/http/http_request_headers.h" |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 52 | #include "net/http/http_server_properties_impl.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 53 | #include "net/http/http_stream.h" |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 54 | #include "net/http/http_stream_factory.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 55 | #include "net/http/http_stream_parser.h" |
[email protected] | c41737d | 2014-05-14 07:47:19 | [diff] [blame] | 56 | #include "net/http/http_transaction_test_util.h" |
eroman | 87c53d6 | 2015-04-02 06:51:07 | [diff] [blame] | 57 | #include "net/log/net_log.h" |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 58 | #include "net/log/test_net_log.h" |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 59 | #include "net/log/test_net_log_entry.h" |
| 60 | #include "net/log/test_net_log_util.h" |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 61 | #include "net/proxy/mock_proxy_resolver.h" |
[email protected] | 51fff29d | 2008-12-19 22:17:53 | [diff] [blame] | 62 | #include "net/proxy/proxy_config_service_fixed.h" |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 63 | #include "net/proxy/proxy_info.h" |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 64 | #include "net/proxy/proxy_resolver.h" |
| 65 | #include "net/proxy/proxy_service.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 66 | #include "net/socket/client_socket_factory.h" |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 67 | #include "net/socket/client_socket_pool_manager.h" |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 68 | #include "net/socket/connection_attempts.h" |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 69 | #include "net/socket/mock_client_socket_pool_manager.h" |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 70 | #include "net/socket/next_proto.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 71 | #include "net/socket/socket_test_util.h" |
| 72 | #include "net/socket/ssl_client_socket.h" |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 73 | #include "net/spdy/spdy_framer.h" |
| 74 | #include "net/spdy/spdy_session.h" |
| 75 | #include "net/spdy/spdy_session_pool.h" |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 76 | #include "net/spdy/spdy_test_util_common.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 77 | #include "net/ssl/ssl_cert_request_info.h" |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 78 | #include "net/ssl/ssl_config_service.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 79 | #include "net/ssl/ssl_config_service_defaults.h" |
| 80 | #include "net/ssl/ssl_info.h" |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 81 | #include "net/ssl/ssl_private_key.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 82 | #include "net/test/cert_test_util.h" |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 83 | #include "net/websockets/websocket_handshake_stream_base.h" |
bnc | f458840 | 2015-11-24 13:33:18 | [diff] [blame] | 84 | #include "testing/gmock/include/gmock/gmock.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 85 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | 23887f04f | 2008-12-02 19:20:15 | [diff] [blame] | 86 | #include "testing/platform_test.h" |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 87 | #include "url/gurl.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 88 | |
[email protected] | ad65a3e | 2013-12-25 18:18:01 | [diff] [blame] | 89 | using base::ASCIIToUTF16; |
| 90 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 91 | //----------------------------------------------------------------------------- |
| 92 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 93 | namespace net { |
| 94 | |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 95 | namespace { |
| 96 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 97 | enum TestCase { |
| 98 | // Test using the SPDY/3.1 protocol. |
| 99 | kTestCaseSPDY31, |
| 100 | |
| 101 | // Test using the HTTP/2 protocol, without specifying a stream |
| 102 | // dependency based on the RequestPriority. |
| 103 | kTestCaseHTTP2NoPriorityDependencies, |
| 104 | |
| 105 | // Test using the HTTP/2 protocol, specifying a stream |
| 106 | // dependency based on the RequestPriority. |
| 107 | kTestCaseHTTP2PriorityDependencies |
| 108 | }; |
| 109 | |
[email protected] | 42cba2fb | 2013-03-29 19:58:57 | [diff] [blame] | 110 | const base::string16 kBar(ASCIIToUTF16("bar")); |
| 111 | const base::string16 kBar2(ASCIIToUTF16("bar2")); |
| 112 | const base::string16 kBar3(ASCIIToUTF16("bar3")); |
| 113 | const base::string16 kBaz(ASCIIToUTF16("baz")); |
| 114 | const base::string16 kFirst(ASCIIToUTF16("first")); |
| 115 | const base::string16 kFoo(ASCIIToUTF16("foo")); |
| 116 | const base::string16 kFoo2(ASCIIToUTF16("foo2")); |
| 117 | const base::string16 kFoo3(ASCIIToUTF16("foo3")); |
| 118 | const base::string16 kFou(ASCIIToUTF16("fou")); |
| 119 | const base::string16 kSecond(ASCIIToUTF16("second")); |
| 120 | const base::string16 kTestingNTLM(ASCIIToUTF16("testing-ntlm")); |
| 121 | const base::string16 kWrongPassword(ASCIIToUTF16("wrongpassword")); |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 122 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 123 | int GetIdleSocketCountInTransportSocketPool(HttpNetworkSession* session) { |
| 124 | return session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 125 | ->IdleSocketCount(); |
[email protected] | e5c02664 | 2012-03-17 00:14:02 | [diff] [blame] | 126 | } |
| 127 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 128 | int GetIdleSocketCountInSSLSocketPool(HttpNetworkSession* session) { |
| 129 | return session->GetSSLSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 130 | ->IdleSocketCount(); |
[email protected] | e5c02664 | 2012-03-17 00:14:02 | [diff] [blame] | 131 | } |
| 132 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 133 | bool IsTransportSocketPoolStalled(HttpNetworkSession* session) { |
| 134 | return session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 135 | ->IsStalled(); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 136 | } |
| 137 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 138 | // Takes in a Value created from a NetLogHttpResponseParameter, and returns |
| 139 | // a JSONified list of headers as a single string. Uses single quotes instead |
| 140 | // of double quotes for easier comparison. Returns false on failure. |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 141 | bool GetHeaders(base::DictionaryValue* params, std::string* headers) { |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 142 | if (!params) |
| 143 | return false; |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 144 | base::ListValue* header_list; |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 145 | if (!params->GetList("headers", &header_list)) |
| 146 | return false; |
| 147 | std::string double_quote_headers; |
estade | 8d04646 | 2015-05-16 01:02:34 | [diff] [blame] | 148 | base::JSONWriter::Write(*header_list, &double_quote_headers); |
[email protected] | 466c986 | 2013-12-03 22:05:28 | [diff] [blame] | 149 | base::ReplaceChars(double_quote_headers, "\"", "'", headers); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 150 | return true; |
| 151 | } |
| 152 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 153 | // Tests LoadTimingInfo in the case a socket is reused and no PAC script is |
| 154 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 155 | void TestLoadTimingReused(const LoadTimingInfo& load_timing_info) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 156 | EXPECT_TRUE(load_timing_info.socket_reused); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 157 | EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 158 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 159 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 160 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 161 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 162 | ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 163 | EXPECT_FALSE(load_timing_info.send_start.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 164 | |
| 165 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 166 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 167 | // Set at a higher level. |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 168 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 169 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 170 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 171 | } |
| 172 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 173 | // Tests LoadTimingInfo in the case a new socket is used and no PAC script is |
| 174 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 175 | void TestLoadTimingNotReused(const LoadTimingInfo& load_timing_info, |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 176 | int connect_timing_flags) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 177 | EXPECT_FALSE(load_timing_info.socket_reused); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 178 | EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 179 | |
| 180 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 181 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 182 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 183 | ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 184 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 185 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 186 | load_timing_info.send_start); |
| 187 | |
| 188 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 189 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 190 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 191 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 192 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 193 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | // Tests LoadTimingInfo in the case a socket is reused and a PAC script is |
| 197 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 198 | void TestLoadTimingReusedWithPac(const LoadTimingInfo& load_timing_info) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 199 | EXPECT_TRUE(load_timing_info.socket_reused); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 200 | EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 201 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 202 | ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 203 | |
| 204 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 205 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 206 | load_timing_info.proxy_resolve_end); |
| 207 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 208 | load_timing_info.send_start); |
| 209 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 210 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 211 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 212 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 213 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 214 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | // Tests LoadTimingInfo in the case a new socket is used and a PAC script is |
| 218 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 219 | void TestLoadTimingNotReusedWithPac(const LoadTimingInfo& load_timing_info, |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 220 | int connect_timing_flags) { |
| 221 | EXPECT_FALSE(load_timing_info.socket_reused); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 222 | EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 223 | |
| 224 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 225 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 226 | load_timing_info.proxy_resolve_end); |
| 227 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 228 | load_timing_info.connect_timing.connect_start); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 229 | ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 230 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 231 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 232 | load_timing_info.send_start); |
| 233 | |
| 234 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 235 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 236 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 237 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 238 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 239 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 240 | } |
| 241 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 242 | void AddWebSocketHeaders(HttpRequestHeaders* headers) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 243 | headers->SetHeader("Connection", "Upgrade"); |
| 244 | headers->SetHeader("Upgrade", "websocket"); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 245 | headers->SetHeader("Origin", "http://www.example.org"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 246 | headers->SetHeader("Sec-WebSocket-Version", "13"); |
| 247 | headers->SetHeader("Sec-WebSocket-Key", "dGhlIHNhbXBsZSBub25jZQ=="); |
| 248 | } |
| 249 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 250 | scoped_ptr<HttpNetworkSession> CreateSession( |
| 251 | SpdySessionDependencies* session_deps) { |
[email protected] | c6bf815 | 2012-12-02 07:43:34 | [diff] [blame] | 252 | return SpdySessionDependencies::SpdyCreateSession(session_deps); |
[email protected] | e8d53619 | 2008-10-17 22:21:14 | [diff] [blame] | 253 | } |
| 254 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 255 | } // namespace |
| 256 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 257 | class HttpNetworkTransactionTest |
| 258 | : public PlatformTest, |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 259 | public ::testing::WithParamInterface<TestCase> { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 260 | public: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 261 | virtual ~HttpNetworkTransactionTest() { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 262 | // Important to restore the per-pool limit first, since the pool limit must |
| 263 | // always be greater than group limit, and the tests reduce both limits. |
| 264 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 265 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_pool_sockets_); |
| 266 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 267 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_group_sockets_); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 268 | SpdySession::SetPriorityDependencyDefaultForTesting(false); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 269 | } |
| 270 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 271 | protected: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 272 | HttpNetworkTransactionTest() |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 273 | : spdy_util_(GetProtocol(), GetDependenciesFromPriority()), |
| 274 | session_deps_(GetProtocol()), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 275 | old_max_group_sockets_(ClientSocketPoolManager::max_sockets_per_group( |
| 276 | HttpNetworkSession::NORMAL_SOCKET_POOL)), |
| 277 | old_max_pool_sockets_(ClientSocketPoolManager::max_sockets_per_pool( |
| 278 | HttpNetworkSession::NORMAL_SOCKET_POOL)) { |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 279 | SpdySession::SetPriorityDependencyDefaultForTesting( |
| 280 | GetDependenciesFromPriority()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 281 | } |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 282 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 283 | struct SimpleGetHelperResult { |
| 284 | int rv; |
| 285 | std::string status_line; |
| 286 | std::string response_data; |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 287 | int64_t total_received_bytes; |
| 288 | int64_t total_sent_bytes; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 289 | LoadTimingInfo load_timing_info; |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 290 | ConnectionAttempts connection_attempts; |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 291 | IPEndPoint remote_endpoint_after_start; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 292 | }; |
| 293 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 294 | void SetUp() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 295 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 296 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 297 | } |
| 298 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 299 | void TearDown() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 300 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 301 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 302 | // Empty the current queue. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 303 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 304 | PlatformTest::TearDown(); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 305 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 306 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 307 | } |
| 308 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 309 | NextProto GetProtocol() const { |
| 310 | return GetParam() == kTestCaseSPDY31 ? kProtoSPDY31 : kProtoHTTP2; |
| 311 | } |
| 312 | |
| 313 | bool GetDependenciesFromPriority() const { |
| 314 | return GetParam() == kTestCaseHTTP2PriorityDependencies; |
| 315 | } |
| 316 | |
bnc | 33b8cef4 | 2014-11-19 17:30:38 | [diff] [blame] | 317 | const char* GetAlternateProtocolFromParam() { |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 318 | return AlternateProtocolToString( |
| 319 | AlternateProtocolFromNextProto(GetProtocol())); |
bnc | 33b8cef4 | 2014-11-19 17:30:38 | [diff] [blame] | 320 | } |
| 321 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 322 | std::string GetAlternativeServiceHttpHeader() { |
| 323 | return std::string("Alt-Svc: ") + GetAlternateProtocolFromParam() + |
| 324 | "=\"www.example.com:443\"\r\n"; |
| 325 | } |
| 326 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 327 | std::string GetAlternateProtocolHttpHeader() { |
bnc | 33b8cef4 | 2014-11-19 17:30:38 | [diff] [blame] | 328 | return std::string("Alternate-Protocol: 443:") + |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 329 | GetAlternateProtocolFromParam() + "\r\n"; |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 330 | } |
| 331 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 332 | // Either |write_failure| specifies a write failure or |read_failure| |
| 333 | // specifies a read failure when using a reused socket. In either case, the |
| 334 | // failure should cause the network transaction to resend the request, and the |
| 335 | // other argument should be NULL. |
| 336 | void KeepAliveConnectionResendRequestTest(const MockWrite* write_failure, |
| 337 | const MockRead* read_failure); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 338 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 339 | // Either |write_failure| specifies a write failure or |read_failure| |
| 340 | // specifies a read failure when using a reused socket. In either case, the |
| 341 | // failure should cause the network transaction to resend the request, and the |
| 342 | // other argument should be NULL. |
| 343 | void PreconnectErrorResendRequestTest(const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 344 | const MockRead* read_failure, |
| 345 | bool use_spdy); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 346 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 347 | SimpleGetHelperResult SimpleGetHelperForData(StaticSocketDataProvider* data[], |
| 348 | size_t data_count) { |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 349 | SimpleGetHelperResult out; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 350 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 351 | HttpRequestInfo request; |
| 352 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 353 | request.url = GURL("http://www.example.org/"); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 354 | request.load_flags = 0; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 355 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 356 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 357 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 358 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 359 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 360 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 361 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 362 | for (size_t i = 0; i < data_count; ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 363 | session_deps_.socket_factory->AddSocketDataProvider(data[i]); |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 364 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 365 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 366 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 367 | |
eroman | 24bc6a1 | 2015-05-06 19:55:48 | [diff] [blame] | 368 | EXPECT_TRUE(log.bound().IsCapturing()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 369 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 370 | EXPECT_EQ(ERR_IO_PENDING, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 371 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 372 | out.rv = callback.WaitForResult(); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 373 | out.total_received_bytes = trans->GetTotalReceivedBytes(); |
| 374 | out.total_sent_bytes = trans->GetTotalSentBytes(); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 375 | |
| 376 | // Even in the failure cases that use this function, connections are always |
| 377 | // successfully established before the error. |
| 378 | EXPECT_TRUE(trans->GetLoadTimingInfo(&out.load_timing_info)); |
| 379 | TestLoadTimingNotReused(out.load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 380 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 381 | if (out.rv != OK) |
| 382 | return out; |
| 383 | |
| 384 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 385 | // Can't use ASSERT_* inside helper functions like this, so |
| 386 | // return an error. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 387 | if (response == NULL || response->headers.get() == NULL) { |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 388 | out.rv = ERR_UNEXPECTED; |
| 389 | return out; |
| 390 | } |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 391 | out.status_line = response->headers->GetStatusLine(); |
| 392 | |
[email protected] | 80a09a8 | 2012-11-16 17:40:06 | [diff] [blame] | 393 | EXPECT_EQ("127.0.0.1", response->socket_address.host()); |
| 394 | EXPECT_EQ(80, response->socket_address.port()); |
[email protected] | 6d81b48 | 2011-02-22 19:47:19 | [diff] [blame] | 395 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 396 | bool got_endpoint = |
| 397 | trans->GetRemoteEndpoint(&out.remote_endpoint_after_start); |
| 398 | EXPECT_EQ(got_endpoint, |
| 399 | out.remote_endpoint_after_start.address().size() > 0); |
| 400 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 401 | rv = ReadTransaction(trans.get(), &out.response_data); |
| 402 | EXPECT_EQ(OK, rv); |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 403 | |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 404 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 405 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 406 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 407 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST_HEADERS, |
[email protected] | 169d001 | 2010-05-10 23:20:12 | [diff] [blame] | 408 | NetLog::PHASE_NONE); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 409 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 410 | entries, pos, |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 411 | NetLog::TYPE_HTTP_TRANSACTION_READ_RESPONSE_HEADERS, |
| 412 | NetLog::PHASE_NONE); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 413 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 414 | std::string line; |
| 415 | EXPECT_TRUE(entries[pos].GetStringValue("line", &line)); |
| 416 | EXPECT_EQ("GET / HTTP/1.1\r\n", line); |
| 417 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 418 | HttpRequestHeaders request_headers; |
| 419 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 420 | std::string value; |
| 421 | EXPECT_TRUE(request_headers.GetHeader("Host", &value)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 422 | EXPECT_EQ("www.example.org", value); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 423 | EXPECT_TRUE(request_headers.GetHeader("Connection", &value)); |
| 424 | EXPECT_EQ("keep-alive", value); |
| 425 | |
| 426 | std::string response_headers; |
| 427 | EXPECT_TRUE(GetHeaders(entries[pos].params.get(), &response_headers)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 428 | EXPECT_EQ("['Host: www.example.org','Connection: keep-alive']", |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 429 | response_headers); |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 430 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 431 | out.total_received_bytes = trans->GetTotalReceivedBytes(); |
| 432 | // The total number of sent bytes should not have changed. |
| 433 | EXPECT_EQ(out.total_sent_bytes, trans->GetTotalSentBytes()); |
| 434 | |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 435 | trans->GetConnectionAttempts(&out.connection_attempts); |
[email protected] | aecfbf2 | 2008-10-16 02:02:47 | [diff] [blame] | 436 | return out; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 437 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 438 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 439 | SimpleGetHelperResult SimpleGetHelper(MockRead data_reads[], |
| 440 | size_t reads_count) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 441 | MockWrite data_writes[] = { |
| 442 | MockWrite("GET / HTTP/1.1\r\n" |
| 443 | "Host: www.example.org\r\n" |
| 444 | "Connection: keep-alive\r\n\r\n"), |
| 445 | }; |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 446 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 447 | StaticSocketDataProvider reads(data_reads, reads_count, data_writes, |
| 448 | arraysize(data_writes)); |
| 449 | StaticSocketDataProvider* data[] = {&reads}; |
| 450 | SimpleGetHelperResult out = SimpleGetHelperForData(data, 1); |
| 451 | |
| 452 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
| 453 | out.total_sent_bytes); |
| 454 | return out; |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 455 | } |
| 456 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 457 | void ConnectStatusHelperWithExpectedStatus(const MockRead& status, |
| 458 | int expected_status); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 459 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 460 | void ConnectStatusHelper(const MockRead& status); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 461 | |
| 462 | void BypassHostCacheOnRefreshHelper(int load_flags); |
| 463 | |
| 464 | void CheckErrorIsPassedBack(int error, IoMode mode); |
| 465 | |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 466 | SpdyTestUtil spdy_util_; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 467 | SpdySessionDependencies session_deps_; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 468 | |
| 469 | // Original socket limits. Some tests set these. Safest to always restore |
| 470 | // them once each test has been run. |
| 471 | int old_max_group_sockets_; |
| 472 | int old_max_pool_sockets_; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 473 | }; |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 474 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 475 | INSTANTIATE_TEST_CASE_P(ProtoPlusDepend, |
bnc | 57685ae6 | 2015-03-10 21:27:20 | [diff] [blame] | 476 | HttpNetworkTransactionTest, |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 477 | testing::Values(kTestCaseSPDY31, |
| 478 | kTestCaseHTTP2NoPriorityDependencies, |
| 479 | kTestCaseHTTP2PriorityDependencies)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 480 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 481 | namespace { |
| 482 | |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 483 | class BeforeNetworkStartHandler { |
| 484 | public: |
| 485 | explicit BeforeNetworkStartHandler(bool defer) |
| 486 | : defer_on_before_network_start_(defer), |
| 487 | observed_before_network_start_(false) {} |
| 488 | |
| 489 | void OnBeforeNetworkStart(bool* defer) { |
| 490 | *defer = defer_on_before_network_start_; |
| 491 | observed_before_network_start_ = true; |
| 492 | } |
| 493 | |
| 494 | bool observed_before_network_start() const { |
| 495 | return observed_before_network_start_; |
| 496 | } |
| 497 | |
| 498 | private: |
| 499 | const bool defer_on_before_network_start_; |
| 500 | bool observed_before_network_start_; |
| 501 | |
| 502 | DISALLOW_COPY_AND_ASSIGN(BeforeNetworkStartHandler); |
| 503 | }; |
| 504 | |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 505 | class BeforeProxyHeadersSentHandler { |
| 506 | public: |
| 507 | BeforeProxyHeadersSentHandler() |
| 508 | : observed_before_proxy_headers_sent_(false) {} |
| 509 | |
[email protected] | 1252d42f | 2014-07-01 21:20:20 | [diff] [blame] | 510 | void OnBeforeProxyHeadersSent(const ProxyInfo& proxy_info, |
| 511 | HttpRequestHeaders* request_headers) { |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 512 | observed_before_proxy_headers_sent_ = true; |
| 513 | observed_proxy_server_uri_ = proxy_info.proxy_server().ToURI(); |
| 514 | } |
| 515 | |
| 516 | bool observed_before_proxy_headers_sent() const { |
| 517 | return observed_before_proxy_headers_sent_; |
| 518 | } |
| 519 | |
| 520 | std::string observed_proxy_server_uri() const { |
| 521 | return observed_proxy_server_uri_; |
| 522 | } |
| 523 | |
| 524 | private: |
| 525 | bool observed_before_proxy_headers_sent_; |
| 526 | std::string observed_proxy_server_uri_; |
| 527 | |
| 528 | DISALLOW_COPY_AND_ASSIGN(BeforeProxyHeadersSentHandler); |
| 529 | }; |
| 530 | |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 531 | // Fill |str| with a long header list that consumes >= |size| bytes. |
| 532 | void FillLargeHeadersString(std::string* str, int size) { |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 533 | const char row[] = |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 534 | "SomeHeaderName: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n"; |
| 535 | const int sizeof_row = strlen(row); |
| 536 | const int num_rows = static_cast<int>( |
| 537 | ceil(static_cast<float>(size) / sizeof_row)); |
| 538 | const int sizeof_data = num_rows * sizeof_row; |
| 539 | DCHECK(sizeof_data >= size); |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 540 | str->reserve(sizeof_data); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 541 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 542 | for (int i = 0; i < num_rows; ++i) |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 543 | str->append(row, sizeof_row); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 544 | } |
| 545 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 546 | #if defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 547 | // Alternative functions that eliminate randomness and dependency on the local |
| 548 | // host name so that the generated NTLM messages are reproducible. |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 549 | void MockGenerateRandom1(uint8* output, size_t n) { |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 550 | static const uint8 bytes[] = { |
| 551 | 0x55, 0x29, 0x66, 0x26, 0x6b, 0x9c, 0x73, 0x54 |
| 552 | }; |
| 553 | static size_t current_byte = 0; |
| 554 | for (size_t i = 0; i < n; ++i) { |
| 555 | output[i] = bytes[current_byte++]; |
| 556 | current_byte %= arraysize(bytes); |
| 557 | } |
| 558 | } |
| 559 | |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 560 | void MockGenerateRandom2(uint8* output, size_t n) { |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 561 | static const uint8 bytes[] = { |
| 562 | 0x96, 0x79, 0x85, 0xe7, 0x49, 0x93, 0x70, 0xa1, |
| 563 | 0x4e, 0xe7, 0x87, 0x45, 0x31, 0x5b, 0xd3, 0x1f |
| 564 | }; |
| 565 | static size_t current_byte = 0; |
| 566 | for (size_t i = 0; i < n; ++i) { |
| 567 | output[i] = bytes[current_byte++]; |
| 568 | current_byte %= arraysize(bytes); |
| 569 | } |
| 570 | } |
| 571 | |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 572 | std::string MockGetHostName() { |
| 573 | return "WTC-WIN7"; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 574 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 575 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 576 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 577 | template<typename ParentPool> |
| 578 | class CaptureGroupNameSocketPool : public ParentPool { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 579 | public: |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 580 | CaptureGroupNameSocketPool(HostResolver* host_resolver, |
| 581 | CertVerifier* cert_verifier); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 582 | |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 583 | const std::string last_group_name_received() const { |
| 584 | return last_group_name_; |
| 585 | } |
| 586 | |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 587 | int RequestSocket(const std::string& group_name, |
| 588 | const void* socket_params, |
| 589 | RequestPriority priority, |
| 590 | ClientSocketHandle* handle, |
| 591 | const CompletionCallback& callback, |
| 592 | const BoundNetLog& net_log) override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 593 | last_group_name_ = group_name; |
| 594 | return ERR_IO_PENDING; |
| 595 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 596 | void CancelRequest(const std::string& group_name, |
| 597 | ClientSocketHandle* handle) override {} |
| 598 | void ReleaseSocket(const std::string& group_name, |
| 599 | scoped_ptr<StreamSocket> socket, |
| 600 | int id) override {} |
| 601 | void CloseIdleSockets() override {} |
| 602 | int IdleSocketCount() const override { return 0; } |
| 603 | int IdleSocketCountInGroup(const std::string& group_name) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 604 | return 0; |
| 605 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 606 | LoadState GetLoadState(const std::string& group_name, |
| 607 | const ClientSocketHandle* handle) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 608 | return LOAD_STATE_IDLE; |
| 609 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 610 | base::TimeDelta ConnectionTimeout() const override { |
[email protected] | a796bcec | 2010-03-22 17:17:26 | [diff] [blame] | 611 | return base::TimeDelta(); |
| 612 | } |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 613 | |
| 614 | private: |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 615 | std::string last_group_name_; |
| 616 | }; |
| 617 | |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 618 | typedef CaptureGroupNameSocketPool<TransportClientSocketPool> |
| 619 | CaptureGroupNameTransportSocketPool; |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 620 | typedef CaptureGroupNameSocketPool<HttpProxyClientSocketPool> |
| 621 | CaptureGroupNameHttpProxySocketPool; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 622 | typedef CaptureGroupNameSocketPool<SOCKSClientSocketPool> |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 623 | CaptureGroupNameSOCKSSocketPool; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 624 | typedef CaptureGroupNameSocketPool<SSLClientSocketPool> |
| 625 | CaptureGroupNameSSLSocketPool; |
| 626 | |
rkaplow | d90695c | 2015-03-25 22:12:41 | [diff] [blame] | 627 | template <typename ParentPool> |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 628 | CaptureGroupNameSocketPool<ParentPool>::CaptureGroupNameSocketPool( |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 629 | HostResolver* host_resolver, |
| 630 | CertVerifier* /* cert_verifier */) |
rkaplow | d90695c | 2015-03-25 22:12:41 | [diff] [blame] | 631 | : ParentPool(0, 0, host_resolver, NULL, NULL) { |
| 632 | } |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 633 | |
hashimoto | 0d3e4fb | 2015-01-09 05:02:50 | [diff] [blame] | 634 | template <> |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 635 | CaptureGroupNameHttpProxySocketPool::CaptureGroupNameSocketPool( |
hashimoto | dae13b0 | 2015-01-15 04:28:21 | [diff] [blame] | 636 | HostResolver* /* host_resolver */, |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 637 | CertVerifier* /* cert_verifier */) |
rkaplow | d90695c | 2015-03-25 22:12:41 | [diff] [blame] | 638 | : HttpProxyClientSocketPool(0, 0, NULL, NULL, NULL) { |
hashimoto | 0d3e4fb | 2015-01-09 05:02:50 | [diff] [blame] | 639 | } |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 640 | |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 641 | template <> |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 642 | CaptureGroupNameSSLSocketPool::CaptureGroupNameSocketPool( |
hashimoto | dae13b0 | 2015-01-15 04:28:21 | [diff] [blame] | 643 | HostResolver* /* host_resolver */, |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 644 | CertVerifier* cert_verifier) |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 645 | : SSLClientSocketPool(0, |
| 646 | 0, |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 647 | cert_verifier, |
| 648 | NULL, |
| 649 | NULL, |
[email protected] | 284303b6 | 2013-11-28 15:11:54 | [diff] [blame] | 650 | NULL, |
eranm | 6571b2b | 2014-12-03 15:53:23 | [diff] [blame] | 651 | NULL, |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 652 | std::string(), |
| 653 | NULL, |
| 654 | NULL, |
| 655 | NULL, |
| 656 | NULL, |
| 657 | NULL, |
[email protected] | 8e45855 | 2014-08-05 00:02:15 | [diff] [blame] | 658 | NULL) { |
| 659 | } |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 660 | |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 661 | //----------------------------------------------------------------------------- |
| 662 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 663 | // Helper functions for validating that AuthChallengeInfo's are correctly |
| 664 | // configured for common cases. |
| 665 | bool CheckBasicServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 666 | if (!auth_challenge) |
| 667 | return false; |
| 668 | EXPECT_FALSE(auth_challenge->is_proxy); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 669 | EXPECT_EQ("www.example.org:80", auth_challenge->challenger.ToString()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 670 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame^] | 671 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 672 | return true; |
| 673 | } |
| 674 | |
| 675 | bool CheckBasicProxyAuth(const AuthChallengeInfo* auth_challenge) { |
| 676 | if (!auth_challenge) |
| 677 | return false; |
| 678 | EXPECT_TRUE(auth_challenge->is_proxy); |
| 679 | EXPECT_EQ("myproxy:70", auth_challenge->challenger.ToString()); |
| 680 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame^] | 681 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 682 | return true; |
| 683 | } |
| 684 | |
| 685 | bool CheckDigestServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 686 | if (!auth_challenge) |
| 687 | return false; |
| 688 | EXPECT_FALSE(auth_challenge->is_proxy); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 689 | EXPECT_EQ("www.example.org:80", auth_challenge->challenger.ToString()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 690 | EXPECT_EQ("digestive", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame^] | 691 | EXPECT_EQ(kDigestAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 692 | return true; |
| 693 | } |
| 694 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 695 | #if defined(NTLM_PORTABLE) |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 696 | bool CheckNTLMServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 697 | if (!auth_challenge) |
| 698 | return false; |
| 699 | EXPECT_FALSE(auth_challenge->is_proxy); |
| 700 | EXPECT_EQ("172.22.68.17:80", auth_challenge->challenger.ToString()); |
| 701 | EXPECT_EQ(std::string(), auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame^] | 702 | EXPECT_EQ(kNtlmAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 703 | return true; |
| 704 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 705 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 706 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 707 | } // namespace |
| 708 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 709 | TEST_P(HttpNetworkTransactionTest, Basic) { |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 710 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 711 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 712 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 713 | } |
| 714 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 715 | TEST_P(HttpNetworkTransactionTest, SimpleGET) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 716 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 717 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 718 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 719 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 720 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 721 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 722 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 723 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 724 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 725 | EXPECT_EQ("hello world", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 726 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 727 | EXPECT_EQ(reads_size, out.total_received_bytes); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 728 | EXPECT_EQ(0u, out.connection_attempts.size()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 729 | |
| 730 | EXPECT_FALSE(out.remote_endpoint_after_start.address().empty()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 731 | } |
| 732 | |
| 733 | // Response with no status line. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 734 | TEST_P(HttpNetworkTransactionTest, SimpleGETNoHeaders) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 735 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 736 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 737 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 738 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 739 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 740 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 741 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 742 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 743 | EXPECT_EQ("hello world", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 744 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 745 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 746 | } |
| 747 | |
| 748 | // Allow up to 4 bytes of junk to precede status line. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 749 | TEST_P(HttpNetworkTransactionTest, StatusLineJunk3Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 750 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 751 | MockRead("xxxHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 752 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 753 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 754 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 755 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 756 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 757 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 758 | EXPECT_EQ("DATA", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 759 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 760 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 761 | } |
| 762 | |
| 763 | // Allow up to 4 bytes of junk to precede status line. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 764 | TEST_P(HttpNetworkTransactionTest, StatusLineJunk4Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 765 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 766 | MockRead("\n\nQJHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 767 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 768 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 769 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 770 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 771 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 772 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 773 | EXPECT_EQ("DATA", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 774 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 775 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 776 | } |
| 777 | |
| 778 | // 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] | 779 | TEST_P(HttpNetworkTransactionTest, StatusLineJunk5Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 780 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 781 | MockRead("xxxxxHTTP/1.1 404 Not Found\nServer: blah"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 782 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 783 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 784 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 785 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 786 | EXPECT_EQ(OK, out.rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 787 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 788 | EXPECT_EQ("xxxxxHTTP/1.1 404 Not Found\nServer: blah", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 789 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 790 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 791 | } |
| 792 | |
| 793 | // Same as StatusLineJunk4Bytes, except the read chunks are smaller. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 794 | TEST_P(HttpNetworkTransactionTest, StatusLineJunk4Bytes_Slow) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 795 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 796 | MockRead("\n"), |
| 797 | MockRead("\n"), |
| 798 | MockRead("Q"), |
| 799 | MockRead("J"), |
| 800 | MockRead("HTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 801 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 802 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 803 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 804 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 805 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 806 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 807 | EXPECT_EQ("DATA", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 808 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 809 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 810 | } |
| 811 | |
| 812 | // Close the connection before enough bytes to have a status line. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 813 | TEST_P(HttpNetworkTransactionTest, StatusLinePartial) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 814 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 815 | MockRead("HTT"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 816 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 817 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 818 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 819 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 820 | EXPECT_EQ(OK, out.rv); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 821 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 822 | EXPECT_EQ("HTT", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 823 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 824 | EXPECT_EQ(reads_size, out.total_received_bytes); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 825 | } |
| 826 | |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 827 | // Simulate a 204 response, lacking a Content-Length header, sent over a |
| 828 | // persistent connection. The response should still terminate since a 204 |
| 829 | // cannot have a response body. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 830 | TEST_P(HttpNetworkTransactionTest, StopsReading204) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 831 | char junk[] = "junk"; |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 832 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 833 | MockRead("HTTP/1.1 204 No Content\r\n\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 834 | MockRead(junk), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 835 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 836 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 837 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 838 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 839 | EXPECT_EQ(OK, out.rv); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 840 | EXPECT_EQ("HTTP/1.1 204 No Content", out.status_line); |
| 841 | EXPECT_EQ("", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 842 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 843 | int64_t response_size = reads_size - strlen(junk); |
| 844 | EXPECT_EQ(response_size, out.total_received_bytes); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 845 | } |
| 846 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 847 | // A simple request using chunked encoding with some extra data after. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 848 | TEST_P(HttpNetworkTransactionTest, ChunkedEncoding) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 849 | std::string final_chunk = "0\r\n\r\n"; |
| 850 | std::string extra_data = "HTTP/1.1 200 OK\r\n"; |
| 851 | std::string last_read = final_chunk + extra_data; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 852 | MockRead data_reads[] = { |
| 853 | MockRead("HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n"), |
| 854 | MockRead("5\r\nHello\r\n"), |
| 855 | MockRead("1\r\n"), |
| 856 | MockRead(" \r\n"), |
| 857 | MockRead("5\r\nworld\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 858 | MockRead(last_read.data()), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 859 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 860 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 861 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 862 | arraysize(data_reads)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 863 | EXPECT_EQ(OK, out.rv); |
| 864 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 865 | EXPECT_EQ("Hello world", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 866 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 867 | int64_t response_size = reads_size - extra_data.size(); |
| 868 | EXPECT_EQ(response_size, out.total_received_bytes); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 869 | } |
| 870 | |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 871 | // Next tests deal with http://crbug.com/56344. |
| 872 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 873 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 874 | MultipleContentLengthHeadersNoTransferEncoding) { |
| 875 | MockRead data_reads[] = { |
| 876 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 877 | MockRead("Content-Length: 10\r\n"), |
| 878 | MockRead("Content-Length: 5\r\n\r\n"), |
| 879 | }; |
| 880 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 881 | arraysize(data_reads)); |
| 882 | EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH, out.rv); |
| 883 | } |
| 884 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 885 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 886 | DuplicateContentLengthHeadersNoTransferEncoding) { |
| 887 | MockRead data_reads[] = { |
| 888 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 889 | MockRead("Content-Length: 5\r\n"), |
| 890 | MockRead("Content-Length: 5\r\n\r\n"), |
| 891 | MockRead("Hello"), |
| 892 | }; |
| 893 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 894 | arraysize(data_reads)); |
| 895 | EXPECT_EQ(OK, out.rv); |
| 896 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 897 | EXPECT_EQ("Hello", out.response_data); |
| 898 | } |
| 899 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 900 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 901 | ComplexContentLengthHeadersNoTransferEncoding) { |
| 902 | // More than 2 dupes. |
| 903 | { |
| 904 | MockRead data_reads[] = { |
| 905 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 906 | MockRead("Content-Length: 5\r\n"), |
| 907 | MockRead("Content-Length: 5\r\n"), |
| 908 | MockRead("Content-Length: 5\r\n\r\n"), |
| 909 | MockRead("Hello"), |
| 910 | }; |
| 911 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 912 | arraysize(data_reads)); |
| 913 | EXPECT_EQ(OK, out.rv); |
| 914 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 915 | EXPECT_EQ("Hello", out.response_data); |
| 916 | } |
| 917 | // HTTP/1.0 |
| 918 | { |
| 919 | MockRead data_reads[] = { |
| 920 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 921 | MockRead("Content-Length: 5\r\n"), |
| 922 | MockRead("Content-Length: 5\r\n"), |
| 923 | MockRead("Content-Length: 5\r\n\r\n"), |
| 924 | MockRead("Hello"), |
| 925 | }; |
| 926 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 927 | arraysize(data_reads)); |
| 928 | EXPECT_EQ(OK, out.rv); |
| 929 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 930 | EXPECT_EQ("Hello", out.response_data); |
| 931 | } |
| 932 | // 2 dupes and one mismatched. |
| 933 | { |
| 934 | MockRead data_reads[] = { |
| 935 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 936 | MockRead("Content-Length: 10\r\n"), |
| 937 | MockRead("Content-Length: 10\r\n"), |
| 938 | MockRead("Content-Length: 5\r\n\r\n"), |
| 939 | }; |
| 940 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 941 | arraysize(data_reads)); |
| 942 | EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH, out.rv); |
| 943 | } |
| 944 | } |
| 945 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 946 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 947 | MultipleContentLengthHeadersTransferEncoding) { |
| 948 | MockRead data_reads[] = { |
| 949 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 950 | MockRead("Content-Length: 666\r\n"), |
| 951 | MockRead("Content-Length: 1337\r\n"), |
| 952 | MockRead("Transfer-Encoding: chunked\r\n\r\n"), |
| 953 | MockRead("5\r\nHello\r\n"), |
| 954 | MockRead("1\r\n"), |
| 955 | MockRead(" \r\n"), |
| 956 | MockRead("5\r\nworld\r\n"), |
| 957 | MockRead("0\r\n\r\nHTTP/1.1 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 958 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 959 | }; |
| 960 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 961 | arraysize(data_reads)); |
| 962 | EXPECT_EQ(OK, out.rv); |
| 963 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 964 | EXPECT_EQ("Hello world", out.response_data); |
| 965 | } |
| 966 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 967 | // Next tests deal with http://crbug.com/98895. |
| 968 | |
| 969 | // Checks that a single Content-Disposition header results in no error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 970 | TEST_P(HttpNetworkTransactionTest, SingleContentDispositionHeader) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 971 | MockRead data_reads[] = { |
| 972 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 973 | MockRead("Content-Disposition: attachment;filename=\"salutations.txt\"r\n"), |
| 974 | MockRead("Content-Length: 5\r\n\r\n"), |
| 975 | MockRead("Hello"), |
| 976 | }; |
| 977 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 978 | arraysize(data_reads)); |
| 979 | EXPECT_EQ(OK, out.rv); |
| 980 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 981 | EXPECT_EQ("Hello", out.response_data); |
| 982 | } |
| 983 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 984 | // Checks that two identical Content-Disposition headers result in no error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 985 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 986 | TwoIdenticalContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 987 | MockRead data_reads[] = { |
| 988 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 989 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 990 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 991 | MockRead("Content-Length: 5\r\n\r\n"), |
| 992 | MockRead("Hello"), |
| 993 | }; |
| 994 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 995 | arraysize(data_reads)); |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 996 | EXPECT_EQ(OK, out.rv); |
| 997 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 998 | EXPECT_EQ("Hello", out.response_data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 999 | } |
| 1000 | |
| 1001 | // Checks that two distinct Content-Disposition headers result in an error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1002 | TEST_P(HttpNetworkTransactionTest, TwoDistinctContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1003 | MockRead data_reads[] = { |
| 1004 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1005 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1006 | MockRead("Content-Disposition: attachment;filename=\"hi.txt\"r\n"), |
| 1007 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1008 | MockRead("Hello"), |
| 1009 | }; |
| 1010 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1011 | arraysize(data_reads)); |
| 1012 | EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION, out.rv); |
| 1013 | } |
| 1014 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1015 | // Checks that two identical Location headers result in no error. |
| 1016 | // Also tests Location header behavior. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1017 | TEST_P(HttpNetworkTransactionTest, TwoIdenticalLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1018 | MockRead data_reads[] = { |
| 1019 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 1020 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1021 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1022 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1023 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1024 | }; |
| 1025 | |
| 1026 | HttpRequestInfo request; |
| 1027 | request.method = "GET"; |
| 1028 | request.url = GURL("http://redirect.com/"); |
| 1029 | request.load_flags = 0; |
| 1030 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1031 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1032 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1033 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1034 | |
| 1035 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1036 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1037 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1038 | TestCompletionCallback callback; |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1039 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1040 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1041 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1042 | |
| 1043 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 1044 | |
| 1045 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1046 | ASSERT_TRUE(response != NULL && response->headers.get() != NULL); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1047 | EXPECT_EQ("HTTP/1.1 302 Redirect", response->headers->GetStatusLine()); |
| 1048 | std::string url; |
| 1049 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 1050 | EXPECT_EQ("http://good.com/", url); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 1051 | EXPECT_TRUE(response->proxy_server.IsEmpty()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1052 | } |
| 1053 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1054 | // Checks that two distinct Location headers result in an error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1055 | TEST_P(HttpNetworkTransactionTest, TwoDistinctLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1056 | MockRead data_reads[] = { |
| 1057 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 1058 | MockRead("Location: http://good.com/\r\n"), |
| 1059 | MockRead("Location: http://evil.com/\r\n"), |
| 1060 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1061 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1062 | }; |
| 1063 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1064 | arraysize(data_reads)); |
| 1065 | EXPECT_EQ(ERR_RESPONSE_HEADERS_MULTIPLE_LOCATION, out.rv); |
| 1066 | } |
| 1067 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1068 | // Do a request using the HEAD method. Verify that we don't try to read the |
| 1069 | // message body (since HEAD has none). |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1070 | TEST_P(HttpNetworkTransactionTest, Head) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1071 | HttpRequestInfo request; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1072 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1073 | request.url = GURL("http://www.example.org/"); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1074 | request.load_flags = 0; |
| 1075 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1076 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1077 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1078 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 1079 | BeforeProxyHeadersSentHandler proxy_headers_handler; |
| 1080 | trans->SetBeforeProxyHeadersSentCallback( |
| 1081 | base::Bind(&BeforeProxyHeadersSentHandler::OnBeforeProxyHeadersSent, |
| 1082 | base::Unretained(&proxy_headers_handler))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1083 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1084 | MockWrite data_writes1[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 1085 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 1086 | "Host: www.example.org\r\n" |
| 1087 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1088 | }; |
| 1089 | MockRead data_reads1[] = { |
| 1090 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 1091 | MockRead("Server: Blah\r\n"), |
| 1092 | MockRead("Content-Length: 1234\r\n\r\n"), |
| 1093 | |
| 1094 | // No response body because the test stops reading here. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1095 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1096 | }; |
| 1097 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1098 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 1099 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1100 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1101 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1102 | TestCompletionCallback callback1; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1103 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1104 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1105 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1106 | |
| 1107 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1108 | EXPECT_EQ(OK, rv); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1109 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1110 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1111 | ASSERT_TRUE(response != NULL); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1112 | |
| 1113 | // Check that the headers got parsed. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1114 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1115 | EXPECT_EQ(1234, response->headers->GetContentLength()); |
| 1116 | EXPECT_EQ("HTTP/1.1 404 Not Found", response->headers->GetStatusLine()); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 1117 | EXPECT_TRUE(response->proxy_server.IsEmpty()); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 1118 | EXPECT_FALSE(proxy_headers_handler.observed_before_proxy_headers_sent()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1119 | |
| 1120 | std::string server_header; |
| 1121 | void* iter = NULL; |
| 1122 | bool has_server_header = response->headers->EnumerateHeader( |
| 1123 | &iter, "Server", &server_header); |
| 1124 | EXPECT_TRUE(has_server_header); |
| 1125 | EXPECT_EQ("Blah", server_header); |
| 1126 | |
| 1127 | // Reading should give EOF right away, since there is no message body |
| 1128 | // (despite non-zero content-length). |
| 1129 | std::string response_data; |
| 1130 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1131 | EXPECT_EQ(OK, rv); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1132 | EXPECT_EQ("", response_data); |
| 1133 | } |
| 1134 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1135 | TEST_P(HttpNetworkTransactionTest, ReuseConnection) { |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1136 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1137 | |
| 1138 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1139 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1140 | MockRead("hello"), |
| 1141 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1142 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1143 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1144 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1145 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1146 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1147 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1148 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1149 | "hello", "world" |
| 1150 | }; |
| 1151 | |
| 1152 | for (int i = 0; i < 2; ++i) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1153 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1154 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1155 | request.url = GURL("http://www.example.org/"); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1156 | request.load_flags = 0; |
| 1157 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1158 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1159 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1160 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1161 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1162 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1163 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1164 | EXPECT_EQ(ERR_IO_PENDING, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1165 | |
| 1166 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1167 | EXPECT_EQ(OK, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1168 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1169 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1170 | ASSERT_TRUE(response != NULL); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1171 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1172 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1173 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 1174 | EXPECT_TRUE(response->proxy_server.IsEmpty()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1175 | |
| 1176 | std::string response_data; |
[email protected] | af4876d | 2008-10-21 23:10:57 | [diff] [blame] | 1177 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1178 | EXPECT_EQ(OK, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1179 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1180 | } |
| 1181 | } |
| 1182 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1183 | TEST_P(HttpNetworkTransactionTest, Ignores100) { |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 1184 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 1185 | element_readers.push_back( |
| 1186 | make_scoped_ptr(new UploadBytesElementReader("foo", 3))); |
| 1187 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1188 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1189 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1190 | request.method = "POST"; |
| 1191 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1192 | request.upload_data_stream = &upload_data_stream; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1193 | request.load_flags = 0; |
| 1194 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1195 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1196 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1197 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1198 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1199 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1200 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 1201 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 1202 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1203 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1204 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1205 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1206 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1207 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1208 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1209 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1210 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1211 | EXPECT_EQ(ERR_IO_PENDING, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1212 | |
| 1213 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1214 | EXPECT_EQ(OK, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1215 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1216 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1217 | ASSERT_TRUE(response != NULL); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1218 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1219 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1220 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1221 | |
| 1222 | std::string response_data; |
[email protected] | af4876d | 2008-10-21 23:10:57 | [diff] [blame] | 1223 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1224 | EXPECT_EQ(OK, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1225 | EXPECT_EQ("hello world", response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1226 | } |
| 1227 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1228 | // This test is almost the same as Ignores100 above, but the response contains |
| 1229 | // 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] | 1230 | // HTTP/1.1 and the two status headers are read in one read. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1231 | TEST_P(HttpNetworkTransactionTest, Ignores1xx) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1232 | HttpRequestInfo request; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1233 | request.method = "GET"; |
| 1234 | request.url = GURL("http://www.foo.com/"); |
| 1235 | request.load_flags = 0; |
| 1236 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1237 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1238 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1239 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1240 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1241 | MockRead data_reads[] = { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1242 | MockRead("HTTP/1.1 102 Unspecified status code\r\n\r\n" |
| 1243 | "HTTP/1.1 200 OK\r\n\r\n"), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1244 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1245 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1246 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1247 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1248 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1249 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1250 | TestCompletionCallback callback; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1251 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1252 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1253 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1254 | |
| 1255 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1256 | EXPECT_EQ(OK, rv); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1257 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1258 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1259 | ASSERT_TRUE(response != NULL); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1260 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1261 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1262 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1263 | |
| 1264 | std::string response_data; |
| 1265 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1266 | EXPECT_EQ(OK, rv); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1267 | EXPECT_EQ("hello world", response_data); |
| 1268 | } |
| 1269 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1270 | TEST_P(HttpNetworkTransactionTest, Incomplete100ThenEOF) { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1271 | HttpRequestInfo request; |
| 1272 | request.method = "POST"; |
| 1273 | request.url = GURL("http://www.foo.com/"); |
| 1274 | request.load_flags = 0; |
| 1275 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1276 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1277 | scoped_ptr<HttpTransaction> trans( |
| 1278 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 1279 | |
| 1280 | MockRead data_reads[] = { |
| 1281 | MockRead(SYNCHRONOUS, "HTTP/1.0 100 Continue\r\n"), |
| 1282 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1283 | }; |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1284 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 1285 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1286 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1287 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1288 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1289 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1290 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1291 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1292 | rv = callback.WaitForResult(); |
| 1293 | EXPECT_EQ(OK, rv); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1294 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1295 | std::string response_data; |
| 1296 | rv = ReadTransaction(trans.get(), &response_data); |
| 1297 | EXPECT_EQ(OK, rv); |
| 1298 | EXPECT_EQ("", response_data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1299 | } |
| 1300 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1301 | TEST_P(HttpNetworkTransactionTest, EmptyResponse) { |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1302 | HttpRequestInfo request; |
| 1303 | request.method = "POST"; |
| 1304 | request.url = GURL("http://www.foo.com/"); |
| 1305 | request.load_flags = 0; |
| 1306 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1307 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1308 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1309 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1310 | |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1311 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1312 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1313 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1314 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1315 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1316 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1317 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1318 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1319 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1320 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1321 | |
| 1322 | rv = callback.WaitForResult(); |
| 1323 | EXPECT_EQ(ERR_EMPTY_RESPONSE, rv); |
| 1324 | } |
| 1325 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1326 | void HttpNetworkTransactionTest::KeepAliveConnectionResendRequestTest( |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1327 | const MockWrite* write_failure, |
| 1328 | const MockRead* read_failure) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1329 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1330 | request.method = "GET"; |
| 1331 | request.url = GURL("http://www.foo.com/"); |
| 1332 | request.load_flags = 0; |
| 1333 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1334 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1335 | session_deps_.net_log = &net_log; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1336 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1337 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1338 | // Written data for successfully sending both requests. |
| 1339 | MockWrite data1_writes[] = { |
| 1340 | MockWrite("GET / HTTP/1.1\r\n" |
| 1341 | "Host: www.foo.com\r\n" |
| 1342 | "Connection: keep-alive\r\n\r\n"), |
| 1343 | MockWrite("GET / HTTP/1.1\r\n" |
| 1344 | "Host: www.foo.com\r\n" |
| 1345 | "Connection: keep-alive\r\n\r\n") |
| 1346 | }; |
| 1347 | |
| 1348 | // Read results for the first request. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1349 | MockRead data1_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1350 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1351 | MockRead("hello"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1352 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1353 | }; |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1354 | |
| 1355 | if (write_failure) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1356 | ASSERT_FALSE(read_failure); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1357 | data1_writes[1] = *write_failure; |
| 1358 | } else { |
| 1359 | ASSERT_TRUE(read_failure); |
| 1360 | data1_reads[2] = *read_failure; |
| 1361 | } |
| 1362 | |
| 1363 | StaticSocketDataProvider data1(data1_reads, arraysize(data1_reads), |
| 1364 | data1_writes, arraysize(data1_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1365 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1366 | |
| 1367 | MockRead data2_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1368 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1369 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1370 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1371 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1372 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1373 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1374 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 1375 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1376 | "hello", "world" |
| 1377 | }; |
| 1378 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1379 | uint32 first_socket_log_id = NetLog::Source::kInvalidId; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1380 | for (int i = 0; i < 2; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1381 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1382 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1383 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1384 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1385 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1386 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1387 | EXPECT_EQ(ERR_IO_PENDING, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1388 | |
| 1389 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1390 | EXPECT_EQ(OK, rv); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1391 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1392 | LoadTimingInfo load_timing_info; |
| 1393 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 1394 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1395 | if (i == 0) { |
| 1396 | first_socket_log_id = load_timing_info.socket_log_id; |
| 1397 | } else { |
| 1398 | // The second request should be using a new socket. |
| 1399 | EXPECT_NE(first_socket_log_id, load_timing_info.socket_log_id); |
| 1400 | } |
| 1401 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1402 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 1403 | ASSERT_TRUE(response != NULL); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1404 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1405 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1406 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1407 | |
| 1408 | std::string response_data; |
[email protected] | af4876d | 2008-10-21 23:10:57 | [diff] [blame] | 1409 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1410 | EXPECT_EQ(OK, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1411 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1412 | } |
| 1413 | } |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1414 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1415 | void HttpNetworkTransactionTest::PreconnectErrorResendRequestTest( |
| 1416 | const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1417 | const MockRead* read_failure, |
| 1418 | bool use_spdy) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1419 | HttpRequestInfo request; |
| 1420 | request.method = "GET"; |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1421 | request.url = GURL("https://www.foo.com/"); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1422 | request.load_flags = 0; |
| 1423 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1424 | TestNetLog net_log; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1425 | session_deps_.net_log = &net_log; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1426 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1427 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1428 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 1429 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 1430 | if (use_spdy) { |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 1431 | ssl1.SetNextProto(GetProtocol()); |
| 1432 | ssl2.SetNextProto(GetProtocol()); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1433 | } |
| 1434 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 1435 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1436 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1437 | // SPDY versions of the request and response. |
| 1438 | scoped_ptr<SpdyFrame> spdy_request(spdy_util_.ConstructSpdyGet( |
| 1439 | request.url.spec().c_str(), false, 1, DEFAULT_PRIORITY)); |
| 1440 | scoped_ptr<SpdyFrame> spdy_response( |
| 1441 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 1442 | scoped_ptr<SpdyFrame> spdy_data( |
| 1443 | spdy_util_.ConstructSpdyBodyFrame(1, "hello", 5, true)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1444 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1445 | // HTTP/1.1 versions of the request and response. |
| 1446 | const char kHttpRequest[] = "GET / HTTP/1.1\r\n" |
| 1447 | "Host: www.foo.com\r\n" |
| 1448 | "Connection: keep-alive\r\n\r\n"; |
| 1449 | const char kHttpResponse[] = "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"; |
| 1450 | const char kHttpData[] = "hello"; |
| 1451 | |
| 1452 | std::vector<MockRead> data1_reads; |
| 1453 | std::vector<MockWrite> data1_writes; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1454 | if (write_failure) { |
| 1455 | ASSERT_FALSE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1456 | data1_writes.push_back(*write_failure); |
| 1457 | data1_reads.push_back(MockRead(ASYNC, OK)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1458 | } else { |
| 1459 | ASSERT_TRUE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1460 | if (use_spdy) { |
| 1461 | data1_writes.push_back(CreateMockWrite(*spdy_request)); |
| 1462 | } else { |
| 1463 | data1_writes.push_back(MockWrite(kHttpRequest)); |
| 1464 | } |
| 1465 | data1_reads.push_back(*read_failure); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1466 | } |
| 1467 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1468 | StaticSocketDataProvider data1(&data1_reads[0], data1_reads.size(), |
| 1469 | &data1_writes[0], data1_writes.size()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1470 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1471 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1472 | std::vector<MockRead> data2_reads; |
| 1473 | std::vector<MockWrite> data2_writes; |
| 1474 | |
| 1475 | if (use_spdy) { |
| 1476 | data2_writes.push_back(CreateMockWrite(*spdy_request, 0, ASYNC)); |
| 1477 | |
| 1478 | data2_reads.push_back(CreateMockRead(*spdy_response, 1, ASYNC)); |
| 1479 | data2_reads.push_back(CreateMockRead(*spdy_data, 2, ASYNC)); |
| 1480 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1481 | } else { |
| 1482 | data2_writes.push_back( |
| 1483 | MockWrite(ASYNC, kHttpRequest, strlen(kHttpRequest), 0)); |
| 1484 | |
| 1485 | data2_reads.push_back( |
| 1486 | MockRead(ASYNC, kHttpResponse, strlen(kHttpResponse), 1)); |
| 1487 | data2_reads.push_back(MockRead(ASYNC, kHttpData, strlen(kHttpData), 2)); |
| 1488 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1489 | } |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 1490 | SequencedSocketData data2(&data2_reads[0], data2_reads.size(), |
| 1491 | &data2_writes[0], data2_writes.size()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1492 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1493 | |
| 1494 | // Preconnect a socket. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 1495 | SSLConfig ssl_config; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1496 | session->ssl_config_service()->GetSSLConfig(&ssl_config); |
bnc | 1f29537 | 2015-10-21 23:24:22 | [diff] [blame] | 1497 | session->GetAlpnProtos(&ssl_config.alpn_protos); |
| 1498 | session->GetNpnProtos(&ssl_config.npn_protos); |
mmenke | d1205bd397 | 2015-07-15 22:26:35 | [diff] [blame] | 1499 | session->http_stream_factory()->PreconnectStreams(1, request, ssl_config, |
| 1500 | ssl_config); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1501 | // Wait for the preconnect to complete. |
| 1502 | // TODO(davidben): Some way to wait for an idle socket count might be handy. |
| 1503 | base::RunLoop().RunUntilIdle(); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1504 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1505 | |
| 1506 | // Make the request. |
| 1507 | TestCompletionCallback callback; |
| 1508 | |
| 1509 | scoped_ptr<HttpTransaction> trans( |
| 1510 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 1511 | |
| 1512 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1513 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1514 | |
| 1515 | rv = callback.WaitForResult(); |
| 1516 | EXPECT_EQ(OK, rv); |
| 1517 | |
| 1518 | LoadTimingInfo load_timing_info; |
| 1519 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1520 | TestLoadTimingNotReused( |
| 1521 | load_timing_info, |
| 1522 | CONNECT_TIMING_HAS_DNS_TIMES|CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1523 | |
| 1524 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 1525 | ASSERT_TRUE(response != NULL); |
| 1526 | |
| 1527 | EXPECT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1528 | if (response->was_fetched_via_spdy) { |
| 1529 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 1530 | } else { |
| 1531 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1532 | } |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1533 | |
| 1534 | std::string response_data; |
| 1535 | rv = ReadTransaction(trans.get(), &response_data); |
| 1536 | EXPECT_EQ(OK, rv); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1537 | EXPECT_EQ(kHttpData, response_data); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1538 | } |
| 1539 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1540 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 1541 | KeepAliveConnectionNotConnectedOnWrite) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1542 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1543 | KeepAliveConnectionResendRequestTest(&write_failure, NULL); |
| 1544 | } |
| 1545 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1546 | TEST_P(HttpNetworkTransactionTest, KeepAliveConnectionReset) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1547 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1548 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1549 | } |
| 1550 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1551 | TEST_P(HttpNetworkTransactionTest, KeepAliveConnectionEOF) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1552 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1553 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1554 | } |
| 1555 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1556 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1557 | // if the socket was a reused keep alive socket. |
| 1558 | TEST_P(HttpNetworkTransactionTest, KeepAlive408) { |
| 1559 | MockRead read_failure(SYNCHRONOUS, |
| 1560 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1561 | "Connection: Keep-Alive\r\n" |
| 1562 | "Content-Length: 6\r\n\r\n" |
| 1563 | "Pickle"); |
| 1564 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
| 1565 | } |
| 1566 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1567 | TEST_P(HttpNetworkTransactionTest, |
| 1568 | PreconnectErrorNotConnectedOnWrite) { |
| 1569 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1570 | PreconnectErrorResendRequestTest(&write_failure, NULL, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1571 | } |
| 1572 | |
| 1573 | TEST_P(HttpNetworkTransactionTest, PreconnectErrorReset) { |
| 1574 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1575 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1576 | } |
| 1577 | |
| 1578 | TEST_P(HttpNetworkTransactionTest, PreconnectErrorEOF) { |
| 1579 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1580 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1581 | } |
| 1582 | |
| 1583 | TEST_P(HttpNetworkTransactionTest, PreconnectErrorAsyncEOF) { |
| 1584 | MockRead read_failure(ASYNC, OK); // EOF |
| 1585 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1586 | } |
| 1587 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1588 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1589 | // if the socket was a preconnected (UNUSED_IDLE) socket. |
| 1590 | TEST_P(HttpNetworkTransactionTest, RetryOnIdle408) { |
| 1591 | MockRead read_failure(SYNCHRONOUS, |
| 1592 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1593 | "Connection: Keep-Alive\r\n" |
| 1594 | "Content-Length: 6\r\n\r\n" |
| 1595 | "Pickle"); |
| 1596 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
| 1597 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1598 | } |
| 1599 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1600 | TEST_P(HttpNetworkTransactionTest, |
| 1601 | SpdyPreconnectErrorNotConnectedOnWrite) { |
| 1602 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
| 1603 | PreconnectErrorResendRequestTest(&write_failure, NULL, true); |
| 1604 | } |
| 1605 | |
| 1606 | TEST_P(HttpNetworkTransactionTest, SpdyPreconnectErrorReset) { |
| 1607 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
| 1608 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
| 1609 | } |
| 1610 | |
| 1611 | TEST_P(HttpNetworkTransactionTest, SpdyPreconnectErrorEOF) { |
| 1612 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
| 1613 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
| 1614 | } |
| 1615 | |
| 1616 | TEST_P(HttpNetworkTransactionTest, SpdyPreconnectErrorAsyncEOF) { |
| 1617 | MockRead read_failure(ASYNC, OK); // EOF |
| 1618 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1619 | } |
| 1620 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1621 | TEST_P(HttpNetworkTransactionTest, NonKeepAliveConnectionReset) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1622 | HttpRequestInfo request; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1623 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1624 | request.url = GURL("http://www.example.org/"); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1625 | request.load_flags = 0; |
| 1626 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1627 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1628 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1629 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1630 | |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1631 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1632 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1633 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 1634 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1635 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1636 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1637 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1638 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1639 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1640 | TestCompletionCallback callback; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1641 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1642 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1643 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1644 | |
| 1645 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1646 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 1647 | |
| 1648 | IPEndPoint endpoint; |
| 1649 | EXPECT_TRUE(trans->GetRemoteEndpoint(&endpoint)); |
| 1650 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1651 | } |
| 1652 | |
| 1653 | // What do various browsers do when the server closes a non-keepalive |
| 1654 | // connection without sending any response header or body? |
| 1655 | // |
| 1656 | // IE7: error page |
| 1657 | // Safari 3.1.2 (Windows): error page |
| 1658 | // Firefox 3.0.1: blank page |
| 1659 | // Opera 9.52: after five attempts, blank page |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1660 | // Us with WinHTTP: error page (ERR_INVALID_RESPONSE) |
| 1661 | // Us: error page (EMPTY_RESPONSE) |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1662 | TEST_P(HttpNetworkTransactionTest, NonKeepAliveConnectionEOF) { |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1663 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1664 | MockRead(SYNCHRONOUS, OK), // EOF |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1665 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 1666 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1667 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1668 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1669 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1670 | arraysize(data_reads)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1671 | EXPECT_EQ(ERR_EMPTY_RESPONSE, out.rv); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1672 | } |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1673 | |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1674 | // Test that network access can be deferred and resumed. |
| 1675 | TEST_P(HttpNetworkTransactionTest, ThrottleBeforeNetworkStart) { |
| 1676 | HttpRequestInfo request; |
| 1677 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1678 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1679 | request.load_flags = 0; |
| 1680 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1681 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1682 | scoped_ptr<HttpTransaction> trans( |
| 1683 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 1684 | |
| 1685 | // Defer on OnBeforeNetworkStart. |
| 1686 | BeforeNetworkStartHandler net_start_handler(true); // defer |
| 1687 | trans->SetBeforeNetworkStartCallback( |
| 1688 | base::Bind(&BeforeNetworkStartHandler::OnBeforeNetworkStart, |
| 1689 | base::Unretained(&net_start_handler))); |
| 1690 | |
| 1691 | MockRead data_reads[] = { |
| 1692 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1693 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1694 | MockRead("hello"), |
| 1695 | MockRead(SYNCHRONOUS, 0), |
| 1696 | }; |
| 1697 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 1698 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 1699 | |
| 1700 | TestCompletionCallback callback; |
| 1701 | |
| 1702 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1703 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1704 | base::MessageLoop::current()->RunUntilIdle(); |
| 1705 | |
| 1706 | // Should have deferred for network start. |
| 1707 | EXPECT_TRUE(net_start_handler.observed_before_network_start()); |
| 1708 | EXPECT_EQ(LOAD_STATE_WAITING_FOR_DELEGATE, trans->GetLoadState()); |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1709 | |
| 1710 | trans->ResumeNetworkStart(); |
| 1711 | rv = callback.WaitForResult(); |
| 1712 | EXPECT_EQ(OK, rv); |
| 1713 | EXPECT_TRUE(trans->GetResponseInfo() != NULL); |
| 1714 | |
| 1715 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
| 1716 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
| 1717 | if (rv == ERR_IO_PENDING) |
| 1718 | rv = callback.WaitForResult(); |
| 1719 | EXPECT_EQ(5, rv); |
| 1720 | trans.reset(); |
| 1721 | } |
| 1722 | |
| 1723 | // Test that network use can be deferred and canceled. |
| 1724 | TEST_P(HttpNetworkTransactionTest, ThrottleAndCancelBeforeNetworkStart) { |
| 1725 | HttpRequestInfo request; |
| 1726 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1727 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1728 | request.load_flags = 0; |
| 1729 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1730 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1731 | scoped_ptr<HttpTransaction> trans( |
| 1732 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 1733 | |
| 1734 | // Defer on OnBeforeNetworkStart. |
| 1735 | BeforeNetworkStartHandler net_start_handler(true); // defer |
| 1736 | trans->SetBeforeNetworkStartCallback( |
| 1737 | base::Bind(&BeforeNetworkStartHandler::OnBeforeNetworkStart, |
| 1738 | base::Unretained(&net_start_handler))); |
| 1739 | |
| 1740 | TestCompletionCallback callback; |
| 1741 | |
| 1742 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1743 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1744 | base::MessageLoop::current()->RunUntilIdle(); |
| 1745 | |
| 1746 | // Should have deferred for network start. |
| 1747 | EXPECT_TRUE(net_start_handler.observed_before_network_start()); |
| 1748 | EXPECT_EQ(LOAD_STATE_WAITING_FOR_DELEGATE, trans->GetLoadState()); |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1749 | } |
| 1750 | |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1751 | // Next 2 cases (KeepAliveEarlyClose and KeepAliveEarlyClose2) are regression |
| 1752 | // tests. There was a bug causing HttpNetworkTransaction to hang in the |
| 1753 | // destructor in such situations. |
| 1754 | // See http://crbug.com/154712 and http://crbug.com/156609. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1755 | TEST_P(HttpNetworkTransactionTest, KeepAliveEarlyClose) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1756 | HttpRequestInfo request; |
| 1757 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1758 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1759 | request.load_flags = 0; |
| 1760 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1761 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1762 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1763 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1764 | |
| 1765 | MockRead data_reads[] = { |
| 1766 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1767 | MockRead("Connection: keep-alive\r\n"), |
| 1768 | MockRead("Content-Length: 100\r\n\r\n"), |
| 1769 | MockRead("hello"), |
| 1770 | MockRead(SYNCHRONOUS, 0), |
| 1771 | }; |
| 1772 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1773 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1774 | |
| 1775 | TestCompletionCallback callback; |
| 1776 | |
| 1777 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1778 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1779 | |
| 1780 | rv = callback.WaitForResult(); |
| 1781 | EXPECT_EQ(OK, rv); |
| 1782 | |
| 1783 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1784 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1785 | if (rv == ERR_IO_PENDING) |
| 1786 | rv = callback.WaitForResult(); |
| 1787 | EXPECT_EQ(5, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1788 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1789 | EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, rv); |
| 1790 | |
| 1791 | trans.reset(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 1792 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1793 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 1794 | } |
| 1795 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1796 | TEST_P(HttpNetworkTransactionTest, KeepAliveEarlyClose2) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1797 | HttpRequestInfo request; |
| 1798 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1799 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1800 | request.load_flags = 0; |
| 1801 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1802 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1803 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1804 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1805 | |
| 1806 | MockRead data_reads[] = { |
| 1807 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1808 | MockRead("Connection: keep-alive\r\n"), |
| 1809 | MockRead("Content-Length: 100\r\n\r\n"), |
| 1810 | MockRead(SYNCHRONOUS, 0), |
| 1811 | }; |
| 1812 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1813 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1814 | |
| 1815 | TestCompletionCallback callback; |
| 1816 | |
| 1817 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 1818 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1819 | |
| 1820 | rv = callback.WaitForResult(); |
| 1821 | EXPECT_EQ(OK, rv); |
| 1822 | |
| 1823 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1824 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1825 | if (rv == ERR_IO_PENDING) |
| 1826 | rv = callback.WaitForResult(); |
| 1827 | EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, rv); |
| 1828 | |
| 1829 | trans.reset(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 1830 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1831 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 1832 | } |
| 1833 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1834 | // Test that we correctly reuse a keep-alive connection after not explicitly |
| 1835 | // reading the body. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1836 | TEST_P(HttpNetworkTransactionTest, KeepAliveAfterUnreadBody) { |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1837 | HttpRequestInfo request; |
| 1838 | request.method = "GET"; |
| 1839 | request.url = GURL("http://www.foo.com/"); |
| 1840 | request.load_flags = 0; |
| 1841 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1842 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1843 | session_deps_.net_log = &net_log; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1844 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1845 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1846 | // Note that because all these reads happen in the same |
| 1847 | // StaticSocketDataProvider, it shows that the same socket is being reused for |
| 1848 | // all transactions. |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1849 | MockRead data1_reads[] = { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1850 | MockRead("HTTP/1.1 204 No Content\r\n\r\n"), |
| 1851 | MockRead("HTTP/1.1 205 Reset Content\r\n\r\n"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1852 | MockRead("HTTP/1.1 304 Not Modified\r\n\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1853 | MockRead("HTTP/1.1 302 Found\r\n" |
| 1854 | "Content-Length: 0\r\n\r\n"), |
| 1855 | MockRead("HTTP/1.1 302 Found\r\n" |
| 1856 | "Content-Length: 5\r\n\r\n" |
| 1857 | "hello"), |
| 1858 | MockRead("HTTP/1.1 301 Moved Permanently\r\n" |
| 1859 | "Content-Length: 0\r\n\r\n"), |
| 1860 | MockRead("HTTP/1.1 301 Moved Permanently\r\n" |
| 1861 | "Content-Length: 5\r\n\r\n" |
| 1862 | "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1863 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1864 | MockRead("hello"), |
| 1865 | }; |
| 1866 | StaticSocketDataProvider data1(data1_reads, arraysize(data1_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1867 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1868 | |
| 1869 | MockRead data2_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1870 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1871 | }; |
| 1872 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1873 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1874 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1875 | const int kNumUnreadBodies = arraysize(data1_reads) - 2; |
| 1876 | std::string response_lines[kNumUnreadBodies]; |
| 1877 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1878 | uint32 first_socket_log_id = NetLog::Source::kInvalidId; |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1879 | for (size_t i = 0; i < arraysize(data1_reads) - 2; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1880 | TestCompletionCallback callback; |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1881 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1882 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1883 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1884 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1885 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1886 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1887 | |
| 1888 | rv = callback.WaitForResult(); |
| 1889 | EXPECT_EQ(OK, rv); |
| 1890 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1891 | LoadTimingInfo load_timing_info; |
| 1892 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 1893 | if (i == 0) { |
| 1894 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1895 | first_socket_log_id = load_timing_info.socket_log_id; |
| 1896 | } else { |
| 1897 | TestLoadTimingReused(load_timing_info); |
| 1898 | EXPECT_EQ(first_socket_log_id, load_timing_info.socket_log_id); |
| 1899 | } |
| 1900 | |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1901 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1902 | ASSERT_TRUE(response != NULL); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1903 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1904 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1905 | response_lines[i] = response->headers->GetStatusLine(); |
| 1906 | |
| 1907 | // We intentionally don't read the response bodies. |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1908 | } |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1909 | |
| 1910 | const char* const kStatusLines[] = { |
| 1911 | "HTTP/1.1 204 No Content", |
| 1912 | "HTTP/1.1 205 Reset Content", |
| 1913 | "HTTP/1.1 304 Not Modified", |
| 1914 | "HTTP/1.1 302 Found", |
| 1915 | "HTTP/1.1 302 Found", |
| 1916 | "HTTP/1.1 301 Moved Permanently", |
| 1917 | "HTTP/1.1 301 Moved Permanently", |
| 1918 | }; |
| 1919 | |
mostynb | 91e0da98 | 2015-01-20 19:17:27 | [diff] [blame] | 1920 | static_assert(kNumUnreadBodies == arraysize(kStatusLines), |
| 1921 | "forgot to update kStatusLines"); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1922 | |
| 1923 | for (int i = 0; i < kNumUnreadBodies; ++i) |
| 1924 | EXPECT_EQ(kStatusLines[i], response_lines[i]); |
| 1925 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1926 | TestCompletionCallback callback; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1927 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1928 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1929 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1930 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1931 | rv = callback.WaitForResult(); |
| 1932 | EXPECT_EQ(OK, rv); |
| 1933 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 1934 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1935 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1936 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1937 | std::string response_data; |
| 1938 | rv = ReadTransaction(trans.get(), &response_data); |
| 1939 | EXPECT_EQ(OK, rv); |
| 1940 | EXPECT_EQ("hello", response_data); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1941 | } |
| 1942 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1943 | // Test the request-challenge-retry sequence for basic auth. |
| 1944 | // (basic auth is the easiest to mock, because it has no randomness). |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1945 | TEST_P(HttpNetworkTransactionTest, BasicAuth) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1946 | HttpRequestInfo request; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1947 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1948 | request.url = GURL("http://www.example.org/"); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1949 | request.load_flags = 0; |
| 1950 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1951 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1952 | session_deps_.net_log = &log; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1953 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1954 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 1955 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1956 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 1957 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1958 | MockWrite( |
| 1959 | "GET / HTTP/1.1\r\n" |
| 1960 | "Host: www.example.org\r\n" |
| 1961 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 1962 | }; |
| 1963 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1964 | MockRead data_reads1[] = { |
| 1965 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 1966 | // Give a couple authenticate options (only the middle one is actually |
| 1967 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 1968 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1969 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 1970 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 1971 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 1972 | // Large content-length -- won't matter, as connection will be reset. |
| 1973 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1974 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1975 | }; |
| 1976 | |
| 1977 | // After calling trans->RestartWithAuth(), this is the request we should |
| 1978 | // be issuing -- the final header line contains the credentials. |
| 1979 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1980 | MockWrite( |
| 1981 | "GET / HTTP/1.1\r\n" |
| 1982 | "Host: www.example.org\r\n" |
| 1983 | "Connection: keep-alive\r\n" |
| 1984 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1985 | }; |
| 1986 | |
| 1987 | // Lastly, the server responds with the actual content. |
| 1988 | MockRead data_reads2[] = { |
| 1989 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1990 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 1991 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1992 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 1993 | }; |
| 1994 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1995 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 1996 | data_writes1, arraysize(data_writes1)); |
| 1997 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 1998 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1999 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2000 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2001 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2002 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2003 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2004 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2005 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2006 | |
| 2007 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2008 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2009 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2010 | LoadTimingInfo load_timing_info1; |
| 2011 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info1)); |
| 2012 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2013 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2014 | int64_t writes_size1 = CountWriteBytes(data_writes1, arraysize(data_writes1)); |
| 2015 | EXPECT_EQ(writes_size1, trans->GetTotalSentBytes()); |
| 2016 | int64_t reads_size1 = CountReadBytes(data_reads1, arraysize(data_reads1)); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2017 | EXPECT_EQ(reads_size1, trans->GetTotalReceivedBytes()); |
| 2018 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2019 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2020 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2021 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2022 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2023 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2024 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2025 | rv = trans->RestartWithAuth( |
| 2026 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2027 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2028 | |
| 2029 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2030 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2031 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2032 | LoadTimingInfo load_timing_info2; |
| 2033 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info2)); |
| 2034 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2035 | // The load timing after restart should have a new socket ID, and times after |
| 2036 | // those of the first load timing. |
| 2037 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2038 | load_timing_info2.connect_timing.connect_start); |
| 2039 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2040 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2041 | int64_t writes_size2 = CountWriteBytes(data_writes2, arraysize(data_writes2)); |
| 2042 | EXPECT_EQ(writes_size1 + writes_size2, trans->GetTotalSentBytes()); |
| 2043 | int64_t reads_size2 = CountReadBytes(data_reads2, arraysize(data_reads2)); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2044 | EXPECT_EQ(reads_size1 + reads_size2, trans->GetTotalReceivedBytes()); |
| 2045 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2046 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2047 | ASSERT_TRUE(response != NULL); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2048 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 2049 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2050 | } |
| 2051 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2052 | // Test the request-challenge-retry sequence for basic auth. |
| 2053 | // (basic auth is the easiest to mock, because it has no randomness). |
| 2054 | TEST_P(HttpNetworkTransactionTest, BasicAuthWithAddressChange) { |
| 2055 | HttpRequestInfo request; |
| 2056 | request.method = "GET"; |
| 2057 | request.url = GURL("http://www.example.org/"); |
| 2058 | request.load_flags = 0; |
| 2059 | |
| 2060 | TestNetLog log; |
| 2061 | MockHostResolver* resolver = new MockHostResolver(); |
| 2062 | session_deps_.net_log = &log; |
| 2063 | session_deps_.host_resolver.reset(resolver); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 2064 | scoped_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2065 | scoped_ptr<HttpTransaction> trans( |
| 2066 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 2067 | |
| 2068 | resolver->rules()->ClearRules(); |
| 2069 | resolver->rules()->AddRule("www.example.org", "127.0.0.1"); |
| 2070 | |
| 2071 | MockWrite data_writes1[] = { |
| 2072 | MockWrite("GET / HTTP/1.1\r\n" |
| 2073 | "Host: www.example.org\r\n" |
| 2074 | "Connection: keep-alive\r\n\r\n"), |
| 2075 | }; |
| 2076 | |
| 2077 | MockRead data_reads1[] = { |
| 2078 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2079 | // Give a couple authenticate options (only the middle one is actually |
| 2080 | // supported). |
| 2081 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 2082 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2083 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2084 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2085 | // Large content-length -- won't matter, as connection will be reset. |
| 2086 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 2087 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 2088 | }; |
| 2089 | |
| 2090 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2091 | // be issuing -- the final header line contains the credentials. |
| 2092 | MockWrite data_writes2[] = { |
| 2093 | MockWrite("GET / HTTP/1.1\r\n" |
| 2094 | "Host: www.example.org\r\n" |
| 2095 | "Connection: keep-alive\r\n" |
| 2096 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2097 | }; |
| 2098 | |
| 2099 | // Lastly, the server responds with the actual content. |
| 2100 | MockRead data_reads2[] = { |
| 2101 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2102 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2103 | MockRead("Content-Length: 100\r\n\r\n"), MockRead(SYNCHRONOUS, OK), |
| 2104 | }; |
| 2105 | |
| 2106 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2107 | data_writes1, arraysize(data_writes1)); |
| 2108 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2109 | data_writes2, arraysize(data_writes2)); |
| 2110 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2111 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2112 | |
| 2113 | TestCompletionCallback callback1; |
| 2114 | |
| 2115 | EXPECT_EQ(OK, callback1.GetResult(trans->Start(&request, callback1.callback(), |
| 2116 | BoundNetLog()))); |
| 2117 | |
| 2118 | LoadTimingInfo load_timing_info1; |
| 2119 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info1)); |
| 2120 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2121 | |
| 2122 | int64_t writes_size1 = CountWriteBytes(data_writes1, arraysize(data_writes1)); |
| 2123 | EXPECT_EQ(writes_size1, trans->GetTotalSentBytes()); |
| 2124 | int64_t reads_size1 = CountReadBytes(data_reads1, arraysize(data_reads1)); |
| 2125 | EXPECT_EQ(reads_size1, trans->GetTotalReceivedBytes()); |
| 2126 | |
| 2127 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 2128 | ASSERT_TRUE(response); |
| 2129 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 2130 | |
| 2131 | IPEndPoint endpoint; |
| 2132 | EXPECT_TRUE(trans->GetRemoteEndpoint(&endpoint)); |
| 2133 | ASSERT_FALSE(endpoint.address().empty()); |
| 2134 | EXPECT_EQ("127.0.0.1:80", endpoint.ToString()); |
| 2135 | |
| 2136 | resolver->rules()->ClearRules(); |
| 2137 | resolver->rules()->AddRule("www.example.org", "127.0.0.2"); |
| 2138 | |
| 2139 | TestCompletionCallback callback2; |
| 2140 | |
| 2141 | EXPECT_EQ(OK, callback2.GetResult(trans->RestartWithAuth( |
| 2142 | AuthCredentials(kFoo, kBar), callback2.callback()))); |
| 2143 | |
| 2144 | LoadTimingInfo load_timing_info2; |
| 2145 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info2)); |
| 2146 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2147 | // The load timing after restart should have a new socket ID, and times after |
| 2148 | // those of the first load timing. |
| 2149 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2150 | load_timing_info2.connect_timing.connect_start); |
| 2151 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2152 | |
| 2153 | int64_t writes_size2 = CountWriteBytes(data_writes2, arraysize(data_writes2)); |
| 2154 | EXPECT_EQ(writes_size1 + writes_size2, trans->GetTotalSentBytes()); |
| 2155 | int64_t reads_size2 = CountReadBytes(data_reads2, arraysize(data_reads2)); |
| 2156 | EXPECT_EQ(reads_size1 + reads_size2, trans->GetTotalReceivedBytes()); |
| 2157 | |
| 2158 | response = trans->GetResponseInfo(); |
| 2159 | ASSERT_TRUE(response); |
| 2160 | EXPECT_FALSE(response->auth_challenge.get()); |
| 2161 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 2162 | |
| 2163 | EXPECT_TRUE(trans->GetRemoteEndpoint(&endpoint)); |
| 2164 | ASSERT_FALSE(endpoint.address().empty()); |
| 2165 | EXPECT_EQ("127.0.0.2:80", endpoint.ToString()); |
| 2166 | } |
| 2167 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2168 | TEST_P(HttpNetworkTransactionTest, DoNotSendAuth) { |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2169 | HttpRequestInfo request; |
| 2170 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2171 | request.url = GURL("http://www.example.org/"); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2172 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2173 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 2174 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2175 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 2176 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2177 | |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2178 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2179 | MockWrite( |
| 2180 | "GET / HTTP/1.1\r\n" |
| 2181 | "Host: www.example.org\r\n" |
| 2182 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2183 | }; |
| 2184 | |
| 2185 | MockRead data_reads[] = { |
| 2186 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2187 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2188 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2189 | // Large content-length -- won't matter, as connection will be reset. |
| 2190 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2191 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2192 | }; |
| 2193 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2194 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 2195 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2196 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2197 | TestCompletionCallback callback; |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2198 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2199 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2200 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2201 | |
| 2202 | rv = callback.WaitForResult(); |
| 2203 | EXPECT_EQ(0, rv); |
| 2204 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2205 | int64_t writes_size = CountWriteBytes(data_writes, arraysize(data_writes)); |
| 2206 | EXPECT_EQ(writes_size, trans->GetTotalSentBytes()); |
| 2207 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2208 | EXPECT_EQ(reads_size, trans->GetTotalReceivedBytes()); |
| 2209 | |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2210 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2211 | ASSERT_TRUE(response != NULL); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2212 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 2213 | } |
| 2214 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2215 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2216 | // connection. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2217 | TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAlive) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2218 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2219 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2220 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2221 | request.load_flags = 0; |
| 2222 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2223 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2224 | session_deps_.net_log = &log; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 2225 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2226 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2227 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2228 | MockWrite( |
| 2229 | "GET / HTTP/1.1\r\n" |
| 2230 | "Host: www.example.org\r\n" |
| 2231 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2232 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2233 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2234 | // be issuing -- the final header line contains the credentials. |
| 2235 | MockWrite( |
| 2236 | "GET / HTTP/1.1\r\n" |
| 2237 | "Host: www.example.org\r\n" |
| 2238 | "Connection: keep-alive\r\n" |
| 2239 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2240 | }; |
| 2241 | |
| 2242 | MockRead data_reads1[] = { |
| 2243 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2244 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2245 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2246 | MockRead("Content-Length: 14\r\n\r\n"), |
| 2247 | MockRead("Unauthorized\r\n"), |
| 2248 | |
| 2249 | // Lastly, the server responds with the actual content. |
| 2250 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2251 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2252 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2253 | MockRead("Hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2254 | }; |
| 2255 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2256 | // If there is a regression where we disconnect a Keep-Alive |
| 2257 | // connection during an auth roundtrip, we'll end up reading this. |
| 2258 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2259 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2260 | }; |
| 2261 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2262 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2263 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2264 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2265 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2266 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2267 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2268 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2269 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2270 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2271 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2272 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2273 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2274 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2275 | |
| 2276 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2277 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2278 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2279 | LoadTimingInfo load_timing_info1; |
| 2280 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info1)); |
| 2281 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2282 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2283 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2284 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2285 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2286 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2287 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2288 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2289 | rv = trans->RestartWithAuth( |
| 2290 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2291 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2292 | |
| 2293 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2294 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2295 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2296 | LoadTimingInfo load_timing_info2; |
| 2297 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info2)); |
| 2298 | TestLoadTimingReused(load_timing_info2); |
| 2299 | // The load timing after restart should have the same socket ID, and times |
| 2300 | // those of the first load timing. |
| 2301 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2302 | load_timing_info2.send_start); |
| 2303 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2304 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2305 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2306 | ASSERT_TRUE(response != NULL); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2307 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2308 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2309 | |
| 2310 | std::string response_data; |
| 2311 | rv = ReadTransaction(trans.get(), &response_data); |
| 2312 | EXPECT_EQ(OK, rv); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2313 | |
| 2314 | int64_t writes_size1 = CountWriteBytes(data_writes1, arraysize(data_writes1)); |
| 2315 | EXPECT_EQ(writes_size1, trans->GetTotalSentBytes()); |
| 2316 | int64_t reads_size1 = CountReadBytes(data_reads1, arraysize(data_reads1)); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2317 | EXPECT_EQ(reads_size1, trans->GetTotalReceivedBytes()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2318 | } |
| 2319 | |
| 2320 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2321 | // connection and with no response body to drain. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2322 | TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAliveNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2323 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2324 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2325 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2326 | request.load_flags = 0; |
| 2327 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 2328 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2329 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2330 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2331 | MockWrite( |
| 2332 | "GET / HTTP/1.1\r\n" |
| 2333 | "Host: www.example.org\r\n" |
| 2334 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2335 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2336 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2337 | // be issuing -- the final header line contains the credentials. |
| 2338 | MockWrite( |
| 2339 | "GET / HTTP/1.1\r\n" |
| 2340 | "Host: www.example.org\r\n" |
| 2341 | "Connection: keep-alive\r\n" |
| 2342 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2343 | }; |
| 2344 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2345 | MockRead data_reads1[] = { |
| 2346 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2347 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2348 | MockRead("Content-Length: 0\r\n\r\n"), // No response body. |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2349 | |
| 2350 | // Lastly, the server responds with the actual content. |
| 2351 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2352 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2353 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2354 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2355 | }; |
| 2356 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2357 | // An incorrect reconnect would cause this to be read. |
| 2358 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2359 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2360 | }; |
| 2361 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2362 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2363 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2364 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2365 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2366 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2367 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2368 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2369 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2370 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2371 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2372 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2373 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2374 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2375 | |
| 2376 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2377 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2378 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2379 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2380 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2381 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2382 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2383 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2384 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2385 | rv = trans->RestartWithAuth( |
| 2386 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2387 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2388 | |
| 2389 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2390 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2391 | |
| 2392 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2393 | ASSERT_TRUE(response != NULL); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2394 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2395 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2396 | } |
| 2397 | |
| 2398 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2399 | // connection and with a large response body to drain. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2400 | TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAliveLargeBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2401 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2402 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2403 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2404 | request.load_flags = 0; |
| 2405 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 2406 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2407 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2408 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2409 | MockWrite( |
| 2410 | "GET / HTTP/1.1\r\n" |
| 2411 | "Host: www.example.org\r\n" |
| 2412 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2413 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2414 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2415 | // be issuing -- the final header line contains the credentials. |
| 2416 | MockWrite( |
| 2417 | "GET / HTTP/1.1\r\n" |
| 2418 | "Host: www.example.org\r\n" |
| 2419 | "Connection: keep-alive\r\n" |
| 2420 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2421 | }; |
| 2422 | |
| 2423 | // Respond with 5 kb of response body. |
| 2424 | std::string large_body_string("Unauthorized"); |
| 2425 | large_body_string.append(5 * 1024, ' '); |
| 2426 | large_body_string.append("\r\n"); |
| 2427 | |
| 2428 | MockRead data_reads1[] = { |
| 2429 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2430 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2431 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2432 | // 5134 = 12 + 5 * 1024 + 2 |
| 2433 | MockRead("Content-Length: 5134\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2434 | MockRead(ASYNC, large_body_string.data(), large_body_string.size()), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2435 | |
| 2436 | // Lastly, the server responds with the actual content. |
| 2437 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2438 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2439 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2440 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2441 | }; |
| 2442 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2443 | // An incorrect reconnect would cause this to be read. |
| 2444 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2445 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2446 | }; |
| 2447 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2448 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2449 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2450 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2451 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2452 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2453 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2454 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2455 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2456 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2457 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2458 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2459 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2460 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2461 | |
| 2462 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2463 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2464 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2465 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2466 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2467 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2468 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2469 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2470 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2471 | rv = trans->RestartWithAuth( |
| 2472 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2473 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2474 | |
| 2475 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2476 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2477 | |
| 2478 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2479 | ASSERT_TRUE(response != NULL); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2480 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2481 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2482 | } |
| 2483 | |
| 2484 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2485 | // connection, but the server gets impatient and closes the connection. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 2486 | TEST_P(HttpNetworkTransactionTest, BasicAuthKeepAliveImpatientServer) { |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2487 | HttpRequestInfo request; |
| 2488 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2489 | request.url = GURL("http://www.example.org/"); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2490 | request.load_flags = 0; |
| 2491 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 2492 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2493 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2494 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2495 | MockWrite( |
| 2496 | "GET / HTTP/1.1\r\n" |
| 2497 | "Host: www.example.org\r\n" |
| 2498 | "Connection: keep-alive\r\n\r\n"), |
| 2499 | // This simulates the seemingly successful write to a closed connection |
| 2500 | // if the bug is not fixed. |
| 2501 | MockWrite( |
| 2502 | "GET / HTTP/1.1\r\n" |
| 2503 | "Host: www.example.org\r\n" |
| 2504 | "Connection: keep-alive\r\n" |
| 2505 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2506 | }; |
| 2507 | |
| 2508 | MockRead data_reads1[] = { |
| 2509 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2510 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2511 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2512 | MockRead("Content-Length: 14\r\n\r\n"), |
| 2513 | // Tell MockTCPClientSocket to simulate the server closing the connection. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2514 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2515 | MockRead("Unauthorized\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2516 | MockRead(SYNCHRONOUS, OK), // The server closes the connection. |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2517 | }; |
| 2518 | |
| 2519 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2520 | // be issuing -- the final header line contains the credentials. |
| 2521 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2522 | MockWrite( |
| 2523 | "GET / HTTP/1.1\r\n" |
| 2524 | "Host: www.example.org\r\n" |
| 2525 | "Connection: keep-alive\r\n" |
| 2526 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2527 | }; |
| 2528 | |
| 2529 | // Lastly, the server responds with the actual content. |
| 2530 | MockRead data_reads2[] = { |
| 2531 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2532 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2533 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2534 | MockRead("hello"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2535 | }; |
| 2536 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2537 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2538 | data_writes1, arraysize(data_writes1)); |
| 2539 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2540 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2541 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2542 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2543 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2544 | TestCompletionCallback callback1; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2545 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2546 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2547 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2548 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2549 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2550 | |
| 2551 | rv = callback1.WaitForResult(); |
| 2552 | EXPECT_EQ(OK, rv); |
| 2553 | |
| 2554 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2555 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2556 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2557 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2558 | TestCompletionCallback callback2; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2559 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2560 | rv = trans->RestartWithAuth( |
| 2561 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2562 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2563 | |
| 2564 | rv = callback2.WaitForResult(); |
| 2565 | EXPECT_EQ(OK, rv); |
| 2566 | |
| 2567 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2568 | ASSERT_TRUE(response != NULL); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2569 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2570 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2571 | } |
| 2572 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2573 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 2574 | // that requires a restart when setting up an SSL tunnel. |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2575 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp10) { |
| 2576 | HttpRequestInfo request; |
| 2577 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2578 | request.url = GURL("https://www.example.org/"); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2579 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2580 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2581 | |
| 2582 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 2583 | session_deps_.proxy_service = |
| 2584 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2585 | BoundTestNetLog log; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2586 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 2587 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2588 | |
| 2589 | // Since we have proxy, should try to establish tunnel. |
| 2590 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2591 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 2592 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2593 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2594 | }; |
| 2595 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2596 | // The proxy responds to the connect with a 407, using a non-persistent |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2597 | // connection. |
| 2598 | MockRead data_reads1[] = { |
| 2599 | // No credentials. |
| 2600 | MockRead("HTTP/1.0 407 Proxy Authentication Required\r\n"), |
| 2601 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n\r\n"), |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2602 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2603 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2604 | // Since the first connection couldn't be reused, need to establish another |
| 2605 | // once given credentials. |
| 2606 | MockWrite data_writes2[] = { |
| 2607 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2608 | // be issuing -- the final header line contains the credentials. |
| 2609 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 2610 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2611 | "Proxy-Connection: keep-alive\r\n" |
| 2612 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2613 | |
| 2614 | MockWrite("GET / HTTP/1.1\r\n" |
| 2615 | "Host: www.example.org\r\n" |
| 2616 | "Connection: keep-alive\r\n\r\n"), |
| 2617 | }; |
| 2618 | |
| 2619 | MockRead data_reads2[] = { |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2620 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 2621 | |
| 2622 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2623 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2624 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2625 | MockRead(SYNCHRONOUS, "hello"), |
| 2626 | }; |
| 2627 | |
| 2628 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2629 | data_writes1, arraysize(data_writes1)); |
| 2630 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2631 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2632 | data_writes2, arraysize(data_writes2)); |
| 2633 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2634 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 2635 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 2636 | |
| 2637 | TestCompletionCallback callback1; |
| 2638 | |
| 2639 | scoped_ptr<HttpTransaction> trans( |
| 2640 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 2641 | |
| 2642 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 2643 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2644 | |
| 2645 | rv = callback1.WaitForResult(); |
| 2646 | EXPECT_EQ(OK, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 2647 | TestNetLogEntry::List entries; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2648 | log.GetEntries(&entries); |
| 2649 | size_t pos = ExpectLogContainsSomewhere( |
| 2650 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 2651 | NetLog::PHASE_NONE); |
| 2652 | ExpectLogContainsSomewhere( |
| 2653 | entries, pos, NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 2654 | NetLog::PHASE_NONE); |
| 2655 | |
| 2656 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 2657 | ASSERT_TRUE(response != NULL); |
| 2658 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
| 2659 | ASSERT_FALSE(response->headers.get() == NULL); |
| 2660 | EXPECT_EQ(407, response->headers->response_code()); |
| 2661 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 2662 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 2663 | |
| 2664 | LoadTimingInfo load_timing_info; |
| 2665 | // CONNECT requests and responses are handled at the connect job level, so |
| 2666 | // the transaction does not yet have a connection. |
| 2667 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2668 | |
| 2669 | TestCompletionCallback callback2; |
| 2670 | |
| 2671 | rv = |
| 2672 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
| 2673 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2674 | |
| 2675 | rv = callback2.WaitForResult(); |
| 2676 | EXPECT_EQ(OK, rv); |
| 2677 | |
| 2678 | response = trans->GetResponseInfo(); |
| 2679 | ASSERT_TRUE(response != NULL); |
| 2680 | |
| 2681 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2682 | EXPECT_EQ(200, response->headers->response_code()); |
| 2683 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 2684 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 2685 | |
| 2686 | // The password prompt info should not be set. |
| 2687 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 2688 | |
| 2689 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2690 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 2691 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 2692 | |
| 2693 | trans.reset(); |
| 2694 | session->CloseAllConnections(); |
| 2695 | } |
| 2696 | |
| 2697 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 2698 | // that requires a restart when setting up an SSL tunnel. |
| 2699 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp11) { |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2700 | HttpRequestInfo request; |
| 2701 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2702 | request.url = GURL("https://www.example.org/"); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2703 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2704 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2705 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2706 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 2707 | session_deps_.proxy_service = |
| 2708 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2709 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2710 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 2711 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2712 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2713 | // Since we have proxy, should try to establish tunnel. |
| 2714 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2715 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 2716 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2717 | "Proxy-Connection: keep-alive\r\n\r\n"), |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 2718 | }; |
| 2719 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2720 | // The proxy responds to the connect with a 407, using a non-persistent |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 2721 | // connection. |
| 2722 | MockRead data_reads1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2723 | // No credentials. |
| 2724 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 2725 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2726 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 2727 | }; |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 2728 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2729 | MockWrite data_writes2[] = { |
| 2730 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2731 | // be issuing -- the final header line contains the credentials. |
| 2732 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 2733 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2734 | "Proxy-Connection: keep-alive\r\n" |
| 2735 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 2736 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2737 | MockWrite("GET / HTTP/1.1\r\n" |
| 2738 | "Host: www.example.org\r\n" |
| 2739 | "Connection: keep-alive\r\n\r\n"), |
| 2740 | }; |
| 2741 | |
| 2742 | MockRead data_reads2[] = { |
| 2743 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 2744 | |
| 2745 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2746 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2747 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2748 | MockRead(SYNCHRONOUS, "hello"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2749 | }; |
| 2750 | |
| 2751 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2752 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2753 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2754 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2755 | data_writes2, arraysize(data_writes2)); |
| 2756 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2757 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2758 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2759 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2760 | TestCompletionCallback callback1; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2761 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2762 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2763 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2764 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2765 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2766 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2767 | |
| 2768 | rv = callback1.WaitForResult(); |
| 2769 | EXPECT_EQ(OK, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 2770 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2771 | log.GetEntries(&entries); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2772 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2773 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2774 | NetLog::PHASE_NONE); |
| 2775 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2776 | entries, pos, |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2777 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 2778 | NetLog::PHASE_NONE); |
| 2779 | |
| 2780 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2781 | ASSERT_TRUE(response != NULL); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2782 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2783 | ASSERT_FALSE(response->headers.get() == NULL); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2784 | EXPECT_EQ(407, response->headers->response_code()); |
| 2785 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2786 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2787 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2788 | LoadTimingInfo load_timing_info; |
| 2789 | // CONNECT requests and responses are handled at the connect job level, so |
| 2790 | // the transaction does not yet have a connection. |
| 2791 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2792 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2793 | TestCompletionCallback callback2; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2794 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2795 | rv = trans->RestartWithAuth( |
| 2796 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2797 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2798 | |
| 2799 | rv = callback2.WaitForResult(); |
| 2800 | EXPECT_EQ(OK, rv); |
| 2801 | |
| 2802 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 2803 | ASSERT_TRUE(response != NULL); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2804 | |
| 2805 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2806 | EXPECT_EQ(200, response->headers->response_code()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2807 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2808 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 2809 | |
| 2810 | // The password prompt info should not be set. |
| 2811 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2812 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 2813 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2814 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 2815 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 2816 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2817 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 2818 | session->CloseAllConnections(); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2819 | } |
| 2820 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2821 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2822 | // proxy connection with HTTP/1.0 responses, when setting up an SSL tunnel. |
| 2823 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp10) { |
| 2824 | HttpRequestInfo request; |
| 2825 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2826 | request.url = GURL("https://www.example.org/"); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2827 | // Ensure that proxy authentication is attempted even |
| 2828 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2829 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2830 | |
| 2831 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 2832 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2833 | BoundTestNetLog log; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2834 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 2835 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2836 | |
| 2837 | scoped_ptr<HttpTransaction> trans( |
| 2838 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 2839 | |
| 2840 | // Since we have proxy, should try to establish tunnel. |
| 2841 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 2842 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2843 | "Host: www.example.org:443\r\n" |
| 2844 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2845 | |
| 2846 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2847 | // be issuing -- the final header line contains the credentials. |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 2848 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2849 | "Host: www.example.org:443\r\n" |
| 2850 | "Proxy-Connection: keep-alive\r\n" |
| 2851 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2852 | }; |
| 2853 | |
| 2854 | // The proxy responds to the connect with a 407, using a persistent |
| 2855 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 2856 | MockRead data_reads1[] = { |
| 2857 | // No credentials. |
| 2858 | MockRead("HTTP/1.0 407 Proxy Authentication Required\r\n"), |
| 2859 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2860 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 2861 | MockRead("Content-Length: 10\r\n\r\n"), |
| 2862 | MockRead("0123456789"), |
| 2863 | |
| 2864 | // Wrong credentials (wrong password). |
| 2865 | MockRead("HTTP/1.0 407 Proxy Authentication Required\r\n"), |
| 2866 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2867 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 2868 | MockRead("Content-Length: 10\r\n\r\n"), |
| 2869 | // No response body because the test stops reading here. |
| 2870 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 2871 | }; |
| 2872 | |
| 2873 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2874 | data_writes1, arraysize(data_writes1)); |
| 2875 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2876 | |
| 2877 | TestCompletionCallback callback1; |
| 2878 | |
| 2879 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 2880 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2881 | |
| 2882 | rv = callback1.WaitForResult(); |
| 2883 | EXPECT_EQ(OK, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 2884 | TestNetLogEntry::List entries; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2885 | log.GetEntries(&entries); |
| 2886 | size_t pos = ExpectLogContainsSomewhere( |
| 2887 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 2888 | NetLog::PHASE_NONE); |
| 2889 | ExpectLogContainsSomewhere( |
| 2890 | entries, pos, NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 2891 | NetLog::PHASE_NONE); |
| 2892 | |
| 2893 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 2894 | ASSERT_TRUE(response); |
| 2895 | ASSERT_TRUE(response->headers); |
| 2896 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2897 | EXPECT_EQ(407, response->headers->response_code()); |
| 2898 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 2899 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 2900 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 2901 | |
| 2902 | TestCompletionCallback callback2; |
| 2903 | |
| 2904 | // Wrong password (should be "bar"). |
| 2905 | rv = |
| 2906 | trans->RestartWithAuth(AuthCredentials(kFoo, kBaz), callback2.callback()); |
| 2907 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2908 | |
| 2909 | rv = callback2.WaitForResult(); |
| 2910 | EXPECT_EQ(OK, rv); |
| 2911 | |
| 2912 | response = trans->GetResponseInfo(); |
| 2913 | ASSERT_TRUE(response); |
| 2914 | ASSERT_TRUE(response->headers); |
| 2915 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 2916 | EXPECT_EQ(407, response->headers->response_code()); |
| 2917 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 2918 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 2919 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 2920 | |
| 2921 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 2922 | // out of scope. |
| 2923 | session->CloseAllConnections(); |
| 2924 | } |
| 2925 | |
| 2926 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2927 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel. |
| 2928 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp11) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2929 | HttpRequestInfo request; |
| 2930 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2931 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2932 | // Ensure that proxy authentication is attempted even |
| 2933 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2934 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2935 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2936 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 2937 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2938 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2939 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 2940 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2941 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2942 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2943 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2944 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2945 | // Since we have proxy, should try to establish tunnel. |
| 2946 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 2947 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2948 | "Host: www.example.org:443\r\n" |
| 2949 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2950 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2951 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2952 | // be issuing -- the final header line contains the credentials. |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 2953 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 2954 | "Host: www.example.org:443\r\n" |
| 2955 | "Proxy-Connection: keep-alive\r\n" |
| 2956 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2957 | }; |
| 2958 | |
| 2959 | // The proxy responds to the connect with a 407, using a persistent |
| 2960 | // connection. |
| 2961 | MockRead data_reads1[] = { |
| 2962 | // No credentials. |
| 2963 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 2964 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2965 | MockRead("Content-Length: 10\r\n\r\n"), |
| 2966 | MockRead("0123456789"), |
| 2967 | |
| 2968 | // Wrong credentials (wrong password). |
| 2969 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 2970 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2971 | MockRead("Content-Length: 10\r\n\r\n"), |
| 2972 | // No response body because the test stops reading here. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2973 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2974 | }; |
| 2975 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2976 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2977 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2978 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2979 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2980 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2981 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2982 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2983 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2984 | |
| 2985 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2986 | EXPECT_EQ(OK, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 2987 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2988 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 2989 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2990 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 2991 | NetLog::PHASE_NONE); |
| 2992 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 2993 | entries, pos, |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 2994 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 2995 | NetLog::PHASE_NONE); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2996 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2997 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 2998 | ASSERT_TRUE(response); |
| 2999 | ASSERT_TRUE(response->headers); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3000 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3001 | EXPECT_EQ(407, response->headers->response_code()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3002 | EXPECT_EQ(10, response->headers->GetContentLength()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3003 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3004 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3005 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3006 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3007 | |
| 3008 | // Wrong password (should be "bar"). |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3009 | rv = trans->RestartWithAuth( |
| 3010 | AuthCredentials(kFoo, kBaz), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3011 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3012 | |
| 3013 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3014 | EXPECT_EQ(OK, rv); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3015 | |
| 3016 | response = trans->GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3017 | ASSERT_TRUE(response); |
| 3018 | ASSERT_TRUE(response->headers); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3019 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3020 | EXPECT_EQ(407, response->headers->response_code()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3021 | EXPECT_EQ(10, response->headers->GetContentLength()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3022 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3023 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 3024 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 3025 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 3026 | // out of scope. |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3027 | session->CloseAllConnections(); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3028 | } |
| 3029 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3030 | // Test the case a proxy closes a socket while the challenge body is being |
| 3031 | // drained. |
| 3032 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHangupDuringBody) { |
| 3033 | HttpRequestInfo request; |
| 3034 | request.method = "GET"; |
| 3035 | request.url = GURL("https://www.example.org/"); |
| 3036 | // Ensure that proxy authentication is attempted even |
| 3037 | // when the no authentication data flag is set. |
| 3038 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
| 3039 | |
| 3040 | // Configure against proxy server "myproxy:70". |
| 3041 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 3042 | scoped_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3043 | |
| 3044 | scoped_ptr<HttpTransaction> trans( |
| 3045 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 3046 | |
| 3047 | // Since we have proxy, should try to establish tunnel. |
| 3048 | MockWrite data_writes1[] = { |
| 3049 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3050 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3051 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3052 | }; |
| 3053 | |
| 3054 | // The proxy responds to the connect with a 407, using a persistent |
| 3055 | // connection. |
| 3056 | MockRead data_reads1[] = { |
| 3057 | // No credentials. |
| 3058 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3059 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3060 | MockRead("Content-Length: 10\r\n\r\n"), MockRead("spam!"), |
| 3061 | // Server hands up in the middle of the body. |
| 3062 | MockRead(ASYNC, ERR_CONNECTION_CLOSED), |
| 3063 | }; |
| 3064 | |
| 3065 | MockWrite data_writes2[] = { |
| 3066 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3067 | // be issuing -- the final header line contains the credentials. |
| 3068 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3069 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3070 | "Proxy-Connection: keep-alive\r\n" |
| 3071 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3072 | |
| 3073 | MockWrite("GET / HTTP/1.1\r\n" |
| 3074 | "Host: www.example.org\r\n" |
| 3075 | "Connection: keep-alive\r\n\r\n"), |
| 3076 | }; |
| 3077 | |
| 3078 | MockRead data_reads2[] = { |
| 3079 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3080 | |
| 3081 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3082 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3083 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3084 | MockRead(SYNCHRONOUS, "hello"), |
| 3085 | }; |
| 3086 | |
| 3087 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3088 | data_writes1, arraysize(data_writes1)); |
| 3089 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3090 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3091 | data_writes2, arraysize(data_writes2)); |
| 3092 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3093 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3094 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3095 | |
| 3096 | TestCompletionCallback callback; |
| 3097 | |
| 3098 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 3099 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 3100 | |
| 3101 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3102 | ASSERT_TRUE(response); |
| 3103 | ASSERT_TRUE(response->headers); |
| 3104 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3105 | EXPECT_EQ(407, response->headers->response_code()); |
| 3106 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3107 | |
| 3108 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
| 3109 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 3110 | |
| 3111 | response = trans->GetResponseInfo(); |
| 3112 | ASSERT_TRUE(response); |
| 3113 | ASSERT_TRUE(response->headers); |
| 3114 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3115 | EXPECT_EQ(200, response->headers->response_code()); |
| 3116 | std::string body; |
| 3117 | EXPECT_EQ(OK, ReadTransaction(trans.get(), &body)); |
| 3118 | EXPECT_EQ("hello", body); |
| 3119 | } |
| 3120 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3121 | // Test that we don't read the response body when we fail to establish a tunnel, |
| 3122 | // even if the user cancels the proxy's auth attempt. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3123 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyCancelTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3124 | HttpRequestInfo request; |
| 3125 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3126 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3127 | request.load_flags = 0; |
| 3128 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3129 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3130 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3131 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 3132 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3133 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3134 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3135 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3136 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3137 | // Since we have proxy, should try to establish tunnel. |
| 3138 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3139 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3140 | "Host: www.example.org:443\r\n" |
| 3141 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3142 | }; |
| 3143 | |
| 3144 | // The proxy responds to the connect with a 407. |
| 3145 | MockRead data_reads[] = { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3146 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3147 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3148 | MockRead("Content-Length: 10\r\n\r\n"), |
| 3149 | MockRead("0123456789"), // Should not be reached. |
| 3150 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3151 | }; |
| 3152 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 3153 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 3154 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3155 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3156 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3157 | TestCompletionCallback callback; |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3158 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3159 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3160 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3161 | |
| 3162 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3163 | EXPECT_EQ(OK, rv); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3164 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3165 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3166 | ASSERT_TRUE(response); |
| 3167 | ASSERT_TRUE(response->headers); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3168 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3169 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3170 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3171 | |
| 3172 | std::string response_data; |
| 3173 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3174 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 3175 | |
| 3176 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3177 | session->CloseAllConnections(); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3178 | } |
| 3179 | |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3180 | // Test that we don't pass extraneous headers from the proxy's response to the |
| 3181 | // caller when the proxy responds to CONNECT with 407. |
| 3182 | TEST_P(HttpNetworkTransactionTest, SanitizeProxyAuthHeaders) { |
| 3183 | HttpRequestInfo request; |
| 3184 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3185 | request.url = GURL("https://www.example.org/"); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3186 | request.load_flags = 0; |
| 3187 | |
| 3188 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3189 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3190 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 3191 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3192 | |
| 3193 | scoped_ptr<HttpTransaction> trans( |
| 3194 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 3195 | |
| 3196 | // Since we have proxy, should try to establish tunnel. |
| 3197 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3198 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3199 | "Host: www.example.org:443\r\n" |
| 3200 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3201 | }; |
| 3202 | |
| 3203 | // The proxy responds to the connect with a 407. |
| 3204 | MockRead data_reads[] = { |
| 3205 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3206 | MockRead("X-Foo: bar\r\n"), |
| 3207 | MockRead("Set-Cookie: foo=bar\r\n"), |
| 3208 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3209 | MockRead("Content-Length: 10\r\n\r\n"), |
| 3210 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 3211 | }; |
| 3212 | |
| 3213 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 3214 | arraysize(data_writes)); |
| 3215 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 3216 | |
| 3217 | TestCompletionCallback callback; |
| 3218 | |
| 3219 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 3220 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3221 | |
| 3222 | rv = callback.WaitForResult(); |
| 3223 | EXPECT_EQ(OK, rv); |
| 3224 | |
| 3225 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3226 | ASSERT_TRUE(response); |
| 3227 | ASSERT_TRUE(response->headers); |
| 3228 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3229 | EXPECT_EQ(407, response->headers->response_code()); |
| 3230 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3231 | EXPECT_FALSE(response->headers->HasHeader("X-Foo")); |
| 3232 | EXPECT_FALSE(response->headers->HasHeader("Set-Cookie")); |
| 3233 | |
| 3234 | std::string response_data; |
| 3235 | rv = ReadTransaction(trans.get(), &response_data); |
| 3236 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
| 3237 | |
| 3238 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
| 3239 | session->CloseAllConnections(); |
| 3240 | } |
| 3241 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3242 | // Test when a server (non-proxy) returns a 407 (proxy-authenticate). |
| 3243 | // The request should fail with ERR_UNEXPECTED_PROXY_AUTH. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3244 | TEST_P(HttpNetworkTransactionTest, UnexpectedProxyAuth) { |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3245 | HttpRequestInfo request; |
| 3246 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3247 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3248 | request.load_flags = 0; |
| 3249 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3250 | // We are using a DIRECT connection (i.e. no proxy) for this session. |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 3251 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3252 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 3253 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3254 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3255 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3256 | MockWrite( |
| 3257 | "GET / HTTP/1.1\r\n" |
| 3258 | "Host: www.example.org\r\n" |
| 3259 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3260 | }; |
| 3261 | |
| 3262 | MockRead data_reads1[] = { |
| 3263 | MockRead("HTTP/1.0 407 Proxy Auth required\r\n"), |
| 3264 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3265 | // Large content-length -- won't matter, as connection will be reset. |
| 3266 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3267 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3268 | }; |
| 3269 | |
| 3270 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3271 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3272 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3273 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3274 | TestCompletionCallback callback; |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3275 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3276 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3277 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3278 | |
| 3279 | rv = callback.WaitForResult(); |
| 3280 | EXPECT_EQ(ERR_UNEXPECTED_PROXY_AUTH, rv); |
| 3281 | } |
| 3282 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3283 | // Tests when an HTTPS server (non-proxy) returns a 407 (proxy-authentication) |
| 3284 | // through a non-authenticating proxy. The request should fail with |
| 3285 | // ERR_UNEXPECTED_PROXY_AUTH. |
| 3286 | // Note that it is impossible to detect if an HTTP server returns a 407 through |
| 3287 | // a non-authenticating proxy - there is nothing to indicate whether the |
| 3288 | // response came from the proxy or the server, so it is treated as if the proxy |
| 3289 | // issued the challenge. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3290 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 3291 | HttpsServerRequestsProxyAuthThroughProxy) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3292 | HttpRequestInfo request; |
| 3293 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3294 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3295 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3296 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3297 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3298 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 3299 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3300 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3301 | // Since we have proxy, should try to establish tunnel. |
| 3302 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3303 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3304 | "Host: www.example.org:443\r\n" |
| 3305 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3306 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3307 | MockWrite("GET / HTTP/1.1\r\n" |
| 3308 | "Host: www.example.org\r\n" |
| 3309 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3310 | }; |
| 3311 | |
| 3312 | MockRead data_reads1[] = { |
| 3313 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3314 | |
| 3315 | MockRead("HTTP/1.1 407 Unauthorized\r\n"), |
| 3316 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3317 | MockRead("\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3318 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3319 | }; |
| 3320 | |
| 3321 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3322 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3323 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3324 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3325 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3326 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3327 | TestCompletionCallback callback1; |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3328 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3329 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3330 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3331 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3332 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3333 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3334 | |
| 3335 | rv = callback1.WaitForResult(); |
| 3336 | EXPECT_EQ(ERR_UNEXPECTED_PROXY_AUTH, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3337 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3338 | log.GetEntries(&entries); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3339 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3340 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3341 | NetLog::PHASE_NONE); |
| 3342 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3343 | entries, pos, |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3344 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3345 | NetLog::PHASE_NONE); |
| 3346 | } |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3347 | |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3348 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 3349 | // that uses non-persistent connections. |
| 3350 | TEST_P(HttpNetworkTransactionTest, |
| 3351 | AuthAllowsDefaultCredentialsTunnelConnectionClose) { |
| 3352 | HttpRequestInfo request; |
| 3353 | request.method = "GET"; |
| 3354 | request.url = GURL("https://www.example.org/"); |
| 3355 | |
| 3356 | // Configure against proxy server "myproxy:70". |
| 3357 | session_deps_.proxy_service = |
| 3358 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 3359 | |
| 3360 | scoped_ptr<HttpAuthHandlerMock::Factory> auth_handler_factory( |
| 3361 | new HttpAuthHandlerMock::Factory()); |
| 3362 | auth_handler_factory->set_do_init_from_challenge(true); |
| 3363 | scoped_ptr<HttpAuthHandlerMock> mock_handler(new HttpAuthHandlerMock()); |
| 3364 | mock_handler->set_allows_default_credentials(true); |
| 3365 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 3366 | HttpAuth::AUTH_PROXY); |
| 3367 | session_deps_.http_auth_handler_factory = auth_handler_factory.Pass(); |
| 3368 | |
| 3369 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 3370 | NetLog net_log; |
| 3371 | session_deps_.net_log = &net_log; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 3372 | scoped_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3373 | |
| 3374 | // Since we have proxy, should try to establish tunnel. |
| 3375 | MockWrite data_writes1[] = { |
| 3376 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3377 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3378 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3379 | }; |
| 3380 | |
| 3381 | // The proxy responds to the connect with a 407, using a non-persistent |
| 3382 | // connection. |
| 3383 | MockRead data_reads1[] = { |
| 3384 | // No credentials. |
| 3385 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3386 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 3387 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 3388 | }; |
| 3389 | |
| 3390 | // Since the first connection couldn't be reused, need to establish another |
| 3391 | // once given credentials. |
| 3392 | MockWrite data_writes2[] = { |
| 3393 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3394 | // be issuing -- the final header line contains the credentials. |
| 3395 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3396 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3397 | "Proxy-Connection: keep-alive\r\n" |
| 3398 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 3399 | |
| 3400 | MockWrite("GET / HTTP/1.1\r\n" |
| 3401 | "Host: www.example.org\r\n" |
| 3402 | "Connection: keep-alive\r\n\r\n"), |
| 3403 | }; |
| 3404 | |
| 3405 | MockRead data_reads2[] = { |
| 3406 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 3407 | |
| 3408 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3409 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3410 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3411 | MockRead(SYNCHRONOUS, "hello"), |
| 3412 | }; |
| 3413 | |
| 3414 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3415 | data_writes1, arraysize(data_writes1)); |
| 3416 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3417 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3418 | data_writes2, arraysize(data_writes2)); |
| 3419 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3420 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3421 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3422 | |
| 3423 | scoped_ptr<HttpTransaction> trans( |
| 3424 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 3425 | |
| 3426 | TestCompletionCallback callback; |
| 3427 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 3428 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 3429 | |
| 3430 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3431 | ASSERT_TRUE(response); |
| 3432 | ASSERT_TRUE(response->headers); |
| 3433 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
| 3434 | EXPECT_EQ(407, response->headers->response_code()); |
| 3435 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3436 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 3437 | EXPECT_FALSE(response->auth_challenge.get()); |
| 3438 | |
| 3439 | LoadTimingInfo load_timing_info; |
| 3440 | // CONNECT requests and responses are handled at the connect job level, so |
| 3441 | // the transaction does not yet have a connection. |
| 3442 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3443 | |
| 3444 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 3445 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 3446 | response = trans->GetResponseInfo(); |
| 3447 | ASSERT_TRUE(response); |
| 3448 | ASSERT_TRUE(response->headers); |
| 3449 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3450 | EXPECT_EQ(200, response->headers->response_code()); |
| 3451 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 3452 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3453 | |
| 3454 | // The password prompt info should not be set. |
| 3455 | EXPECT_FALSE(response->auth_challenge); |
| 3456 | |
| 3457 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3458 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3459 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3460 | |
| 3461 | trans.reset(); |
| 3462 | session->CloseAllConnections(); |
| 3463 | } |
| 3464 | |
| 3465 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 3466 | // that hangs up when credentials are initially sent. |
| 3467 | TEST_P(HttpNetworkTransactionTest, |
| 3468 | AuthAllowsDefaultCredentialsTunnelServerClosesConnection) { |
| 3469 | HttpRequestInfo request; |
| 3470 | request.method = "GET"; |
| 3471 | request.url = GURL("https://www.example.org/"); |
| 3472 | |
| 3473 | // Configure against proxy server "myproxy:70". |
| 3474 | session_deps_.proxy_service = |
| 3475 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 3476 | |
| 3477 | scoped_ptr<HttpAuthHandlerMock::Factory> auth_handler_factory( |
| 3478 | new HttpAuthHandlerMock::Factory()); |
| 3479 | auth_handler_factory->set_do_init_from_challenge(true); |
| 3480 | scoped_ptr<HttpAuthHandlerMock> mock_handler(new HttpAuthHandlerMock()); |
| 3481 | mock_handler->set_allows_default_credentials(true); |
| 3482 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 3483 | HttpAuth::AUTH_PROXY); |
| 3484 | session_deps_.http_auth_handler_factory = auth_handler_factory.Pass(); |
| 3485 | |
| 3486 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 3487 | NetLog net_log; |
| 3488 | session_deps_.net_log = &net_log; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 3489 | scoped_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3490 | |
| 3491 | // Should try to establish tunnel. |
| 3492 | MockWrite data_writes1[] = { |
| 3493 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3494 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3495 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3496 | |
| 3497 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3498 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3499 | "Proxy-Connection: keep-alive\r\n" |
| 3500 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 3501 | }; |
| 3502 | |
| 3503 | // The proxy responds to the connect with a 407, using a non-persistent |
| 3504 | // connection. |
| 3505 | MockRead data_reads1[] = { |
| 3506 | // No credentials. |
| 3507 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3508 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 3509 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 3510 | }; |
| 3511 | |
| 3512 | // Since the first connection was closed, need to establish another once given |
| 3513 | // credentials. |
| 3514 | MockWrite data_writes2[] = { |
| 3515 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3516 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3517 | "Proxy-Connection: keep-alive\r\n" |
| 3518 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 3519 | |
| 3520 | MockWrite("GET / HTTP/1.1\r\n" |
| 3521 | "Host: www.example.org\r\n" |
| 3522 | "Connection: keep-alive\r\n\r\n"), |
| 3523 | }; |
| 3524 | |
| 3525 | MockRead data_reads2[] = { |
| 3526 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 3527 | |
| 3528 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3529 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3530 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3531 | MockRead(SYNCHRONOUS, "hello"), |
| 3532 | }; |
| 3533 | |
| 3534 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3535 | data_writes1, arraysize(data_writes1)); |
| 3536 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3537 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3538 | data_writes2, arraysize(data_writes2)); |
| 3539 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3540 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3541 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3542 | |
| 3543 | scoped_ptr<HttpTransaction> trans( |
| 3544 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 3545 | |
| 3546 | TestCompletionCallback callback; |
| 3547 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 3548 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 3549 | |
| 3550 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3551 | ASSERT_TRUE(response); |
| 3552 | ASSERT_TRUE(response->headers); |
| 3553 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3554 | EXPECT_EQ(407, response->headers->response_code()); |
| 3555 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3556 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 3557 | EXPECT_FALSE(response->auth_challenge); |
| 3558 | |
| 3559 | LoadTimingInfo load_timing_info; |
| 3560 | // CONNECT requests and responses are handled at the connect job level, so |
| 3561 | // the transaction does not yet have a connection. |
| 3562 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3563 | |
| 3564 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 3565 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 3566 | |
| 3567 | response = trans->GetResponseInfo(); |
| 3568 | ASSERT_TRUE(response); |
| 3569 | ASSERT_TRUE(response->headers); |
| 3570 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3571 | EXPECT_EQ(200, response->headers->response_code()); |
| 3572 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 3573 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3574 | |
| 3575 | // The password prompt info should not be set. |
| 3576 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 3577 | |
| 3578 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3579 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3580 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3581 | |
| 3582 | trans.reset(); |
| 3583 | session->CloseAllConnections(); |
| 3584 | } |
| 3585 | |
| 3586 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 3587 | // that hangs up when credentials are initially sent, and hangs up again when |
| 3588 | // they are retried. |
| 3589 | TEST_P(HttpNetworkTransactionTest, |
| 3590 | AuthAllowsDefaultCredentialsTunnelServerClosesConnectionTwice) { |
| 3591 | HttpRequestInfo request; |
| 3592 | request.method = "GET"; |
| 3593 | request.url = GURL("https://www.example.org/"); |
| 3594 | |
| 3595 | // Configure against proxy server "myproxy:70". |
| 3596 | session_deps_.proxy_service = |
| 3597 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 3598 | |
| 3599 | scoped_ptr<HttpAuthHandlerMock::Factory> auth_handler_factory( |
| 3600 | new HttpAuthHandlerMock::Factory()); |
| 3601 | auth_handler_factory->set_do_init_from_challenge(true); |
| 3602 | scoped_ptr<HttpAuthHandlerMock> mock_handler(new HttpAuthHandlerMock()); |
| 3603 | mock_handler->set_allows_default_credentials(true); |
| 3604 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 3605 | HttpAuth::AUTH_PROXY); |
| 3606 | session_deps_.http_auth_handler_factory = auth_handler_factory.Pass(); |
| 3607 | |
| 3608 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 3609 | NetLog net_log; |
| 3610 | session_deps_.net_log = &net_log; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 3611 | scoped_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3612 | |
| 3613 | // Should try to establish tunnel. |
| 3614 | MockWrite data_writes1[] = { |
| 3615 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3616 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3617 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3618 | |
| 3619 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3620 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3621 | "Proxy-Connection: keep-alive\r\n" |
| 3622 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 3623 | }; |
| 3624 | |
| 3625 | // The proxy responds to the connect with a 407, and then hangs up after the |
| 3626 | // second request is sent. |
| 3627 | MockRead data_reads1[] = { |
| 3628 | // No credentials. |
| 3629 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3630 | MockRead("Content-Length: 0\r\n"), |
| 3631 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 3632 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 3633 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 3634 | }; |
| 3635 | |
| 3636 | // HttpNetworkTransaction sees a reused connection that was closed with |
| 3637 | // ERR_CONNECTION_CLOSED, realized it might have been a race, so retries the |
| 3638 | // request. |
| 3639 | MockWrite data_writes2[] = { |
| 3640 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3641 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3642 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3643 | }; |
| 3644 | |
| 3645 | // The proxy, having had more than enough of us, just hangs up. |
| 3646 | MockRead data_reads2[] = { |
| 3647 | // No credentials. |
| 3648 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 3649 | }; |
| 3650 | |
| 3651 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3652 | data_writes1, arraysize(data_writes1)); |
| 3653 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3654 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3655 | data_writes2, arraysize(data_writes2)); |
| 3656 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3657 | |
| 3658 | scoped_ptr<HttpTransaction> trans( |
| 3659 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 3660 | |
| 3661 | TestCompletionCallback callback; |
| 3662 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 3663 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 3664 | |
| 3665 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3666 | ASSERT_TRUE(response); |
| 3667 | ASSERT_TRUE(response->headers); |
| 3668 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3669 | EXPECT_EQ(407, response->headers->response_code()); |
| 3670 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3671 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 3672 | EXPECT_FALSE(response->auth_challenge); |
| 3673 | |
| 3674 | LoadTimingInfo load_timing_info; |
| 3675 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3676 | |
| 3677 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 3678 | EXPECT_EQ(ERR_EMPTY_RESPONSE, callback.GetResult(rv)); |
| 3679 | |
| 3680 | trans.reset(); |
| 3681 | session->CloseAllConnections(); |
| 3682 | } |
| 3683 | |
| 3684 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 3685 | // that hangs up when credentials are initially sent, and sends a challenge |
| 3686 | // again they are retried. |
| 3687 | TEST_P(HttpNetworkTransactionTest, |
| 3688 | AuthAllowsDefaultCredentialsTunnelServerChallengesTwice) { |
| 3689 | HttpRequestInfo request; |
| 3690 | request.method = "GET"; |
| 3691 | request.url = GURL("https://www.example.org/"); |
| 3692 | |
| 3693 | // Configure against proxy server "myproxy:70". |
| 3694 | session_deps_.proxy_service = |
| 3695 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 3696 | |
| 3697 | scoped_ptr<HttpAuthHandlerMock::Factory> auth_handler_factory( |
| 3698 | new HttpAuthHandlerMock::Factory()); |
| 3699 | auth_handler_factory->set_do_init_from_challenge(true); |
| 3700 | scoped_ptr<HttpAuthHandlerMock> mock_handler(new HttpAuthHandlerMock()); |
| 3701 | mock_handler->set_allows_default_credentials(true); |
| 3702 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 3703 | HttpAuth::AUTH_PROXY); |
| 3704 | // Add another handler for the second challenge. It supports default |
| 3705 | // credentials, but they shouldn't be used, since they were already tried. |
| 3706 | mock_handler.reset(new HttpAuthHandlerMock()); |
| 3707 | mock_handler->set_allows_default_credentials(true); |
| 3708 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 3709 | HttpAuth::AUTH_PROXY); |
| 3710 | session_deps_.http_auth_handler_factory = auth_handler_factory.Pass(); |
| 3711 | |
| 3712 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 3713 | NetLog net_log; |
| 3714 | session_deps_.net_log = &net_log; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 3715 | scoped_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3716 | |
| 3717 | // Should try to establish tunnel. |
| 3718 | MockWrite data_writes1[] = { |
| 3719 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3720 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3721 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3722 | }; |
| 3723 | |
| 3724 | // The proxy responds to the connect with a 407, using a non-persistent |
| 3725 | // connection. |
| 3726 | MockRead data_reads1[] = { |
| 3727 | // No credentials. |
| 3728 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3729 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 3730 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 3731 | }; |
| 3732 | |
| 3733 | // Since the first connection was closed, need to establish another once given |
| 3734 | // credentials. |
| 3735 | MockWrite data_writes2[] = { |
| 3736 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3737 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3738 | "Proxy-Connection: keep-alive\r\n" |
| 3739 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 3740 | }; |
| 3741 | |
| 3742 | MockRead data_reads2[] = { |
| 3743 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3744 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 3745 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 3746 | }; |
| 3747 | |
| 3748 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3749 | data_writes1, arraysize(data_writes1)); |
| 3750 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3751 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3752 | data_writes2, arraysize(data_writes2)); |
| 3753 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3754 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3755 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3756 | |
| 3757 | scoped_ptr<HttpTransaction> trans( |
| 3758 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 3759 | |
| 3760 | TestCompletionCallback callback; |
| 3761 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 3762 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 3763 | |
| 3764 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3765 | ASSERT_TRUE(response); |
| 3766 | ASSERT_TRUE(response->headers); |
| 3767 | EXPECT_EQ(407, response->headers->response_code()); |
| 3768 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3769 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 3770 | EXPECT_FALSE(response->auth_challenge); |
| 3771 | |
| 3772 | LoadTimingInfo load_timing_info; |
| 3773 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3774 | |
| 3775 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 3776 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 3777 | response = trans->GetResponseInfo(); |
| 3778 | ASSERT_TRUE(response); |
| 3779 | ASSERT_TRUE(response->headers); |
| 3780 | EXPECT_EQ(407, response->headers->response_code()); |
| 3781 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 3782 | EXPECT_TRUE(response->auth_challenge); |
| 3783 | |
| 3784 | trans.reset(); |
| 3785 | session->CloseAllConnections(); |
| 3786 | } |
| 3787 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3788 | // Test the load timing for HTTPS requests with an HTTP proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3789 | TEST_P(HttpNetworkTransactionTest, HttpProxyLoadTimingNoPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3790 | HttpRequestInfo request1; |
| 3791 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3792 | request1.url = GURL("https://www.example.org/1"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3793 | |
| 3794 | HttpRequestInfo request2; |
| 3795 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3796 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3797 | |
| 3798 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3799 | session_deps_.proxy_service = ProxyService::CreateFixed("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3800 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3801 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 3802 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3803 | |
| 3804 | // Since we have proxy, should try to establish tunnel. |
| 3805 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3806 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3807 | "Host: www.example.org:443\r\n" |
| 3808 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3809 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3810 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 3811 | "Host: www.example.org\r\n" |
| 3812 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3813 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3814 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 3815 | "Host: www.example.org\r\n" |
| 3816 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3817 | }; |
| 3818 | |
| 3819 | // The proxy responds to the connect with a 407, using a persistent |
| 3820 | // connection. |
| 3821 | MockRead data_reads1[] = { |
| 3822 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3823 | |
| 3824 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3825 | MockRead("Content-Length: 1\r\n\r\n"), |
| 3826 | MockRead(SYNCHRONOUS, "1"), |
| 3827 | |
| 3828 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3829 | MockRead("Content-Length: 2\r\n\r\n"), |
| 3830 | MockRead(SYNCHRONOUS, "22"), |
| 3831 | }; |
| 3832 | |
| 3833 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3834 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3835 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3836 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3837 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3838 | |
| 3839 | TestCompletionCallback callback1; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3840 | scoped_ptr<HttpTransaction> trans1( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3841 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3842 | |
| 3843 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
| 3844 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3845 | |
| 3846 | rv = callback1.WaitForResult(); |
| 3847 | EXPECT_EQ(OK, rv); |
| 3848 | |
| 3849 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 3850 | ASSERT_TRUE(response1 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3851 | ASSERT_TRUE(response1->headers.get() != NULL); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3852 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 3853 | |
| 3854 | LoadTimingInfo load_timing_info1; |
| 3855 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 3856 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_SSL_TIMES); |
| 3857 | |
| 3858 | trans1.reset(); |
| 3859 | |
| 3860 | TestCompletionCallback callback2; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3861 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3862 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3863 | |
| 3864 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
| 3865 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3866 | |
| 3867 | rv = callback2.WaitForResult(); |
| 3868 | EXPECT_EQ(OK, rv); |
| 3869 | |
| 3870 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 3871 | ASSERT_TRUE(response2 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3872 | ASSERT_TRUE(response2->headers.get() != NULL); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3873 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 3874 | |
| 3875 | LoadTimingInfo load_timing_info2; |
| 3876 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 3877 | TestLoadTimingReused(load_timing_info2); |
| 3878 | |
| 3879 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 3880 | |
| 3881 | trans2.reset(); |
| 3882 | session->CloseAllConnections(); |
| 3883 | } |
| 3884 | |
| 3885 | // 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] | 3886 | TEST_P(HttpNetworkTransactionTest, HttpProxyLoadTimingWithPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3887 | HttpRequestInfo request1; |
| 3888 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3889 | request1.url = GURL("https://www.example.org/1"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3890 | |
| 3891 | HttpRequestInfo request2; |
| 3892 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3893 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3894 | |
| 3895 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3896 | session_deps_.proxy_service = |
| 3897 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3898 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3899 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 3900 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3901 | |
| 3902 | // Since we have proxy, should try to establish tunnel. |
| 3903 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3904 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3905 | "Host: www.example.org:443\r\n" |
| 3906 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3907 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3908 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 3909 | "Host: www.example.org\r\n" |
| 3910 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3911 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3912 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 3913 | "Host: www.example.org\r\n" |
| 3914 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3915 | }; |
| 3916 | |
| 3917 | // The proxy responds to the connect with a 407, using a persistent |
| 3918 | // connection. |
| 3919 | MockRead data_reads1[] = { |
| 3920 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3921 | |
| 3922 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3923 | MockRead("Content-Length: 1\r\n\r\n"), |
| 3924 | MockRead(SYNCHRONOUS, "1"), |
| 3925 | |
| 3926 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3927 | MockRead("Content-Length: 2\r\n\r\n"), |
| 3928 | MockRead(SYNCHRONOUS, "22"), |
| 3929 | }; |
| 3930 | |
| 3931 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3932 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3933 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3934 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3935 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3936 | |
| 3937 | TestCompletionCallback callback1; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3938 | scoped_ptr<HttpTransaction> trans1( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3939 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3940 | |
| 3941 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
| 3942 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3943 | |
| 3944 | rv = callback1.WaitForResult(); |
| 3945 | EXPECT_EQ(OK, rv); |
| 3946 | |
| 3947 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 3948 | ASSERT_TRUE(response1 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3949 | ASSERT_TRUE(response1->headers.get() != NULL); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3950 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 3951 | |
| 3952 | LoadTimingInfo load_timing_info1; |
| 3953 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 3954 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 3955 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3956 | |
| 3957 | trans1.reset(); |
| 3958 | |
| 3959 | TestCompletionCallback callback2; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3960 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3961 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3962 | |
| 3963 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
| 3964 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3965 | |
| 3966 | rv = callback2.WaitForResult(); |
| 3967 | EXPECT_EQ(OK, rv); |
| 3968 | |
| 3969 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 3970 | ASSERT_TRUE(response2 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3971 | ASSERT_TRUE(response2->headers.get() != NULL); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3972 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 3973 | |
| 3974 | LoadTimingInfo load_timing_info2; |
| 3975 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 3976 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 3977 | |
| 3978 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 3979 | |
| 3980 | trans2.reset(); |
| 3981 | session->CloseAllConnections(); |
| 3982 | } |
| 3983 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3984 | // Test a simple get through an HTTPS Proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 3985 | TEST_P(HttpNetworkTransactionTest, HttpsProxyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3986 | HttpRequestInfo request; |
| 3987 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3988 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3989 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3990 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3991 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3992 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3993 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 3994 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3995 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3996 | // Since we have proxy, should use full url |
| 3997 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3998 | MockWrite( |
| 3999 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 4000 | "Host: www.example.org\r\n" |
| 4001 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4002 | }; |
| 4003 | |
| 4004 | MockRead data_reads1[] = { |
| 4005 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4006 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4007 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4008 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4009 | }; |
| 4010 | |
| 4011 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4012 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4013 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4014 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4015 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4016 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4017 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4018 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4019 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4020 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4021 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4022 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4023 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4024 | |
| 4025 | rv = callback1.WaitForResult(); |
| 4026 | EXPECT_EQ(OK, rv); |
| 4027 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4028 | LoadTimingInfo load_timing_info; |
| 4029 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4030 | TestLoadTimingNotReused(load_timing_info, |
| 4031 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 4032 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4033 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4034 | ASSERT_TRUE(response != NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4035 | |
| 4036 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4037 | EXPECT_EQ(200, response->headers->response_code()); |
| 4038 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 4039 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4040 | |
| 4041 | // The password prompt info should not be set. |
| 4042 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 4043 | } |
| 4044 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4045 | // Test a SPDY get through an HTTPS Proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4046 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4047 | HttpRequestInfo request; |
| 4048 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4049 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4050 | request.load_flags = 0; |
| 4051 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4052 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4053 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4054 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4055 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4056 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4057 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4058 | // fetch http://www.example.org/ via SPDY |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4059 | scoped_ptr<SpdyFrame> req( |
| 4060 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4061 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4062 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4063 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 4064 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4065 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4066 | CreateMockRead(*resp, 1), CreateMockRead(*data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4067 | }; |
| 4068 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4069 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4070 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4071 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4072 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4073 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4074 | ssl.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4075 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4076 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4077 | TestCompletionCallback callback1; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4078 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4079 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4080 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4081 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4082 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4083 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4084 | |
| 4085 | rv = callback1.WaitForResult(); |
| 4086 | EXPECT_EQ(OK, rv); |
| 4087 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4088 | LoadTimingInfo load_timing_info; |
| 4089 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4090 | TestLoadTimingNotReused(load_timing_info, |
| 4091 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 4092 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4093 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4094 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4095 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 4096 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4097 | |
| 4098 | std::string response_data; |
| 4099 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 4100 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4101 | } |
| 4102 | |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4103 | // Verifies that a session which races and wins against the owning transaction |
| 4104 | // (completing prior to host resolution), doesn't fail the transaction. |
| 4105 | // Regression test for crbug.com/334413. |
| 4106 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyGetWithSessionRace) { |
| 4107 | HttpRequestInfo request; |
| 4108 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4109 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4110 | request.load_flags = 0; |
| 4111 | |
| 4112 | // Configure SPDY proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4113 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4114 | BoundTestNetLog log; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4115 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4116 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4117 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4118 | // Fetch http://www.example.org/ through the SPDY proxy. |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4119 | scoped_ptr<SpdyFrame> req( |
| 4120 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4121 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4122 | |
| 4123 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 4124 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 4125 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4126 | CreateMockRead(*resp, 1), CreateMockRead(*data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4127 | }; |
| 4128 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4129 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4130 | arraysize(spdy_writes)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4131 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 4132 | |
| 4133 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4134 | ssl.SetNextProto(GetProtocol()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4135 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4136 | |
| 4137 | TestCompletionCallback callback1; |
| 4138 | |
| 4139 | scoped_ptr<HttpTransaction> trans( |
| 4140 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 4141 | |
| 4142 | // Stall the hostname resolution begun by the transaction. |
| 4143 | session_deps_.host_resolver->set_synchronous_mode(false); |
| 4144 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 4145 | |
| 4146 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 4147 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4148 | |
| 4149 | // Race a session to the proxy, which completes first. |
| 4150 | session_deps_.host_resolver->set_ondemand_mode(false); |
| 4151 | SpdySessionKey key( |
| 4152 | HostPortPair("proxy", 70), ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
| 4153 | base::WeakPtr<SpdySession> spdy_session = |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4154 | CreateSecureSpdySession(session.get(), key, log.bound()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4155 | |
| 4156 | // Unstall the resolution begun by the transaction. |
| 4157 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 4158 | session_deps_.host_resolver->ResolveAllPending(); |
| 4159 | |
| 4160 | EXPECT_FALSE(callback1.have_result()); |
| 4161 | rv = callback1.WaitForResult(); |
| 4162 | EXPECT_EQ(OK, rv); |
| 4163 | |
| 4164 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4165 | ASSERT_TRUE(response != NULL); |
| 4166 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 4167 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4168 | |
| 4169 | std::string response_data; |
| 4170 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 4171 | EXPECT_EQ(kUploadData, response_data); |
| 4172 | } |
| 4173 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4174 | // Test a SPDY get through an HTTPS Proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4175 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyGetWithProxyAuth) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4176 | HttpRequestInfo request; |
| 4177 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4178 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4179 | request.load_flags = 0; |
| 4180 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4181 | // Configure against https proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4182 | session_deps_.proxy_service = ProxyService::CreateFixed("https://myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4183 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4184 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4185 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4186 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4187 | // The first request will be a bare GET, the second request will be a |
| 4188 | // GET with a Proxy-Authorization header. |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4189 | scoped_ptr<SpdyFrame> req_get( |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4190 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4191 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4192 | const char* const kExtraAuthorizationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4193 | "proxy-authorization", "Basic Zm9vOmJhcg==" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4194 | }; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4195 | scoped_ptr<SpdyFrame> req_get_authorization( |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4196 | spdy_util_.ConstructSpdyGet(kExtraAuthorizationHeaders, |
| 4197 | arraysize(kExtraAuthorizationHeaders) / 2, |
| 4198 | false, |
| 4199 | 3, |
| 4200 | LOWEST, |
| 4201 | false)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4202 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4203 | CreateMockWrite(*req_get, 0), CreateMockWrite(*req_get_authorization, 3), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4204 | }; |
| 4205 | |
| 4206 | // The first response is a 407 proxy authentication challenge, and the second |
| 4207 | // response will be a 200 response since the second request includes a valid |
| 4208 | // Authorization header. |
| 4209 | const char* const kExtraAuthenticationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4210 | "proxy-authenticate", "Basic realm=\"MyRealm1\"" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4211 | }; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4212 | scoped_ptr<SpdyFrame> resp_authentication( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4213 | spdy_util_.ConstructSpdySynReplyError( |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4214 | "407 Proxy Authentication Required", |
| 4215 | kExtraAuthenticationHeaders, arraysize(kExtraAuthenticationHeaders)/2, |
| 4216 | 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4217 | scoped_ptr<SpdyFrame> body_authentication( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4218 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 4219 | scoped_ptr<SpdyFrame> resp_data( |
| 4220 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 4221 | scoped_ptr<SpdyFrame> body_data(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4222 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4223 | CreateMockRead(*resp_authentication, 1), |
| 4224 | CreateMockRead(*body_authentication, 2), |
| 4225 | CreateMockRead(*resp_data, 4), |
| 4226 | CreateMockRead(*body_data, 5), |
| 4227 | MockRead(ASYNC, 0, 6), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4228 | }; |
| 4229 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4230 | SequencedSocketData data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4231 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4232 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4233 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4234 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4235 | ssl.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4236 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4237 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4238 | TestCompletionCallback callback1; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4239 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4240 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4241 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4242 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4243 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4244 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4245 | |
| 4246 | rv = callback1.WaitForResult(); |
| 4247 | EXPECT_EQ(OK, rv); |
| 4248 | |
| 4249 | const HttpResponseInfo* const response = trans->GetResponseInfo(); |
| 4250 | |
| 4251 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4252 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4253 | EXPECT_EQ(407, response->headers->response_code()); |
| 4254 | EXPECT_TRUE(response->was_fetched_via_spdy); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4255 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4256 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4257 | TestCompletionCallback callback2; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4258 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4259 | rv = trans->RestartWithAuth( |
| 4260 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4261 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4262 | |
| 4263 | rv = callback2.WaitForResult(); |
| 4264 | EXPECT_EQ(OK, rv); |
| 4265 | |
| 4266 | const HttpResponseInfo* const response_restart = trans->GetResponseInfo(); |
| 4267 | |
| 4268 | ASSERT_TRUE(response_restart != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4269 | ASSERT_TRUE(response_restart->headers.get() != NULL); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4270 | EXPECT_EQ(200, response_restart->headers->response_code()); |
| 4271 | // The password prompt info should not be set. |
| 4272 | EXPECT_TRUE(response_restart->auth_challenge.get() == NULL); |
| 4273 | } |
| 4274 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4275 | // 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] | 4276 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyConnectHttps) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4277 | HttpRequestInfo request; |
| 4278 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4279 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4280 | request.load_flags = 0; |
| 4281 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4282 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4283 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4284 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4285 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4286 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4287 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4288 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4289 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4290 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4291 | // CONNECT to www.example.org:443 via SPDY |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 4292 | scoped_ptr<SpdyFrame> connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4293 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 4294 | // fetch https://www.example.org/ via HTTP |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4295 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4296 | const char get[] = |
| 4297 | "GET / HTTP/1.1\r\n" |
| 4298 | "Host: www.example.org\r\n" |
| 4299 | "Connection: keep-alive\r\n\r\n"; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4300 | scoped_ptr<SpdyFrame> wrapped_get( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4301 | spdy_util_.ConstructSpdyBodyFrame(1, get, strlen(get), false)); |
| 4302 | scoped_ptr<SpdyFrame> conn_resp( |
| 4303 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4304 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 4305 | "Content-Length: 10\r\n\r\n"; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4306 | scoped_ptr<SpdyFrame> wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4307 | spdy_util_.ConstructSpdyBodyFrame(1, resp, strlen(resp), false)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4308 | scoped_ptr<SpdyFrame> wrapped_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4309 | spdy_util_.ConstructSpdyBodyFrame(1, "1234567890", 10, false)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4310 | scoped_ptr<SpdyFrame> window_update( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 4311 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp->size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 4312 | |
| 4313 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4314 | CreateMockWrite(*connect, 0), |
| 4315 | CreateMockWrite(*wrapped_get, 2), |
| 4316 | CreateMockWrite(*window_update, 6), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 4317 | }; |
| 4318 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4319 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4320 | CreateMockRead(*conn_resp, 1, ASYNC), |
| 4321 | CreateMockRead(*wrapped_get_resp, 3, ASYNC), |
| 4322 | CreateMockRead(*wrapped_body, 4, ASYNC), |
| 4323 | CreateMockRead(*wrapped_body, 5, ASYNC), |
| 4324 | MockRead(ASYNC, 0, 7), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4325 | }; |
| 4326 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4327 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4328 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4329 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4330 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4331 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4332 | ssl.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4333 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4334 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4335 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4336 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4337 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4338 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4339 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4340 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4341 | |
| 4342 | rv = callback1.WaitForResult(); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4343 | ASSERT_EQ(OK, rv); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4344 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4345 | LoadTimingInfo load_timing_info; |
| 4346 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4347 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4348 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4349 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4350 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4351 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4352 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4353 | |
| 4354 | std::string response_data; |
| 4355 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 4356 | EXPECT_EQ("1234567890", response_data); |
| 4357 | } |
| 4358 | |
| 4359 | // Test a SPDY CONNECT through an HTTPS Proxy to a SPDY server. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4360 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyConnectSpdy) { |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4361 | SpdyTestUtil spdy_util_wrapped(GetProtocol(), GetDependenciesFromPriority()); |
| 4362 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4363 | HttpRequestInfo request; |
| 4364 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4365 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4366 | request.load_flags = 0; |
| 4367 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4368 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4369 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4370 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4371 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4372 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4373 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4374 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4375 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4376 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4377 | // CONNECT to www.example.org:443 via SPDY |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 4378 | scoped_ptr<SpdyFrame> connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4379 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 4380 | // fetch https://www.example.org/ via SPDY |
| 4381 | const char kMyUrl[] = "https://www.example.org/"; |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4382 | scoped_ptr<SpdyFrame> get( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4383 | spdy_util_wrapped.ConstructSpdyGet(kMyUrl, false, 1, LOWEST)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4384 | scoped_ptr<SpdyFrame> wrapped_get( |
| 4385 | spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
| 4386 | scoped_ptr<SpdyFrame> conn_resp( |
| 4387 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 4388 | scoped_ptr<SpdyFrame> get_resp( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4389 | spdy_util_wrapped.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4390 | scoped_ptr<SpdyFrame> wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4391 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4392 | scoped_ptr<SpdyFrame> body(spdy_util_wrapped.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4393 | scoped_ptr<SpdyFrame> wrapped_body( |
| 4394 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4395 | scoped_ptr<SpdyFrame> window_update_get_resp( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 4396 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp->size())); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4397 | scoped_ptr<SpdyFrame> window_update_body( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 4398 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body->size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 4399 | |
| 4400 | MockWrite spdy_writes[] = { |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4401 | CreateMockWrite(*connect, 0), |
| 4402 | CreateMockWrite(*wrapped_get, 2), |
| 4403 | CreateMockWrite(*window_update_get_resp, 6), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 4404 | CreateMockWrite(*window_update_body, 7), |
| 4405 | }; |
| 4406 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4407 | MockRead spdy_reads[] = { |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4408 | CreateMockRead(*conn_resp, 1, ASYNC), |
| 4409 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4410 | CreateMockRead(*wrapped_get_resp, 4, ASYNC), |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4411 | CreateMockRead(*wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4412 | MockRead(ASYNC, 0, 8), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4413 | }; |
| 4414 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4415 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4416 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4417 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4418 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4419 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4420 | ssl.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4421 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4422 | SSLSocketDataProvider ssl2(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4423 | ssl2.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4424 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4425 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4426 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4427 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4428 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4429 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4430 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4431 | // Allow the SpdyProxyClientSocket's write callback to complete. |
| 4432 | base::MessageLoop::current()->RunUntilIdle(); |
| 4433 | // Now allow the read of the response to complete. |
| 4434 | spdy_data.CompleteRead(); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4435 | rv = callback1.WaitForResult(); |
| 4436 | EXPECT_EQ(OK, rv); |
| 4437 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4438 | LoadTimingInfo load_timing_info; |
| 4439 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4440 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4441 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4442 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4443 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4444 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 4445 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4446 | |
| 4447 | std::string response_data; |
| 4448 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 4449 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4450 | } |
| 4451 | |
| 4452 | // Test a SPDY CONNECT failure through an HTTPS Proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4453 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyConnectFailure) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4454 | HttpRequestInfo request; |
| 4455 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4456 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4457 | request.load_flags = 0; |
| 4458 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4459 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4460 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4461 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4462 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4463 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4464 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4465 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4466 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4467 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4468 | // CONNECT to www.example.org:443 via SPDY |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 4469 | scoped_ptr<SpdyFrame> connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4470 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 4471 | scoped_ptr<SpdyFrame> get( |
| 4472 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4473 | |
| 4474 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4475 | CreateMockWrite(*connect, 0), CreateMockWrite(*get, 2), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4476 | }; |
| 4477 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4478 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdySynReplyError(1)); |
| 4479 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4480 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4481 | CreateMockRead(*resp, 1, ASYNC), MockRead(ASYNC, 0, 3), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4482 | }; |
| 4483 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4484 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4485 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4486 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4487 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4488 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4489 | ssl.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4490 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4491 | SSLSocketDataProvider ssl2(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4492 | ssl2.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4493 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4494 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4495 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4496 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4497 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4498 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4499 | |
| 4500 | rv = callback1.WaitForResult(); |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 4501 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4502 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 4503 | // TODO(ttuttle): Anything else to check here? |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4504 | } |
| 4505 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4506 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 4507 | // HTTPS Proxy to different servers. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4508 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4509 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsTwoServers) { |
| 4510 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4511 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4512 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4513 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4514 | scoped_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4515 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4516 | |
| 4517 | HttpRequestInfo request1; |
| 4518 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4519 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4520 | request1.load_flags = 0; |
| 4521 | |
| 4522 | HttpRequestInfo request2; |
| 4523 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4524 | request2.url = GURL("https://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4525 | request2.load_flags = 0; |
| 4526 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4527 | // CONNECT to www.example.org:443 via SPDY. |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 4528 | scoped_ptr<SpdyFrame> connect1(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4529 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4530 | scoped_ptr<SpdyFrame> conn_resp1( |
| 4531 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4532 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4533 | // Fetch https://www.example.org/ via HTTP. |
| 4534 | const char get1[] = |
| 4535 | "GET / HTTP/1.1\r\n" |
| 4536 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4537 | "Connection: keep-alive\r\n\r\n"; |
| 4538 | scoped_ptr<SpdyFrame> wrapped_get1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4539 | spdy_util_.ConstructSpdyBodyFrame(1, get1, strlen(get1), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4540 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 4541 | "Content-Length: 1\r\n\r\n"; |
| 4542 | scoped_ptr<SpdyFrame> wrapped_get_resp1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4543 | spdy_util_.ConstructSpdyBodyFrame(1, resp1, strlen(resp1), false)); |
| 4544 | scoped_ptr<SpdyFrame> wrapped_body1( |
| 4545 | spdy_util_.ConstructSpdyBodyFrame(1, "1", 1, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4546 | scoped_ptr<SpdyFrame> window_update( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 4547 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1->size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4548 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4549 | // CONNECT to mail.example.org:443 via SPDY. |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 4550 | SpdyHeaderBlock connect2_block; |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 4551 | spdy_util_.MaybeAddVersionHeader(&connect2_block); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 4552 | connect2_block[spdy_util_.GetMethodKey()] = "CONNECT"; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4553 | if (GetProtocol() == kProtoHTTP2) { |
bnc | 6b996d53 | 2015-07-29 10:51:32 | [diff] [blame] | 4554 | connect2_block[spdy_util_.GetHostKey()] = "mail.example.org:443"; |
| 4555 | } else { |
bnc | 6b996d53 | 2015-07-29 10:51:32 | [diff] [blame] | 4556 | connect2_block[spdy_util_.GetHostKey()] = "mail.example.org"; |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 4557 | connect2_block[spdy_util_.GetPathKey()] = "mail.example.org:443"; |
bnc | 6b996d53 | 2015-07-29 10:51:32 | [diff] [blame] | 4558 | } |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4559 | scoped_ptr<SpdyFrame> connect2( |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 4560 | spdy_util_.ConstructSpdySyn(3, connect2_block, LOWEST, false, false)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 4561 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4562 | scoped_ptr<SpdyFrame> conn_resp2( |
| 4563 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4564 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4565 | // Fetch https://mail.example.org/ via HTTP. |
| 4566 | const char get2[] = |
| 4567 | "GET / HTTP/1.1\r\n" |
| 4568 | "Host: mail.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4569 | "Connection: keep-alive\r\n\r\n"; |
| 4570 | scoped_ptr<SpdyFrame> wrapped_get2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4571 | spdy_util_.ConstructSpdyBodyFrame(3, get2, strlen(get2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4572 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 4573 | "Content-Length: 2\r\n\r\n"; |
| 4574 | scoped_ptr<SpdyFrame> wrapped_get_resp2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4575 | spdy_util_.ConstructSpdyBodyFrame(3, resp2, strlen(resp2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4576 | scoped_ptr<SpdyFrame> wrapped_body2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4577 | spdy_util_.ConstructSpdyBodyFrame(3, "22", 2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4578 | |
| 4579 | MockWrite spdy_writes[] = { |
| 4580 | CreateMockWrite(*connect1, 0), |
| 4581 | CreateMockWrite(*wrapped_get1, 2), |
| 4582 | CreateMockWrite(*connect2, 5), |
| 4583 | CreateMockWrite(*wrapped_get2, 7), |
| 4584 | }; |
| 4585 | |
| 4586 | MockRead spdy_reads[] = { |
| 4587 | CreateMockRead(*conn_resp1, 1, ASYNC), |
| 4588 | CreateMockRead(*wrapped_get_resp1, 3, ASYNC), |
| 4589 | CreateMockRead(*wrapped_body1, 4, ASYNC), |
| 4590 | CreateMockRead(*conn_resp2, 6, ASYNC), |
| 4591 | CreateMockRead(*wrapped_get_resp2, 8, ASYNC), |
| 4592 | CreateMockRead(*wrapped_body2, 9, ASYNC), |
| 4593 | MockRead(ASYNC, 0, 10), |
| 4594 | }; |
| 4595 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4596 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4597 | arraysize(spdy_writes)); |
| 4598 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4599 | |
| 4600 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4601 | ssl.SetNextProto(GetProtocol()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4602 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4603 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4604 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4605 | SSLSocketDataProvider ssl3(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4606 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4607 | |
| 4608 | TestCompletionCallback callback; |
| 4609 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4610 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4611 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4612 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4613 | EXPECT_EQ(OK, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4614 | |
| 4615 | LoadTimingInfo load_timing_info; |
| 4616 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4617 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4618 | |
| 4619 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4620 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4621 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4622 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4623 | |
| 4624 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 4625 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4626 | rv = trans->Read(buf.get(), 256, callback.callback()); |
| 4627 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4628 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4629 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4630 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4631 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4632 | EXPECT_EQ(OK, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4633 | |
| 4634 | LoadTimingInfo load_timing_info2; |
| 4635 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4636 | // Even though the SPDY connection is reused, a new tunnelled connection has |
| 4637 | // to be created, so the socket's load timing looks like a fresh connection. |
| 4638 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4639 | |
| 4640 | // The requests should have different IDs, since they each are using their own |
| 4641 | // separate stream. |
| 4642 | EXPECT_NE(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 4643 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4644 | rv = trans2->Read(buf.get(), 256, callback.callback()); |
| 4645 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4646 | } |
| 4647 | |
| 4648 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 4649 | // HTTPS Proxy to the same server. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4650 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4651 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsSameServer) { |
| 4652 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4653 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4654 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4655 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4656 | scoped_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4657 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4658 | |
| 4659 | HttpRequestInfo request1; |
| 4660 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4661 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4662 | request1.load_flags = 0; |
| 4663 | |
| 4664 | HttpRequestInfo request2; |
| 4665 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4666 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4667 | request2.load_flags = 0; |
| 4668 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4669 | // CONNECT to www.example.org:443 via SPDY. |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 4670 | scoped_ptr<SpdyFrame> connect1(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4671 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4672 | scoped_ptr<SpdyFrame> conn_resp1( |
| 4673 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4674 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4675 | // Fetch https://www.example.org/ via HTTP. |
| 4676 | const char get1[] = |
| 4677 | "GET / HTTP/1.1\r\n" |
| 4678 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4679 | "Connection: keep-alive\r\n\r\n"; |
| 4680 | scoped_ptr<SpdyFrame> wrapped_get1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4681 | spdy_util_.ConstructSpdyBodyFrame(1, get1, strlen(get1), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4682 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 4683 | "Content-Length: 1\r\n\r\n"; |
| 4684 | scoped_ptr<SpdyFrame> wrapped_get_resp1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4685 | spdy_util_.ConstructSpdyBodyFrame(1, resp1, strlen(resp1), false)); |
| 4686 | scoped_ptr<SpdyFrame> wrapped_body1( |
| 4687 | spdy_util_.ConstructSpdyBodyFrame(1, "1", 1, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4688 | scoped_ptr<SpdyFrame> window_update( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 4689 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1->size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4690 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4691 | // Fetch https://www.example.org/2 via HTTP. |
| 4692 | const char get2[] = |
| 4693 | "GET /2 HTTP/1.1\r\n" |
| 4694 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4695 | "Connection: keep-alive\r\n\r\n"; |
| 4696 | scoped_ptr<SpdyFrame> wrapped_get2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4697 | spdy_util_.ConstructSpdyBodyFrame(1, get2, strlen(get2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4698 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 4699 | "Content-Length: 2\r\n\r\n"; |
| 4700 | scoped_ptr<SpdyFrame> wrapped_get_resp2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4701 | spdy_util_.ConstructSpdyBodyFrame(1, resp2, strlen(resp2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4702 | scoped_ptr<SpdyFrame> wrapped_body2( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4703 | spdy_util_.ConstructSpdyBodyFrame(1, "22", 2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4704 | |
| 4705 | MockWrite spdy_writes[] = { |
| 4706 | CreateMockWrite(*connect1, 0), |
| 4707 | CreateMockWrite(*wrapped_get1, 2), |
| 4708 | CreateMockWrite(*wrapped_get2, 5), |
| 4709 | }; |
| 4710 | |
| 4711 | MockRead spdy_reads[] = { |
| 4712 | CreateMockRead(*conn_resp1, 1, ASYNC), |
| 4713 | CreateMockRead(*wrapped_get_resp1, 3, ASYNC), |
| 4714 | CreateMockRead(*wrapped_body1, 4, ASYNC), |
| 4715 | CreateMockRead(*wrapped_get_resp2, 6, ASYNC), |
| 4716 | CreateMockRead(*wrapped_body2, 7, ASYNC), |
| 4717 | MockRead(ASYNC, 0, 8), |
| 4718 | }; |
| 4719 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4720 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4721 | arraysize(spdy_writes)); |
| 4722 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4723 | |
| 4724 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4725 | ssl.SetNextProto(GetProtocol()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4726 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4727 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4728 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4729 | |
| 4730 | TestCompletionCallback callback; |
| 4731 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4732 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4733 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4734 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
| 4735 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4736 | |
| 4737 | rv = callback.WaitForResult(); |
| 4738 | EXPECT_EQ(OK, rv); |
| 4739 | |
| 4740 | LoadTimingInfo load_timing_info; |
| 4741 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4742 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4743 | |
| 4744 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4745 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4746 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4747 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4748 | |
| 4749 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 4750 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4751 | EXPECT_EQ(1, trans->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4752 | trans.reset(); |
| 4753 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4754 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4755 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4756 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
| 4757 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4758 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4759 | rv = callback.WaitForResult(); |
| 4760 | EXPECT_EQ(OK, rv); |
| 4761 | |
| 4762 | LoadTimingInfo load_timing_info2; |
| 4763 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4764 | TestLoadTimingReused(load_timing_info2); |
| 4765 | |
| 4766 | // The requests should have the same ID. |
| 4767 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 4768 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4769 | EXPECT_EQ(2, trans2->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4770 | } |
| 4771 | |
| 4772 | // Test load timing in the case of of two HTTP requests through a SPDY HTTPS |
| 4773 | // Proxy to different servers. |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4774 | TEST_P(HttpNetworkTransactionTest, HttpsProxySpdyLoadTimingTwoHttpRequests) { |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4775 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4776 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4777 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4778 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4779 | scoped_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4780 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4781 | |
| 4782 | HttpRequestInfo request1; |
| 4783 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4784 | request1.url = GURL("http://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4785 | request1.load_flags = 0; |
| 4786 | |
| 4787 | HttpRequestInfo request2; |
| 4788 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4789 | request2.url = GURL("http://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4790 | request2.load_flags = 0; |
| 4791 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4792 | // http://www.example.org/ |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4793 | scoped_ptr<SpdyHeaderBlock> headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4794 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 4795 | scoped_ptr<SpdyFrame> get1( |
| 4796 | spdy_util_.ConstructSpdySyn(1, *headers, LOWEST, false, true)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4797 | scoped_ptr<SpdyFrame> get_resp1( |
| 4798 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 4799 | scoped_ptr<SpdyFrame> body1( |
| 4800 | spdy_util_.ConstructSpdyBodyFrame(1, "1", 1, true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4801 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4802 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4803 | // http://mail.example.org/ |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4804 | scoped_ptr<SpdyHeaderBlock> headers2( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4805 | spdy_util_.ConstructGetHeaderBlockForProxy("http://mail.example.org/")); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 4806 | scoped_ptr<SpdyFrame> get2( |
| 4807 | spdy_util_.ConstructSpdySyn(3, *headers2, LOWEST, false, true)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4808 | scoped_ptr<SpdyFrame> get_resp2( |
| 4809 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 4810 | scoped_ptr<SpdyFrame> body2( |
| 4811 | spdy_util_.ConstructSpdyBodyFrame(3, "22", 2, true)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4812 | |
| 4813 | MockWrite spdy_writes[] = { |
| 4814 | CreateMockWrite(*get1, 0), |
| 4815 | CreateMockWrite(*get2, 3), |
| 4816 | }; |
| 4817 | |
| 4818 | MockRead spdy_reads[] = { |
| 4819 | CreateMockRead(*get_resp1, 1, ASYNC), |
| 4820 | CreateMockRead(*body1, 2, ASYNC), |
| 4821 | CreateMockRead(*get_resp2, 4, ASYNC), |
| 4822 | CreateMockRead(*body2, 5, ASYNC), |
| 4823 | MockRead(ASYNC, 0, 6), |
| 4824 | }; |
| 4825 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4826 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4827 | arraysize(spdy_writes)); |
| 4828 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4829 | |
| 4830 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4831 | ssl.SetNextProto(GetProtocol()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4832 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4833 | |
| 4834 | TestCompletionCallback callback; |
| 4835 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4836 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4837 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4838 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4839 | EXPECT_EQ(OK, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4840 | |
| 4841 | LoadTimingInfo load_timing_info; |
| 4842 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4843 | TestLoadTimingNotReused(load_timing_info, |
| 4844 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 4845 | |
| 4846 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4847 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4848 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 4849 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4850 | |
| 4851 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 4852 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4853 | rv = trans->Read(buf.get(), 256, callback.callback()); |
| 4854 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4855 | // Delete the first request, so the second one can reuse the socket. |
| 4856 | trans.reset(); |
| 4857 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4858 | scoped_ptr<HttpTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4859 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4860 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4861 | EXPECT_EQ(OK, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4862 | |
| 4863 | LoadTimingInfo load_timing_info2; |
| 4864 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4865 | TestLoadTimingReused(load_timing_info2); |
| 4866 | |
| 4867 | // The requests should have the same ID. |
| 4868 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 4869 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 4870 | rv = trans2->Read(buf.get(), 256, callback.callback()); |
| 4871 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 4872 | } |
| 4873 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4874 | // Test the challenge-response-retry sequence through an HTTPS Proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4875 | TEST_P(HttpNetworkTransactionTest, HttpsProxyAuthRetry) { |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4876 | HttpRequestInfo request; |
| 4877 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4878 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4879 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 4880 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4881 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4882 | // Configure against https proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4883 | session_deps_.proxy_service = ProxyService::CreateFixed("https://myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4884 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4885 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4886 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4887 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4888 | // Since we have proxy, should use full url |
| 4889 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4890 | MockWrite( |
| 4891 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 4892 | "Host: www.example.org\r\n" |
| 4893 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4894 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4895 | // After calling trans->RestartWithAuth(), this is the request we should |
| 4896 | // be issuing -- the final header line contains the credentials. |
| 4897 | MockWrite( |
| 4898 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 4899 | "Host: www.example.org\r\n" |
| 4900 | "Proxy-Connection: keep-alive\r\n" |
| 4901 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4902 | }; |
| 4903 | |
| 4904 | // The proxy responds to the GET with a 407, using a persistent |
| 4905 | // connection. |
| 4906 | MockRead data_reads1[] = { |
| 4907 | // No credentials. |
| 4908 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4909 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4910 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 4911 | MockRead("Content-Length: 0\r\n\r\n"), |
| 4912 | |
| 4913 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4914 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4915 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4916 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4917 | }; |
| 4918 | |
| 4919 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4920 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4921 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4922 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4923 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4924 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4925 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4926 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4927 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4928 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4929 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4930 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4931 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4932 | |
| 4933 | rv = callback1.WaitForResult(); |
| 4934 | EXPECT_EQ(OK, rv); |
| 4935 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4936 | LoadTimingInfo load_timing_info; |
| 4937 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4938 | TestLoadTimingNotReused(load_timing_info, |
| 4939 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 4940 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4941 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4942 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4943 | ASSERT_FALSE(response->headers.get() == NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4944 | EXPECT_EQ(407, response->headers->response_code()); |
| 4945 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4946 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4947 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4948 | TestCompletionCallback callback2; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4949 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4950 | rv = trans->RestartWithAuth( |
| 4951 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4952 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4953 | |
| 4954 | rv = callback2.WaitForResult(); |
| 4955 | EXPECT_EQ(OK, rv); |
| 4956 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4957 | load_timing_info = LoadTimingInfo(); |
| 4958 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4959 | // Retrying with HTTP AUTH is considered to be reusing a socket. |
| 4960 | TestLoadTimingReused(load_timing_info); |
| 4961 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4962 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 4963 | ASSERT_TRUE(response != NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4964 | |
| 4965 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4966 | EXPECT_EQ(200, response->headers->response_code()); |
| 4967 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 4968 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4969 | |
| 4970 | // The password prompt info should not be set. |
| 4971 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 4972 | } |
| 4973 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4974 | void HttpNetworkTransactionTest::ConnectStatusHelperWithExpectedStatus( |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4975 | const MockRead& status, int expected_status) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4976 | HttpRequestInfo request; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4977 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4978 | request.url = GURL("https://www.example.org/"); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4979 | request.load_flags = 0; |
| 4980 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4981 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4982 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4983 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4984 | |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4985 | // Since we have proxy, should try to establish tunnel. |
| 4986 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4987 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4988 | "Host: www.example.org:443\r\n" |
| 4989 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4990 | }; |
| 4991 | |
| 4992 | MockRead data_reads[] = { |
| 4993 | status, |
| 4994 | MockRead("Content-Length: 10\r\n\r\n"), |
| 4995 | // No response body because the test stops reading here. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4996 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 4997 | }; |
| 4998 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 4999 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 5000 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5001 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5002 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5003 | TestCompletionCallback callback; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5004 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5005 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5006 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5007 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5008 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5009 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5010 | |
| 5011 | rv = callback.WaitForResult(); |
| 5012 | EXPECT_EQ(expected_status, rv); |
| 5013 | } |
| 5014 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5015 | void HttpNetworkTransactionTest::ConnectStatusHelper( |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5016 | const MockRead& status) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5017 | ConnectStatusHelperWithExpectedStatus( |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5018 | status, ERR_TUNNEL_CONNECTION_FAILED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5019 | } |
| 5020 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5021 | TEST_P(HttpNetworkTransactionTest, ConnectStatus100) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5022 | ConnectStatusHelper(MockRead("HTTP/1.1 100 Continue\r\n")); |
| 5023 | } |
| 5024 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5025 | TEST_P(HttpNetworkTransactionTest, ConnectStatus101) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5026 | ConnectStatusHelper(MockRead("HTTP/1.1 101 Switching Protocols\r\n")); |
| 5027 | } |
| 5028 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5029 | TEST_P(HttpNetworkTransactionTest, ConnectStatus201) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5030 | ConnectStatusHelper(MockRead("HTTP/1.1 201 Created\r\n")); |
| 5031 | } |
| 5032 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5033 | TEST_P(HttpNetworkTransactionTest, ConnectStatus202) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5034 | ConnectStatusHelper(MockRead("HTTP/1.1 202 Accepted\r\n")); |
| 5035 | } |
| 5036 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5037 | TEST_P(HttpNetworkTransactionTest, ConnectStatus203) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5038 | ConnectStatusHelper( |
| 5039 | MockRead("HTTP/1.1 203 Non-Authoritative Information\r\n")); |
| 5040 | } |
| 5041 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5042 | TEST_P(HttpNetworkTransactionTest, ConnectStatus204) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5043 | ConnectStatusHelper(MockRead("HTTP/1.1 204 No Content\r\n")); |
| 5044 | } |
| 5045 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5046 | TEST_P(HttpNetworkTransactionTest, ConnectStatus205) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5047 | ConnectStatusHelper(MockRead("HTTP/1.1 205 Reset Content\r\n")); |
| 5048 | } |
| 5049 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5050 | TEST_P(HttpNetworkTransactionTest, ConnectStatus206) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5051 | ConnectStatusHelper(MockRead("HTTP/1.1 206 Partial Content\r\n")); |
| 5052 | } |
| 5053 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5054 | TEST_P(HttpNetworkTransactionTest, ConnectStatus300) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5055 | ConnectStatusHelper(MockRead("HTTP/1.1 300 Multiple Choices\r\n")); |
| 5056 | } |
| 5057 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5058 | TEST_P(HttpNetworkTransactionTest, ConnectStatus301) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5059 | ConnectStatusHelper(MockRead("HTTP/1.1 301 Moved Permanently\r\n")); |
| 5060 | } |
| 5061 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5062 | TEST_P(HttpNetworkTransactionTest, ConnectStatus302) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5063 | ConnectStatusHelper(MockRead("HTTP/1.1 302 Found\r\n")); |
| 5064 | } |
| 5065 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5066 | TEST_P(HttpNetworkTransactionTest, ConnectStatus303) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5067 | ConnectStatusHelper(MockRead("HTTP/1.1 303 See Other\r\n")); |
| 5068 | } |
| 5069 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5070 | TEST_P(HttpNetworkTransactionTest, ConnectStatus304) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5071 | ConnectStatusHelper(MockRead("HTTP/1.1 304 Not Modified\r\n")); |
| 5072 | } |
| 5073 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5074 | TEST_P(HttpNetworkTransactionTest, ConnectStatus305) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5075 | ConnectStatusHelper(MockRead("HTTP/1.1 305 Use Proxy\r\n")); |
| 5076 | } |
| 5077 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5078 | TEST_P(HttpNetworkTransactionTest, ConnectStatus306) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5079 | ConnectStatusHelper(MockRead("HTTP/1.1 306\r\n")); |
| 5080 | } |
| 5081 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5082 | TEST_P(HttpNetworkTransactionTest, ConnectStatus307) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5083 | ConnectStatusHelper(MockRead("HTTP/1.1 307 Temporary Redirect\r\n")); |
| 5084 | } |
| 5085 | |
[email protected] | 0a17aab3 | 2014-04-24 03:32:37 | [diff] [blame] | 5086 | TEST_P(HttpNetworkTransactionTest, ConnectStatus308) { |
| 5087 | ConnectStatusHelper(MockRead("HTTP/1.1 308 Permanent Redirect\r\n")); |
| 5088 | } |
| 5089 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5090 | TEST_P(HttpNetworkTransactionTest, ConnectStatus400) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5091 | ConnectStatusHelper(MockRead("HTTP/1.1 400 Bad Request\r\n")); |
| 5092 | } |
| 5093 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5094 | TEST_P(HttpNetworkTransactionTest, ConnectStatus401) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5095 | ConnectStatusHelper(MockRead("HTTP/1.1 401 Unauthorized\r\n")); |
| 5096 | } |
| 5097 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5098 | TEST_P(HttpNetworkTransactionTest, ConnectStatus402) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5099 | ConnectStatusHelper(MockRead("HTTP/1.1 402 Payment Required\r\n")); |
| 5100 | } |
| 5101 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5102 | TEST_P(HttpNetworkTransactionTest, ConnectStatus403) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5103 | ConnectStatusHelper(MockRead("HTTP/1.1 403 Forbidden\r\n")); |
| 5104 | } |
| 5105 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5106 | TEST_P(HttpNetworkTransactionTest, ConnectStatus404) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5107 | ConnectStatusHelper(MockRead("HTTP/1.1 404 Not Found\r\n")); |
| 5108 | } |
| 5109 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5110 | TEST_P(HttpNetworkTransactionTest, ConnectStatus405) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5111 | ConnectStatusHelper(MockRead("HTTP/1.1 405 Method Not Allowed\r\n")); |
| 5112 | } |
| 5113 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5114 | TEST_P(HttpNetworkTransactionTest, ConnectStatus406) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5115 | ConnectStatusHelper(MockRead("HTTP/1.1 406 Not Acceptable\r\n")); |
| 5116 | } |
| 5117 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5118 | TEST_P(HttpNetworkTransactionTest, ConnectStatus407) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5119 | ConnectStatusHelperWithExpectedStatus( |
| 5120 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
[email protected] | a7ea883 | 2010-07-12 17:54:54 | [diff] [blame] | 5121 | ERR_PROXY_AUTH_UNSUPPORTED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5122 | } |
| 5123 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5124 | TEST_P(HttpNetworkTransactionTest, ConnectStatus408) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5125 | ConnectStatusHelper(MockRead("HTTP/1.1 408 Request Timeout\r\n")); |
| 5126 | } |
| 5127 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5128 | TEST_P(HttpNetworkTransactionTest, ConnectStatus409) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5129 | ConnectStatusHelper(MockRead("HTTP/1.1 409 Conflict\r\n")); |
| 5130 | } |
| 5131 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5132 | TEST_P(HttpNetworkTransactionTest, ConnectStatus410) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5133 | ConnectStatusHelper(MockRead("HTTP/1.1 410 Gone\r\n")); |
| 5134 | } |
| 5135 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5136 | TEST_P(HttpNetworkTransactionTest, ConnectStatus411) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5137 | ConnectStatusHelper(MockRead("HTTP/1.1 411 Length Required\r\n")); |
| 5138 | } |
| 5139 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5140 | TEST_P(HttpNetworkTransactionTest, ConnectStatus412) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5141 | ConnectStatusHelper(MockRead("HTTP/1.1 412 Precondition Failed\r\n")); |
| 5142 | } |
| 5143 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5144 | TEST_P(HttpNetworkTransactionTest, ConnectStatus413) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5145 | ConnectStatusHelper(MockRead("HTTP/1.1 413 Request Entity Too Large\r\n")); |
| 5146 | } |
| 5147 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5148 | TEST_P(HttpNetworkTransactionTest, ConnectStatus414) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5149 | ConnectStatusHelper(MockRead("HTTP/1.1 414 Request-URI Too Long\r\n")); |
| 5150 | } |
| 5151 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5152 | TEST_P(HttpNetworkTransactionTest, ConnectStatus415) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5153 | ConnectStatusHelper(MockRead("HTTP/1.1 415 Unsupported Media Type\r\n")); |
| 5154 | } |
| 5155 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5156 | TEST_P(HttpNetworkTransactionTest, ConnectStatus416) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5157 | ConnectStatusHelper( |
| 5158 | MockRead("HTTP/1.1 416 Requested Range Not Satisfiable\r\n")); |
| 5159 | } |
| 5160 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5161 | TEST_P(HttpNetworkTransactionTest, ConnectStatus417) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5162 | ConnectStatusHelper(MockRead("HTTP/1.1 417 Expectation Failed\r\n")); |
| 5163 | } |
| 5164 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5165 | TEST_P(HttpNetworkTransactionTest, ConnectStatus500) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5166 | ConnectStatusHelper(MockRead("HTTP/1.1 500 Internal Server Error\r\n")); |
| 5167 | } |
| 5168 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5169 | TEST_P(HttpNetworkTransactionTest, ConnectStatus501) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5170 | ConnectStatusHelper(MockRead("HTTP/1.1 501 Not Implemented\r\n")); |
| 5171 | } |
| 5172 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5173 | TEST_P(HttpNetworkTransactionTest, ConnectStatus502) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5174 | ConnectStatusHelper(MockRead("HTTP/1.1 502 Bad Gateway\r\n")); |
| 5175 | } |
| 5176 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5177 | TEST_P(HttpNetworkTransactionTest, ConnectStatus503) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5178 | ConnectStatusHelper(MockRead("HTTP/1.1 503 Service Unavailable\r\n")); |
| 5179 | } |
| 5180 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5181 | TEST_P(HttpNetworkTransactionTest, ConnectStatus504) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5182 | ConnectStatusHelper(MockRead("HTTP/1.1 504 Gateway Timeout\r\n")); |
| 5183 | } |
| 5184 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5185 | TEST_P(HttpNetworkTransactionTest, ConnectStatus505) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5186 | ConnectStatusHelper(MockRead("HTTP/1.1 505 HTTP Version Not Supported\r\n")); |
| 5187 | } |
| 5188 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5189 | // Test the flow when both the proxy server AND origin server require |
| 5190 | // authentication. Again, this uses basic auth for both since that is |
| 5191 | // the simplest to mock. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5192 | TEST_P(HttpNetworkTransactionTest, BasicAuthProxyThenServer) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5193 | HttpRequestInfo request; |
| 5194 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5195 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5196 | request.load_flags = 0; |
| 5197 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5198 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5199 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 5200 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 5201 | |
| 5202 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 5203 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5204 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5205 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5206 | MockWrite( |
| 5207 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5208 | "Host: www.example.org\r\n" |
| 5209 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5210 | }; |
| 5211 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5212 | MockRead data_reads1[] = { |
| 5213 | MockRead("HTTP/1.0 407 Unauthorized\r\n"), |
| 5214 | // Give a couple authenticate options (only the middle one is actually |
| 5215 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 5216 | MockRead("Proxy-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5217 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5218 | MockRead("Proxy-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 5219 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5220 | // Large content-length -- won't matter, as connection will be reset. |
| 5221 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5222 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5223 | }; |
| 5224 | |
| 5225 | // After calling trans->RestartWithAuth() the first time, this is the |
| 5226 | // request we should be issuing -- the final header line contains the |
| 5227 | // proxy's credentials. |
| 5228 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5229 | MockWrite( |
| 5230 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5231 | "Host: www.example.org\r\n" |
| 5232 | "Proxy-Connection: keep-alive\r\n" |
| 5233 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5234 | }; |
| 5235 | |
| 5236 | // Now the proxy server lets the request pass through to origin server. |
| 5237 | // The origin server responds with a 401. |
| 5238 | MockRead data_reads2[] = { |
| 5239 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5240 | // Note: We are using the same realm-name as the proxy server. This is |
| 5241 | // completely valid, as realms are unique across hosts. |
| 5242 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5243 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5244 | MockRead("Content-Length: 2000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5245 | MockRead(SYNCHRONOUS, ERR_FAILED), // Won't be reached. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5246 | }; |
| 5247 | |
| 5248 | // After calling trans->RestartWithAuth() the second time, we should send |
| 5249 | // the credentials for both the proxy and origin server. |
| 5250 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5251 | MockWrite( |
| 5252 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5253 | "Host: www.example.org\r\n" |
| 5254 | "Proxy-Connection: keep-alive\r\n" |
| 5255 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n" |
| 5256 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5257 | }; |
| 5258 | |
| 5259 | // Lastly we get the desired content. |
| 5260 | MockRead data_reads3[] = { |
| 5261 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5262 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5263 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5264 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5265 | }; |
| 5266 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5267 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5268 | data_writes1, arraysize(data_writes1)); |
| 5269 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5270 | data_writes2, arraysize(data_writes2)); |
| 5271 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 5272 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5273 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5274 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 5275 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5276 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5277 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5278 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5279 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5280 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5281 | |
| 5282 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5283 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5284 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5285 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5286 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5287 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5288 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5289 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5290 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5291 | rv = trans->RestartWithAuth( |
| 5292 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5293 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5294 | |
| 5295 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5296 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5297 | |
| 5298 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5299 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5300 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5301 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5302 | TestCompletionCallback callback3; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5303 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5304 | rv = trans->RestartWithAuth( |
| 5305 | AuthCredentials(kFoo2, kBar2), callback3.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5306 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5307 | |
| 5308 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5309 | EXPECT_EQ(OK, rv); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5310 | |
| 5311 | response = trans->GetResponseInfo(); |
| 5312 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5313 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5314 | } |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5315 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 5316 | // For the NTLM implementation using SSPI, we skip the NTLM tests since we |
| 5317 | // can't hook into its internals to cause it to generate predictable NTLM |
| 5318 | // authorization headers. |
| 5319 | #if defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5320 | // The NTLM authentication unit tests were generated by capturing the HTTP |
| 5321 | // requests and responses using Fiddler 2 and inspecting the generated random |
| 5322 | // bytes in the debugger. |
| 5323 | |
| 5324 | // Enter the correct password and authenticate successfully. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5325 | TEST_P(HttpNetworkTransactionTest, NTLMAuth1) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5326 | HttpRequestInfo request; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5327 | request.method = "GET"; |
| 5328 | request.url = GURL("http://172.22.68.17/kids/login.aspx"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 5329 | |
| 5330 | // Ensure load is not disrupted by flags which suppress behaviour specific |
| 5331 | // to other auth schemes. |
| 5332 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5333 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5334 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom1, |
| 5335 | MockGetHostName); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 5336 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5337 | |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5338 | MockWrite data_writes1[] = { |
| 5339 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5340 | "Host: 172.22.68.17\r\n" |
| 5341 | "Connection: keep-alive\r\n\r\n"), |
| 5342 | }; |
| 5343 | |
| 5344 | MockRead data_reads1[] = { |
| 5345 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 5346 | // Negotiate and NTLM are often requested together. However, we only want |
| 5347 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 5348 | // the header that requests Negotiate for this test. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5349 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 5350 | MockRead("Connection: close\r\n"), |
| 5351 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 5352 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5353 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5354 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5355 | }; |
| 5356 | |
| 5357 | MockWrite data_writes2[] = { |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5358 | // After restarting with a null identity, this is the |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5359 | // request we should be issuing -- the final header line contains a Type |
| 5360 | // 1 message. |
| 5361 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5362 | "Host: 172.22.68.17\r\n" |
| 5363 | "Connection: keep-alive\r\n" |
| 5364 | "Authorization: NTLM " |
| 5365 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
| 5366 | |
| 5367 | // After calling trans->RestartWithAuth(), we should send a Type 3 message |
| 5368 | // (the credentials for the origin server). The second request continues |
| 5369 | // on the same connection. |
| 5370 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5371 | "Host: 172.22.68.17\r\n" |
| 5372 | "Connection: keep-alive\r\n" |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5373 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 5374 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 5375 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwBVKW" |
| 5376 | "Yma5xzVAAAAAAAAAAAAAAAAAAAAACH+gWcm+YsP9Tqb9zCR3WAeZZX" |
| 5377 | "ahlhx5I=\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5378 | }; |
| 5379 | |
| 5380 | MockRead data_reads2[] = { |
| 5381 | // The origin server responds with a Type 2 message. |
| 5382 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 5383 | MockRead("WWW-Authenticate: NTLM " |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5384 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCjGpMpPGlYKkAAAAAAAAAALo" |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5385 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 5386 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 5387 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 5388 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 5389 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 5390 | "BtAAAAAAA=\r\n"), |
| 5391 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 5392 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5393 | MockRead("You are not authorized to view this page\r\n"), |
| 5394 | |
| 5395 | // Lastly we get the desired content. |
| 5396 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5397 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 5398 | MockRead("Content-Length: 13\r\n\r\n"), |
| 5399 | MockRead("Please Login\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5400 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5401 | }; |
| 5402 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5403 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5404 | data_writes1, arraysize(data_writes1)); |
| 5405 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5406 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5407 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5408 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5409 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5410 | TestCompletionCallback callback1; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5411 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5412 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5413 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5414 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5415 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5416 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5417 | |
| 5418 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5419 | EXPECT_EQ(OK, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5420 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5421 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5422 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5423 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5424 | ASSERT_FALSE(response == NULL); |
| 5425 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5426 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5427 | TestCompletionCallback callback2; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5428 | |
[email protected] | f3cf980 | 2011-10-28 18:44:58 | [diff] [blame] | 5429 | rv = trans->RestartWithAuth(AuthCredentials(kTestingNTLM, kTestingNTLM), |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5430 | callback2.callback()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5431 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5432 | |
| 5433 | rv = callback2.WaitForResult(); |
| 5434 | EXPECT_EQ(OK, rv); |
| 5435 | |
| 5436 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 5437 | |
| 5438 | response = trans->GetResponseInfo(); |
| 5439 | ASSERT_TRUE(response != NULL); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5440 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5441 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5442 | TestCompletionCallback callback3; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5443 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5444 | rv = trans->RestartWithAuth(AuthCredentials(), callback3.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5445 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5446 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5447 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5448 | EXPECT_EQ(OK, rv); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5449 | |
| 5450 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5451 | ASSERT_TRUE(response != NULL); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5452 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5453 | EXPECT_EQ(13, response->headers->GetContentLength()); |
| 5454 | } |
| 5455 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5456 | // Enter a wrong password, and then the correct one. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5457 | TEST_P(HttpNetworkTransactionTest, NTLMAuth2) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5458 | HttpRequestInfo request; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5459 | request.method = "GET"; |
| 5460 | request.url = GURL("http://172.22.68.17/kids/login.aspx"); |
| 5461 | request.load_flags = 0; |
| 5462 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5463 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom2, |
| 5464 | MockGetHostName); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 5465 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5466 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5467 | MockWrite data_writes1[] = { |
| 5468 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5469 | "Host: 172.22.68.17\r\n" |
| 5470 | "Connection: keep-alive\r\n\r\n"), |
| 5471 | }; |
| 5472 | |
| 5473 | MockRead data_reads1[] = { |
| 5474 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 5475 | // Negotiate and NTLM are often requested together. However, we only want |
| 5476 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 5477 | // the header that requests Negotiate for this test. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5478 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 5479 | MockRead("Connection: close\r\n"), |
| 5480 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 5481 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5482 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5483 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5484 | }; |
| 5485 | |
| 5486 | MockWrite data_writes2[] = { |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5487 | // After restarting with a null identity, this is the |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5488 | // request we should be issuing -- the final header line contains a Type |
| 5489 | // 1 message. |
| 5490 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5491 | "Host: 172.22.68.17\r\n" |
| 5492 | "Connection: keep-alive\r\n" |
| 5493 | "Authorization: NTLM " |
| 5494 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
| 5495 | |
| 5496 | // After calling trans->RestartWithAuth(), we should send a Type 3 message |
| 5497 | // (the credentials for the origin server). The second request continues |
| 5498 | // on the same connection. |
| 5499 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5500 | "Host: 172.22.68.17\r\n" |
| 5501 | "Connection: keep-alive\r\n" |
| 5502 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 5503 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 5504 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwCWeY" |
| 5505 | "XnSZNwoQAAAAAAAAAAAAAAAAAAAADLa34/phTTKzNTWdub+uyFleOj" |
| 5506 | "4Ww7b7E=\r\n\r\n"), |
| 5507 | }; |
| 5508 | |
| 5509 | MockRead data_reads2[] = { |
| 5510 | // The origin server responds with a Type 2 message. |
| 5511 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 5512 | MockRead("WWW-Authenticate: NTLM " |
| 5513 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCbVWUZezVGpAAAAAAAAAAALo" |
| 5514 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 5515 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 5516 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 5517 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 5518 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 5519 | "BtAAAAAAA=\r\n"), |
| 5520 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 5521 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5522 | MockRead("You are not authorized to view this page\r\n"), |
| 5523 | |
| 5524 | // Wrong password. |
| 5525 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5526 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 5527 | MockRead("Connection: close\r\n"), |
| 5528 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 5529 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5530 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5531 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5532 | }; |
| 5533 | |
| 5534 | MockWrite data_writes3[] = { |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5535 | // After restarting with a null identity, this is the |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5536 | // request we should be issuing -- the final header line contains a Type |
| 5537 | // 1 message. |
| 5538 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5539 | "Host: 172.22.68.17\r\n" |
| 5540 | "Connection: keep-alive\r\n" |
| 5541 | "Authorization: NTLM " |
| 5542 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
| 5543 | |
| 5544 | // After calling trans->RestartWithAuth(), we should send a Type 3 message |
| 5545 | // (the credentials for the origin server). The second request continues |
| 5546 | // on the same connection. |
| 5547 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5548 | "Host: 172.22.68.17\r\n" |
| 5549 | "Connection: keep-alive\r\n" |
| 5550 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 5551 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 5552 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwBO54" |
| 5553 | "dFMVvTHwAAAAAAAAAAAAAAAAAAAACS7sT6Uzw7L0L//WUqlIaVWpbI" |
| 5554 | "+4MUm7c=\r\n\r\n"), |
| 5555 | }; |
| 5556 | |
| 5557 | MockRead data_reads3[] = { |
| 5558 | // The origin server responds with a Type 2 message. |
| 5559 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 5560 | MockRead("WWW-Authenticate: NTLM " |
| 5561 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCL24VN8dgOR8AAAAAAAAAALo" |
| 5562 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 5563 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 5564 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 5565 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 5566 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 5567 | "BtAAAAAAA=\r\n"), |
| 5568 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 5569 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5570 | MockRead("You are not authorized to view this page\r\n"), |
| 5571 | |
| 5572 | // Lastly we get the desired content. |
| 5573 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5574 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 5575 | MockRead("Content-Length: 13\r\n\r\n"), |
| 5576 | MockRead("Please Login\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5577 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5578 | }; |
| 5579 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5580 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5581 | data_writes1, arraysize(data_writes1)); |
| 5582 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5583 | data_writes2, arraysize(data_writes2)); |
| 5584 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 5585 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5586 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5587 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 5588 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5589 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5590 | TestCompletionCallback callback1; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5591 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5592 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5593 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5594 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5595 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5596 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5597 | |
| 5598 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5599 | EXPECT_EQ(OK, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5600 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5601 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5602 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5603 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5604 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5605 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5606 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5607 | TestCompletionCallback callback2; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5608 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5609 | // Enter the wrong password. |
[email protected] | f3cf980 | 2011-10-28 18:44:58 | [diff] [blame] | 5610 | rv = trans->RestartWithAuth(AuthCredentials(kTestingNTLM, kWrongPassword), |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5611 | callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5612 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5613 | |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5614 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5615 | EXPECT_EQ(OK, rv); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5616 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5617 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5618 | TestCompletionCallback callback3; |
| 5619 | rv = trans->RestartWithAuth(AuthCredentials(), callback3.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5620 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5621 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5622 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5623 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 5624 | |
| 5625 | response = trans->GetResponseInfo(); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5626 | ASSERT_FALSE(response == NULL); |
| 5627 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5628 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5629 | TestCompletionCallback callback4; |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5630 | |
| 5631 | // Now enter the right password. |
[email protected] | f3cf980 | 2011-10-28 18:44:58 | [diff] [blame] | 5632 | rv = trans->RestartWithAuth(AuthCredentials(kTestingNTLM, kTestingNTLM), |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5633 | callback4.callback()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5634 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5635 | |
| 5636 | rv = callback4.WaitForResult(); |
| 5637 | EXPECT_EQ(OK, rv); |
| 5638 | |
| 5639 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 5640 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5641 | TestCompletionCallback callback5; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5642 | |
| 5643 | // One more roundtrip |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5644 | rv = trans->RestartWithAuth(AuthCredentials(), callback5.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5645 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5646 | |
| 5647 | rv = callback5.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5648 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5649 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5650 | response = trans->GetResponseInfo(); |
| 5651 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 5652 | EXPECT_EQ(13, response->headers->GetContentLength()); |
| 5653 | } |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 5654 | #endif // NTLM_PORTABLE |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5655 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5656 | // Test reading a server response which has only headers, and no body. |
| 5657 | // After some maximum number of bytes is consumed, the transaction should |
| 5658 | // fail with ERR_RESPONSE_HEADERS_TOO_BIG. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5659 | TEST_P(HttpNetworkTransactionTest, LargeHeadersNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5660 | HttpRequestInfo request; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5661 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5662 | request.url = GURL("http://www.example.org/"); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5663 | request.load_flags = 0; |
| 5664 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 5665 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5666 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 5667 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5668 | |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 5669 | // Respond with 300 kb of headers (we should fail after 256 kb). |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 5670 | std::string large_headers_string; |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 5671 | FillLargeHeadersString(&large_headers_string, 300 * 1024); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5672 | |
| 5673 | MockRead data_reads[] = { |
| 5674 | MockRead("HTTP/1.0 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5675 | MockRead(ASYNC, large_headers_string.data(), large_headers_string.size()), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5676 | MockRead("\r\nBODY"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5677 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5678 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5679 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5680 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5681 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5682 | TestCompletionCallback callback; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5683 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5684 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5685 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5686 | |
| 5687 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5688 | EXPECT_EQ(ERR_RESPONSE_HEADERS_TOO_BIG, rv); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5689 | } |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5690 | |
| 5691 | // Make sure that we don't try to reuse a TCPClientSocket when failing to |
| 5692 | // establish tunnel. |
| 5693 | // http://code.google.com/p/chromium/issues/detail?id=3772 |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5694 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5695 | DontRecycleTransportSocketForSSLTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5696 | HttpRequestInfo request; |
| 5697 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5698 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5699 | request.load_flags = 0; |
| 5700 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5701 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5702 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | db8f44c | 2008-12-13 04:52:01 | [diff] [blame] | 5703 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 5704 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5705 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5706 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5707 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5708 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5709 | // Since we have proxy, should try to establish tunnel. |
| 5710 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5711 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5712 | "Host: www.example.org:443\r\n" |
| 5713 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5714 | }; |
| 5715 | |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 5716 | // The proxy responds to the connect with a 404, using a persistent |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5717 | // connection. Usually a proxy would return 501 (not implemented), |
| 5718 | // or 200 (tunnel established). |
| 5719 | MockRead data_reads1[] = { |
| 5720 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 5721 | MockRead("Content-Length: 10\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5722 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5723 | }; |
| 5724 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5725 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5726 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5727 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5728 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5729 | TestCompletionCallback callback1; |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5730 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5731 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5732 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5733 | |
| 5734 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5735 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5736 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5737 | // Empty the current queue. This is necessary because idle sockets are |
| 5738 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5739 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5740 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5741 | // We now check to make sure the TCPClientSocket was not added back to |
| 5742 | // the pool. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5743 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5744 | trans.reset(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5745 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5746 | // Make sure that the socket didn't get recycled after calling the destructor. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5747 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 5748 | } |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 5749 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5750 | // 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] | 5751 | TEST_P(HttpNetworkTransactionTest, RecycleSocket) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5752 | HttpRequestInfo request; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5753 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5754 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5755 | request.load_flags = 0; |
| 5756 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 5757 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5758 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5759 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5760 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5761 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5762 | MockRead data_reads[] = { |
| 5763 | // A part of the response body is received with the response headers. |
| 5764 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 5765 | // The rest of the response body is received in two parts. |
| 5766 | MockRead("lo"), |
| 5767 | MockRead(" world"), |
| 5768 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5769 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5770 | }; |
| 5771 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5772 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5773 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5774 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5775 | TestCompletionCallback callback; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5776 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5777 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5778 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5779 | |
| 5780 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5781 | EXPECT_EQ(OK, rv); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5782 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5783 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5784 | ASSERT_TRUE(response != NULL); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5785 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5786 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5787 | std::string status_line = response->headers->GetStatusLine(); |
| 5788 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 5789 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5790 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5791 | |
| 5792 | std::string response_data; |
| 5793 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5794 | EXPECT_EQ(OK, rv); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5795 | EXPECT_EQ("hello world", response_data); |
| 5796 | |
| 5797 | // Empty the current queue. This is necessary because idle sockets are |
| 5798 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5799 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5800 | |
| 5801 | // 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] | 5802 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 5803 | } |
| 5804 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5805 | // Make sure that we recycle a SSL socket after reading all of the response |
| 5806 | // body. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5807 | TEST_P(HttpNetworkTransactionTest, RecycleSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5808 | HttpRequestInfo request; |
| 5809 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5810 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5811 | request.load_flags = 0; |
| 5812 | |
| 5813 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5814 | MockWrite( |
| 5815 | "GET / HTTP/1.1\r\n" |
| 5816 | "Host: www.example.org\r\n" |
| 5817 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5818 | }; |
| 5819 | |
| 5820 | MockRead data_reads[] = { |
| 5821 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5822 | MockRead("Content-Length: 11\r\n\r\n"), |
| 5823 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5824 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5825 | }; |
| 5826 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5827 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5828 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5829 | |
| 5830 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 5831 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5832 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5833 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5834 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5835 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 5836 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5837 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5838 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5839 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5840 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5841 | |
| 5842 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5843 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 5844 | |
| 5845 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5846 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5847 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5848 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5849 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5850 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5851 | |
| 5852 | std::string response_data; |
| 5853 | rv = ReadTransaction(trans.get(), &response_data); |
| 5854 | EXPECT_EQ(OK, rv); |
| 5855 | EXPECT_EQ("hello world", response_data); |
| 5856 | |
| 5857 | // Empty the current queue. This is necessary because idle sockets are |
| 5858 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5859 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5860 | |
| 5861 | // 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] | 5862 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5863 | } |
| 5864 | |
| 5865 | // Grab a SSL socket, use it, and put it back into the pool. Then, reuse it |
| 5866 | // from the pool and make sure that we recover okay. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5867 | TEST_P(HttpNetworkTransactionTest, RecycleDeadSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5868 | HttpRequestInfo request; |
| 5869 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5870 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5871 | request.load_flags = 0; |
| 5872 | |
| 5873 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5874 | MockWrite( |
| 5875 | "GET / HTTP/1.1\r\n" |
| 5876 | "Host: www.example.org\r\n" |
| 5877 | "Connection: keep-alive\r\n\r\n"), |
| 5878 | MockWrite( |
| 5879 | "GET / HTTP/1.1\r\n" |
| 5880 | "Host: www.example.org\r\n" |
| 5881 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5882 | }; |
| 5883 | |
| 5884 | MockRead data_reads[] = { |
| 5885 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5886 | MockRead("Content-Length: 11\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5887 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5888 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5889 | MockRead(ASYNC, 0, 0) // EOF |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5890 | }; |
| 5891 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5892 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 5893 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5894 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 5895 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5896 | |
| 5897 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 5898 | data_writes, arraysize(data_writes)); |
| 5899 | StaticSocketDataProvider data2(data_reads, arraysize(data_reads), |
| 5900 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5901 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 5902 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5903 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5904 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5905 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 5906 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5907 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5908 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5909 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5910 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5911 | |
| 5912 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5913 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 5914 | |
| 5915 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5916 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5917 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5918 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5919 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5920 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5921 | |
| 5922 | std::string response_data; |
| 5923 | rv = ReadTransaction(trans.get(), &response_data); |
| 5924 | EXPECT_EQ(OK, rv); |
| 5925 | EXPECT_EQ("hello world", response_data); |
| 5926 | |
| 5927 | // Empty the current queue. This is necessary because idle sockets are |
| 5928 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5929 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5930 | |
| 5931 | // 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] | 5932 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5933 | |
| 5934 | // Now start the second transaction, which should reuse the previous socket. |
| 5935 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5936 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5937 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5938 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5939 | |
| 5940 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5941 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 5942 | |
| 5943 | response = trans->GetResponseInfo(); |
| 5944 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5945 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5946 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5947 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5948 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5949 | |
| 5950 | rv = ReadTransaction(trans.get(), &response_data); |
| 5951 | EXPECT_EQ(OK, rv); |
| 5952 | EXPECT_EQ("hello world", response_data); |
| 5953 | |
| 5954 | // Empty the current queue. This is necessary because idle sockets are |
| 5955 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 5956 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5957 | |
| 5958 | // We now check to make sure the socket was added back to the pool. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5959 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 5960 | } |
| 5961 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5962 | // Make sure that we recycle a socket after a zero-length response. |
| 5963 | // http://crbug.com/9880 |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5964 | TEST_P(HttpNetworkTransactionTest, RecycleSocketAfterZeroContentLength) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5965 | HttpRequestInfo request; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5966 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5967 | request.url = GURL( |
| 5968 | "http://www.example.org/csi?v=3&s=web&action=&" |
| 5969 | "tran=undefined&ei=mAXcSeegAo-SMurloeUN&" |
| 5970 | "e=17259,18167,19592,19773,19981,20133,20173,20233&" |
| 5971 | "rt=prt.2642,ol.2649,xjs.2951"); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5972 | request.load_flags = 0; |
| 5973 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 5974 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5975 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5976 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5977 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5978 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5979 | MockRead data_reads[] = { |
| 5980 | MockRead("HTTP/1.1 204 No Content\r\n" |
| 5981 | "Content-Length: 0\r\n" |
| 5982 | "Content-Type: text/html\r\n\r\n"), |
| 5983 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5984 | MockRead(SYNCHRONOUS, OK), |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5985 | }; |
| 5986 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5987 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5988 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5989 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5990 | TestCompletionCallback callback; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5991 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5992 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5993 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5994 | |
| 5995 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5996 | EXPECT_EQ(OK, rv); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 5997 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5998 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 5999 | ASSERT_TRUE(response != NULL); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6000 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6001 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6002 | std::string status_line = response->headers->GetStatusLine(); |
| 6003 | EXPECT_EQ("HTTP/1.1 204 No Content", status_line); |
| 6004 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6005 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6006 | |
| 6007 | std::string response_data; |
| 6008 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6009 | EXPECT_EQ(OK, rv); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6010 | EXPECT_EQ("", response_data); |
| 6011 | |
| 6012 | // Empty the current queue. This is necessary because idle sockets are |
| 6013 | // added to the connection pool asynchronously with a PostTask. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 6014 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6015 | |
| 6016 | // 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] | 6017 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6018 | } |
| 6019 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6020 | TEST_P(HttpNetworkTransactionTest, ResendRequestOnWriteBodyError) { |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 6021 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 6022 | element_readers.push_back( |
| 6023 | make_scoped_ptr(new UploadBytesElementReader("foo", 3))); |
| 6024 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 6025 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6026 | HttpRequestInfo request[2]; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6027 | // Transaction 1: a GET request that succeeds. The socket is recycled |
| 6028 | // after use. |
| 6029 | request[0].method = "GET"; |
| 6030 | request[0].url = GURL("http://www.google.com/"); |
| 6031 | request[0].load_flags = 0; |
| 6032 | // Transaction 2: a POST request. Reuses the socket kept alive from |
| 6033 | // transaction 1. The first attempts fails when writing the POST data. |
| 6034 | // This causes the transaction to retry with a new socket. The second |
| 6035 | // attempt succeeds. |
| 6036 | request[1].method = "POST"; |
| 6037 | request[1].url = GURL("http://www.google.com/login.cgi"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 6038 | request[1].upload_data_stream = &upload_data_stream; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6039 | request[1].load_flags = 0; |
| 6040 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 6041 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6042 | |
| 6043 | // The first socket is used for transaction 1 and the first attempt of |
| 6044 | // transaction 2. |
| 6045 | |
| 6046 | // The response of transaction 1. |
| 6047 | MockRead data_reads1[] = { |
| 6048 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\n"), |
| 6049 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6050 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6051 | }; |
| 6052 | // The mock write results of transaction 1 and the first attempt of |
| 6053 | // transaction 2. |
| 6054 | MockWrite data_writes1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6055 | MockWrite(SYNCHRONOUS, 64), // GET |
| 6056 | MockWrite(SYNCHRONOUS, 93), // POST |
| 6057 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_ABORTED), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6058 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6059 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6060 | data_writes1, arraysize(data_writes1)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6061 | |
| 6062 | // The second socket is used for the second attempt of transaction 2. |
| 6063 | |
| 6064 | // The response of transaction 2. |
| 6065 | MockRead data_reads2[] = { |
| 6066 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 7\r\n\r\n"), |
| 6067 | MockRead("welcome"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6068 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6069 | }; |
| 6070 | // The mock write results of the second attempt of transaction 2. |
| 6071 | MockWrite data_writes2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6072 | MockWrite(SYNCHRONOUS, 93), // POST |
| 6073 | MockWrite(SYNCHRONOUS, 3), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6074 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6075 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6076 | data_writes2, arraysize(data_writes2)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6077 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6078 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6079 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6080 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 6081 | const char* const kExpectedResponseData[] = { |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6082 | "hello world", "welcome" |
| 6083 | }; |
| 6084 | |
| 6085 | for (int i = 0; i < 2; ++i) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6086 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6087 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6088 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6089 | TestCompletionCallback callback; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6090 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6091 | int rv = trans->Start(&request[i], callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6092 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6093 | |
| 6094 | rv = callback.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6095 | EXPECT_EQ(OK, rv); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6096 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6097 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6098 | ASSERT_TRUE(response != NULL); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6099 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6100 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6101 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6102 | |
| 6103 | std::string response_data; |
| 6104 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6105 | EXPECT_EQ(OK, rv); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6106 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
| 6107 | } |
| 6108 | } |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6109 | |
| 6110 | // Test the request-challenge-retry sequence for basic auth when there is |
| 6111 | // 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] | 6112 | // it fails the identity from the URL is used to answer the challenge. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6113 | TEST_P(HttpNetworkTransactionTest, AuthIdentityInURL) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6114 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6115 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6116 | request.url = GURL("http://foo:b@[email protected]/"); |
[email protected] | 7b08ba6 | 2012-02-10 20:19:41 | [diff] [blame] | 6117 | request.load_flags = LOAD_NORMAL; |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 6118 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 6119 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6120 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6121 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6122 | |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 6123 | // The password contains an escaped character -- for this test to pass it |
| 6124 | // will need to be unescaped by HttpNetworkTransaction. |
| 6125 | EXPECT_EQ("b%40r", request.url.password()); |
| 6126 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6127 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6128 | MockWrite( |
| 6129 | "GET / HTTP/1.1\r\n" |
| 6130 | "Host: www.example.org\r\n" |
| 6131 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6132 | }; |
| 6133 | |
| 6134 | MockRead data_reads1[] = { |
| 6135 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6136 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6137 | MockRead("Content-Length: 10\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6138 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6139 | }; |
| 6140 | |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6141 | // After the challenge above, the transaction will be restarted using the |
| 6142 | // identity from the url (foo, b@r) to answer the challenge. |
| 6143 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6144 | MockWrite( |
| 6145 | "GET / HTTP/1.1\r\n" |
| 6146 | "Host: www.example.org\r\n" |
| 6147 | "Connection: keep-alive\r\n" |
| 6148 | "Authorization: Basic Zm9vOmJAcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6149 | }; |
| 6150 | |
| 6151 | MockRead data_reads2[] = { |
| 6152 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6153 | MockRead("Content-Length: 100\r\n\r\n"), |
| 6154 | MockRead(SYNCHRONOUS, OK), |
| 6155 | }; |
| 6156 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6157 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6158 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6159 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6160 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6161 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6162 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6163 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6164 | TestCompletionCallback callback1; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6165 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6166 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6167 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6168 | EXPECT_EQ(OK, rv); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6169 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 6170 | |
| 6171 | TestCompletionCallback callback2; |
| 6172 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
| 6173 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6174 | rv = callback2.WaitForResult(); |
| 6175 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6176 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 6177 | |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6178 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6179 | ASSERT_TRUE(response != NULL); |
| 6180 | |
| 6181 | // There is no challenge info, since the identity in URL worked. |
| 6182 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6183 | |
| 6184 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6185 | |
| 6186 | // Empty the current queue. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 6187 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6188 | } |
| 6189 | |
| 6190 | // Test the request-challenge-retry sequence for basic auth when there is an |
| 6191 | // incorrect identity in the URL. The identity from the URL should be used only |
| 6192 | // once. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6193 | TEST_P(HttpNetworkTransactionTest, WrongAuthIdentityInURL) { |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6194 | HttpRequestInfo request; |
| 6195 | request.method = "GET"; |
| 6196 | // Note: the URL has a username:password in it. The password "baz" is |
| 6197 | // wrong (should be "bar"). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6198 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6199 | |
| 6200 | request.load_flags = LOAD_NORMAL; |
| 6201 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 6202 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6203 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6204 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6205 | |
| 6206 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6207 | MockWrite( |
| 6208 | "GET / HTTP/1.1\r\n" |
| 6209 | "Host: www.example.org\r\n" |
| 6210 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6211 | }; |
| 6212 | |
| 6213 | MockRead data_reads1[] = { |
| 6214 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6215 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6216 | MockRead("Content-Length: 10\r\n\r\n"), |
| 6217 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 6218 | }; |
| 6219 | |
| 6220 | // After the challenge above, the transaction will be restarted using the |
| 6221 | // identity from the url (foo, baz) to answer the challenge. |
| 6222 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6223 | MockWrite( |
| 6224 | "GET / HTTP/1.1\r\n" |
| 6225 | "Host: www.example.org\r\n" |
| 6226 | "Connection: keep-alive\r\n" |
| 6227 | "Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6228 | }; |
| 6229 | |
| 6230 | MockRead data_reads2[] = { |
| 6231 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6232 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6233 | MockRead("Content-Length: 10\r\n\r\n"), |
| 6234 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 6235 | }; |
| 6236 | |
| 6237 | // After the challenge above, the transaction will be restarted using the |
| 6238 | // identity supplied by the user (foo, bar) to answer the challenge. |
| 6239 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6240 | MockWrite( |
| 6241 | "GET / HTTP/1.1\r\n" |
| 6242 | "Host: www.example.org\r\n" |
| 6243 | "Connection: keep-alive\r\n" |
| 6244 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6245 | }; |
| 6246 | |
| 6247 | MockRead data_reads3[] = { |
| 6248 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6249 | MockRead("Content-Length: 100\r\n\r\n"), |
| 6250 | MockRead(SYNCHRONOUS, OK), |
| 6251 | }; |
| 6252 | |
| 6253 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6254 | data_writes1, arraysize(data_writes1)); |
| 6255 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6256 | data_writes2, arraysize(data_writes2)); |
| 6257 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 6258 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6259 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6260 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 6261 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6262 | |
| 6263 | TestCompletionCallback callback1; |
| 6264 | |
| 6265 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
| 6266 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6267 | |
| 6268 | rv = callback1.WaitForResult(); |
| 6269 | EXPECT_EQ(OK, rv); |
| 6270 | |
| 6271 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 6272 | TestCompletionCallback callback2; |
| 6273 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
| 6274 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6275 | rv = callback2.WaitForResult(); |
| 6276 | EXPECT_EQ(OK, rv); |
| 6277 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 6278 | |
| 6279 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6280 | ASSERT_TRUE(response != NULL); |
| 6281 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 6282 | |
| 6283 | TestCompletionCallback callback3; |
| 6284 | rv = trans->RestartWithAuth( |
| 6285 | AuthCredentials(kFoo, kBar), callback3.callback()); |
| 6286 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6287 | rv = callback3.WaitForResult(); |
| 6288 | EXPECT_EQ(OK, rv); |
| 6289 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 6290 | |
| 6291 | response = trans->GetResponseInfo(); |
| 6292 | ASSERT_TRUE(response != NULL); |
| 6293 | |
| 6294 | // There is no challenge info, since the identity worked. |
| 6295 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6296 | |
| 6297 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6298 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 6299 | // Empty the current queue. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 6300 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 6301 | } |
| 6302 | |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6303 | |
| 6304 | // Test the request-challenge-retry sequence for basic auth when there is a |
| 6305 | // correct identity in the URL, but its use is being suppressed. The identity |
| 6306 | // from the URL should never be used. |
| 6307 | TEST_P(HttpNetworkTransactionTest, AuthIdentityInURLSuppressed) { |
| 6308 | HttpRequestInfo request; |
| 6309 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6310 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6311 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
| 6312 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 6313 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6314 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6315 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6316 | |
| 6317 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6318 | MockWrite( |
| 6319 | "GET / HTTP/1.1\r\n" |
| 6320 | "Host: www.example.org\r\n" |
| 6321 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6322 | }; |
| 6323 | |
| 6324 | MockRead data_reads1[] = { |
| 6325 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6326 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6327 | MockRead("Content-Length: 10\r\n\r\n"), |
| 6328 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 6329 | }; |
| 6330 | |
| 6331 | // After the challenge above, the transaction will be restarted using the |
| 6332 | // identity supplied by the user, not the one in the URL, to answer the |
| 6333 | // challenge. |
| 6334 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6335 | MockWrite( |
| 6336 | "GET / HTTP/1.1\r\n" |
| 6337 | "Host: www.example.org\r\n" |
| 6338 | "Connection: keep-alive\r\n" |
| 6339 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6340 | }; |
| 6341 | |
| 6342 | MockRead data_reads3[] = { |
| 6343 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6344 | MockRead("Content-Length: 100\r\n\r\n"), |
| 6345 | MockRead(SYNCHRONOUS, OK), |
| 6346 | }; |
| 6347 | |
| 6348 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6349 | data_writes1, arraysize(data_writes1)); |
| 6350 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 6351 | data_writes3, arraysize(data_writes3)); |
| 6352 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6353 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 6354 | |
| 6355 | TestCompletionCallback callback1; |
| 6356 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
| 6357 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6358 | rv = callback1.WaitForResult(); |
| 6359 | EXPECT_EQ(OK, rv); |
| 6360 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 6361 | |
| 6362 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6363 | ASSERT_TRUE(response != NULL); |
| 6364 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 6365 | |
| 6366 | TestCompletionCallback callback3; |
| 6367 | rv = trans->RestartWithAuth( |
| 6368 | AuthCredentials(kFoo, kBar), callback3.callback()); |
| 6369 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6370 | rv = callback3.WaitForResult(); |
| 6371 | EXPECT_EQ(OK, rv); |
| 6372 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 6373 | |
| 6374 | response = trans->GetResponseInfo(); |
| 6375 | ASSERT_TRUE(response != NULL); |
| 6376 | |
| 6377 | // There is no challenge info, since the identity worked. |
| 6378 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6379 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6380 | |
| 6381 | // Empty the current queue. |
| 6382 | base::MessageLoop::current()->RunUntilIdle(); |
| 6383 | } |
| 6384 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6385 | // Test that previously tried username/passwords for a realm get re-used. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6386 | TEST_P(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) { |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 6387 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6388 | |
| 6389 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 6390 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6391 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6392 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6393 | request.url = GURL("http://www.example.org/x/y/z"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6394 | request.load_flags = 0; |
| 6395 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6396 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6397 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6398 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6399 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6400 | MockWrite( |
| 6401 | "GET /x/y/z HTTP/1.1\r\n" |
| 6402 | "Host: www.example.org\r\n" |
| 6403 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6404 | }; |
| 6405 | |
| 6406 | MockRead data_reads1[] = { |
| 6407 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6408 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6409 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6410 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6411 | }; |
| 6412 | |
| 6413 | // Resend with authorization (username=foo, password=bar) |
| 6414 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6415 | MockWrite( |
| 6416 | "GET /x/y/z HTTP/1.1\r\n" |
| 6417 | "Host: www.example.org\r\n" |
| 6418 | "Connection: keep-alive\r\n" |
| 6419 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6420 | }; |
| 6421 | |
| 6422 | // Sever accepts the authorization. |
| 6423 | MockRead data_reads2[] = { |
| 6424 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6425 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6426 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6427 | }; |
| 6428 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6429 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6430 | data_writes1, arraysize(data_writes1)); |
| 6431 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6432 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6433 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6434 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6435 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6436 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6437 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6438 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6439 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6440 | |
| 6441 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6442 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6443 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6444 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6445 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6446 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6447 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6448 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6449 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6450 | rv = trans->RestartWithAuth( |
| 6451 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6452 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6453 | |
| 6454 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6455 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6456 | |
| 6457 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6458 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6459 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6460 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6461 | } |
| 6462 | |
| 6463 | // ------------------------------------------------------------------------ |
| 6464 | |
| 6465 | // Transaction 2: authenticate (foo2, bar2) on MyRealm2 |
| 6466 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6467 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6468 | request.method = "GET"; |
| 6469 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 6470 | // protection space as MyRealm1. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6471 | request.url = GURL("http://www.example.org/x/y/a/b"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6472 | request.load_flags = 0; |
| 6473 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6474 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6475 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6476 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6477 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6478 | MockWrite( |
| 6479 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 6480 | "Host: www.example.org\r\n" |
| 6481 | "Connection: keep-alive\r\n" |
| 6482 | // Send preemptive authorization for MyRealm1 |
| 6483 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6484 | }; |
| 6485 | |
| 6486 | // The server didn't like the preemptive authorization, and |
| 6487 | // challenges us for a different realm (MyRealm2). |
| 6488 | MockRead data_reads1[] = { |
| 6489 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6490 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm2\"\r\n"), |
| 6491 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6492 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6493 | }; |
| 6494 | |
| 6495 | // Resend with authorization for MyRealm2 (username=foo2, password=bar2) |
| 6496 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6497 | MockWrite( |
| 6498 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 6499 | "Host: www.example.org\r\n" |
| 6500 | "Connection: keep-alive\r\n" |
| 6501 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6502 | }; |
| 6503 | |
| 6504 | // Sever accepts the authorization. |
| 6505 | MockRead data_reads2[] = { |
| 6506 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6507 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6508 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6509 | }; |
| 6510 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6511 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6512 | data_writes1, arraysize(data_writes1)); |
| 6513 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6514 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6515 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6516 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6517 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6518 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6519 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6520 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6521 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6522 | |
| 6523 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6524 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6525 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6526 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6527 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6528 | ASSERT_TRUE(response->auth_challenge.get()); |
| 6529 | EXPECT_FALSE(response->auth_challenge->is_proxy); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6530 | EXPECT_EQ("www.example.org:80", |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6531 | response->auth_challenge->challenger.ToString()); |
| 6532 | EXPECT_EQ("MyRealm2", response->auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame^] | 6533 | EXPECT_EQ(kBasicAuthScheme, response->auth_challenge->scheme); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6534 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6535 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6536 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6537 | rv = trans->RestartWithAuth( |
| 6538 | AuthCredentials(kFoo2, kBar2), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6539 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6540 | |
| 6541 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6542 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6543 | |
| 6544 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6545 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6546 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6547 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6548 | } |
| 6549 | |
| 6550 | // ------------------------------------------------------------------------ |
| 6551 | |
| 6552 | // Transaction 3: Resend a request in MyRealm's protection space -- |
| 6553 | // succeed with preemptive authorization. |
| 6554 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6555 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6556 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6557 | request.url = GURL("http://www.example.org/x/y/z2"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6558 | request.load_flags = 0; |
| 6559 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6560 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6561 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6562 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6563 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6564 | MockWrite( |
| 6565 | "GET /x/y/z2 HTTP/1.1\r\n" |
| 6566 | "Host: www.example.org\r\n" |
| 6567 | "Connection: keep-alive\r\n" |
| 6568 | // The authorization for MyRealm1 gets sent preemptively |
| 6569 | // (since the url is in the same protection space) |
| 6570 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6571 | }; |
| 6572 | |
| 6573 | // Sever accepts the preemptive authorization |
| 6574 | MockRead data_reads1[] = { |
| 6575 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6576 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6577 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6578 | }; |
| 6579 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6580 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6581 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6582 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6583 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6584 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6585 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6586 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6587 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6588 | |
| 6589 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6590 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6591 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6592 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6593 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6594 | |
| 6595 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6596 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6597 | } |
| 6598 | |
| 6599 | // ------------------------------------------------------------------------ |
| 6600 | |
| 6601 | // Transaction 4: request another URL in MyRealm (however the |
| 6602 | // url is not known to belong to the protection space, so no pre-auth). |
| 6603 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6604 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6605 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6606 | request.url = GURL("http://www.example.org/x/1"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6607 | request.load_flags = 0; |
| 6608 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6609 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6610 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6611 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6612 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6613 | MockWrite( |
| 6614 | "GET /x/1 HTTP/1.1\r\n" |
| 6615 | "Host: www.example.org\r\n" |
| 6616 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6617 | }; |
| 6618 | |
| 6619 | MockRead data_reads1[] = { |
| 6620 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6621 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6622 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6623 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6624 | }; |
| 6625 | |
| 6626 | // Resend with authorization from MyRealm's cache. |
| 6627 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6628 | MockWrite( |
| 6629 | "GET /x/1 HTTP/1.1\r\n" |
| 6630 | "Host: www.example.org\r\n" |
| 6631 | "Connection: keep-alive\r\n" |
| 6632 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6633 | }; |
| 6634 | |
| 6635 | // Sever accepts the authorization. |
| 6636 | MockRead data_reads2[] = { |
| 6637 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6638 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6639 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6640 | }; |
| 6641 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6642 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6643 | data_writes1, arraysize(data_writes1)); |
| 6644 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6645 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6646 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6647 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6648 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6649 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6650 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6651 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6652 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6653 | |
| 6654 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6655 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6656 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6657 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6658 | TestCompletionCallback callback2; |
| 6659 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6660 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6661 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6662 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6663 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 6664 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6665 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6666 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6667 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6668 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6669 | } |
| 6670 | |
| 6671 | // ------------------------------------------------------------------------ |
| 6672 | |
| 6673 | // Transaction 5: request a URL in MyRealm, but the server rejects the |
| 6674 | // cached identity. Should invalidate and re-prompt. |
| 6675 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6676 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6677 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6678 | request.url = GURL("http://www.example.org/p/q/t"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6679 | request.load_flags = 0; |
| 6680 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6681 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6682 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6683 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6684 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6685 | MockWrite( |
| 6686 | "GET /p/q/t HTTP/1.1\r\n" |
| 6687 | "Host: www.example.org\r\n" |
| 6688 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6689 | }; |
| 6690 | |
| 6691 | MockRead data_reads1[] = { |
| 6692 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6693 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6694 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6695 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6696 | }; |
| 6697 | |
| 6698 | // Resend with authorization from cache for MyRealm. |
| 6699 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6700 | MockWrite( |
| 6701 | "GET /p/q/t HTTP/1.1\r\n" |
| 6702 | "Host: www.example.org\r\n" |
| 6703 | "Connection: keep-alive\r\n" |
| 6704 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6705 | }; |
| 6706 | |
| 6707 | // Sever rejects the authorization. |
| 6708 | MockRead data_reads2[] = { |
| 6709 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6710 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6711 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6712 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6713 | }; |
| 6714 | |
| 6715 | // At this point we should prompt for new credentials for MyRealm. |
| 6716 | // Restart with username=foo3, password=foo4. |
| 6717 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6718 | MockWrite( |
| 6719 | "GET /p/q/t HTTP/1.1\r\n" |
| 6720 | "Host: www.example.org\r\n" |
| 6721 | "Connection: keep-alive\r\n" |
| 6722 | "Authorization: Basic Zm9vMzpiYXIz\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6723 | }; |
| 6724 | |
| 6725 | // Sever accepts the authorization. |
| 6726 | MockRead data_reads3[] = { |
| 6727 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6728 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6729 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6730 | }; |
| 6731 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6732 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6733 | data_writes1, arraysize(data_writes1)); |
| 6734 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6735 | data_writes2, arraysize(data_writes2)); |
| 6736 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 6737 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6738 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6739 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 6740 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6741 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6742 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6743 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6744 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6745 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6746 | |
| 6747 | rv = callback1.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6748 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6749 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6750 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6751 | TestCompletionCallback callback2; |
| 6752 | rv = trans->RestartWithAuth(AuthCredentials(), callback2.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6753 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6754 | rv = callback2.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6755 | EXPECT_EQ(OK, rv); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6756 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 6757 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6758 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6759 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6760 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6761 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6762 | TestCompletionCallback callback3; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6763 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6764 | rv = trans->RestartWithAuth( |
| 6765 | AuthCredentials(kFoo3, kBar3), callback3.callback()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6766 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6767 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6768 | rv = callback3.WaitForResult(); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6769 | EXPECT_EQ(OK, rv); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6770 | |
| 6771 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6772 | ASSERT_TRUE(response != NULL); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6773 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6774 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6775 | } |
| 6776 | } |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6777 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6778 | // Tests that nonce count increments when multiple auth attempts |
| 6779 | // are started with the same nonce. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6780 | TEST_P(HttpNetworkTransactionTest, DigestPreAuthNonceCount) { |
[email protected] | 54fea256 | 2010-11-17 14:40:44 | [diff] [blame] | 6781 | HttpAuthHandlerDigest::Factory* digest_factory = |
| 6782 | new HttpAuthHandlerDigest::Factory(); |
| 6783 | HttpAuthHandlerDigest::FixedNonceGenerator* nonce_generator = |
| 6784 | new HttpAuthHandlerDigest::FixedNonceGenerator("0123456789abcdef"); |
| 6785 | digest_factory->set_nonce_generator(nonce_generator); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6786 | session_deps_.http_auth_handler_factory.reset(digest_factory); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 6787 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6788 | |
| 6789 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 6790 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6791 | HttpRequestInfo request; |
| 6792 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6793 | request.url = GURL("http://www.example.org/x/y/z"); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6794 | request.load_flags = 0; |
| 6795 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6796 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6797 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6798 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6799 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6800 | MockWrite( |
| 6801 | "GET /x/y/z HTTP/1.1\r\n" |
| 6802 | "Host: www.example.org\r\n" |
| 6803 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6804 | }; |
| 6805 | |
| 6806 | MockRead data_reads1[] = { |
| 6807 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6808 | MockRead("WWW-Authenticate: Digest realm=\"digestive\", nonce=\"OU812\", " |
| 6809 | "algorithm=MD5, qop=\"auth\"\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6810 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6811 | }; |
| 6812 | |
| 6813 | // Resend with authorization (username=foo, password=bar) |
| 6814 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6815 | MockWrite( |
| 6816 | "GET /x/y/z HTTP/1.1\r\n" |
| 6817 | "Host: www.example.org\r\n" |
| 6818 | "Connection: keep-alive\r\n" |
| 6819 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 6820 | "nonce=\"OU812\", uri=\"/x/y/z\", algorithm=MD5, " |
| 6821 | "response=\"03ffbcd30add722589c1de345d7a927f\", qop=auth, " |
| 6822 | "nc=00000001, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6823 | }; |
| 6824 | |
| 6825 | // Sever accepts the authorization. |
| 6826 | MockRead data_reads2[] = { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 6827 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6828 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6829 | }; |
| 6830 | |
| 6831 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6832 | data_writes1, arraysize(data_writes1)); |
| 6833 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6834 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6835 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6836 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6837 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6838 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6839 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6840 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6841 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6842 | |
| 6843 | rv = callback1.WaitForResult(); |
| 6844 | EXPECT_EQ(OK, rv); |
| 6845 | |
| 6846 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6847 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6848 | EXPECT_TRUE(CheckDigestServerAuth(response->auth_challenge.get())); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6849 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6850 | TestCompletionCallback callback2; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6851 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6852 | rv = trans->RestartWithAuth( |
| 6853 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6854 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6855 | |
| 6856 | rv = callback2.WaitForResult(); |
| 6857 | EXPECT_EQ(OK, rv); |
| 6858 | |
| 6859 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6860 | ASSERT_TRUE(response != NULL); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6861 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6862 | } |
| 6863 | |
| 6864 | // ------------------------------------------------------------------------ |
| 6865 | |
| 6866 | // Transaction 2: Request another resource in digestive's protection space. |
| 6867 | // This will preemptively add an Authorization header which should have an |
| 6868 | // "nc" value of 2 (as compared to 1 in the first use. |
| 6869 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6870 | HttpRequestInfo request; |
| 6871 | request.method = "GET"; |
| 6872 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 6873 | // protection space as digest. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6874 | request.url = GURL("http://www.example.org/x/y/a/b"); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6875 | request.load_flags = 0; |
| 6876 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 6877 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6878 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6879 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6880 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6881 | MockWrite( |
| 6882 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 6883 | "Host: www.example.org\r\n" |
| 6884 | "Connection: keep-alive\r\n" |
| 6885 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 6886 | "nonce=\"OU812\", uri=\"/x/y/a/b\", algorithm=MD5, " |
| 6887 | "response=\"d6f9a2c07d1c5df7b89379dca1269b35\", qop=auth, " |
| 6888 | "nc=00000002, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6889 | }; |
| 6890 | |
| 6891 | // Sever accepts the authorization. |
| 6892 | MockRead data_reads1[] = { |
| 6893 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6894 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6895 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6896 | }; |
| 6897 | |
| 6898 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6899 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6900 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6901 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6902 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6903 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6904 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6905 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6906 | |
| 6907 | rv = callback1.WaitForResult(); |
| 6908 | EXPECT_EQ(OK, rv); |
| 6909 | |
| 6910 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 6911 | ASSERT_TRUE(response != NULL); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 6912 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6913 | } |
| 6914 | } |
| 6915 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6916 | // Test the ResetStateForRestart() private method. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6917 | TEST_P(HttpNetworkTransactionTest, ResetStateForRestart) { |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6918 | // Create a transaction (the dependencies aren't important). |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 6919 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 6920 | scoped_ptr<HttpNetworkTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6921 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6922 | |
| 6923 | // Setup some state (which we expect ResetStateForRestart() will clear). |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6924 | trans->read_buf_ = new IOBuffer(15); |
| 6925 | trans->read_buf_len_ = 15; |
[email protected] | b94f92d | 2010-10-27 16:45:20 | [diff] [blame] | 6926 | trans->request_headers_.SetHeader("Authorization", "NTLM"); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6927 | |
| 6928 | // Setup state in response_ |
[email protected] | a7e4131 | 2009-12-16 23:18:14 | [diff] [blame] | 6929 | HttpResponseInfo* response = &trans->response_; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 6930 | response->auth_challenge = new AuthChallengeInfo(); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 6931 | response->ssl_info.cert_status = static_cast<CertStatus>(-1); // Nonsensical. |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 6932 | response->response_time = base::Time::Now(); |
| 6933 | response->was_cached = true; // (Wouldn't ever actually be true...) |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6934 | |
| 6935 | { // Setup state for response_.vary_data |
| 6936 | HttpRequestInfo request; |
| 6937 | std::string temp("HTTP/1.1 200 OK\nVary: foo, bar\n\n"); |
| 6938 | std::replace(temp.begin(), temp.end(), '\n', '\0'); |
[email protected] | ad8e04a | 2010-11-01 04:16:27 | [diff] [blame] | 6939 | scoped_refptr<HttpResponseHeaders> headers(new HttpResponseHeaders(temp)); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 6940 | request.extra_headers.SetHeader("Foo", "1"); |
| 6941 | request.extra_headers.SetHeader("bar", "23"); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6942 | EXPECT_TRUE(response->vary_data.Init(request, *headers.get())); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6943 | } |
| 6944 | |
| 6945 | // Cause the above state to be reset. |
| 6946 | trans->ResetStateForRestart(); |
| 6947 | |
| 6948 | // Verify that the state that needed to be reset, has been reset. |
[email protected] | 9b6fee1 | 2009-09-29 18:13:07 | [diff] [blame] | 6949 | EXPECT_TRUE(trans->read_buf_.get() == NULL); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6950 | EXPECT_EQ(0, trans->read_buf_len_); |
[email protected] | b94f92d | 2010-10-27 16:45:20 | [diff] [blame] | 6951 | EXPECT_TRUE(trans->request_headers_.IsEmpty()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 6952 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 6953 | EXPECT_TRUE(response->headers.get() == NULL); |
[email protected] | 34f4094 | 2010-10-04 00:34:04 | [diff] [blame] | 6954 | EXPECT_FALSE(response->was_cached); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 6955 | EXPECT_EQ(0U, response->ssl_info.cert_status); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 6956 | EXPECT_FALSE(response->vary_data.is_valid()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 6957 | } |
| 6958 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6959 | // Test HTTPS connections to a site with a bad certificate |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6960 | TEST_P(HttpNetworkTransactionTest, HTTPSBadCertificate) { |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6961 | HttpRequestInfo request; |
| 6962 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6963 | request.url = GURL("https://www.example.org/"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6964 | request.load_flags = 0; |
| 6965 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 6966 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6967 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 6968 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6969 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6970 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6971 | MockWrite( |
| 6972 | "GET / HTTP/1.1\r\n" |
| 6973 | "Host: www.example.org\r\n" |
| 6974 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6975 | }; |
| 6976 | |
| 6977 | MockRead data_reads[] = { |
| 6978 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6979 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6980 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6981 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6982 | }; |
| 6983 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 6984 | StaticSocketDataProvider ssl_bad_certificate; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6985 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6986 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6987 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 6988 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6989 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6990 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 6991 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6992 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 6993 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6994 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6995 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6996 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6997 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 6998 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6999 | |
| 7000 | rv = callback.WaitForResult(); |
| 7001 | EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, rv); |
| 7002 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7003 | rv = trans->RestartIgnoringLastError(callback.callback()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7004 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7005 | |
| 7006 | rv = callback.WaitForResult(); |
| 7007 | EXPECT_EQ(OK, rv); |
| 7008 | |
| 7009 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7010 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7011 | ASSERT_TRUE(response != NULL); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7012 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7013 | } |
| 7014 | |
| 7015 | // Test HTTPS connections to a site with a bad certificate, going through a |
| 7016 | // proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7017 | TEST_P(HttpNetworkTransactionTest, HTTPSBadCertificateViaProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7018 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7019 | |
| 7020 | HttpRequestInfo request; |
| 7021 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7022 | request.url = GURL("https://www.example.org/"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7023 | request.load_flags = 0; |
| 7024 | |
| 7025 | MockWrite proxy_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7026 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7027 | "Host: www.example.org:443\r\n" |
| 7028 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7029 | }; |
| 7030 | |
| 7031 | MockRead proxy_reads[] = { |
| 7032 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7033 | MockRead(SYNCHRONOUS, OK) |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7034 | }; |
| 7035 | |
| 7036 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7037 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7038 | "Host: www.example.org:443\r\n" |
| 7039 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 7040 | MockWrite("GET / HTTP/1.1\r\n" |
| 7041 | "Host: www.example.org\r\n" |
| 7042 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7043 | }; |
| 7044 | |
| 7045 | MockRead data_reads[] = { |
| 7046 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 7047 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7048 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7049 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7050 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7051 | }; |
| 7052 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7053 | StaticSocketDataProvider ssl_bad_certificate( |
| 7054 | proxy_reads, arraysize(proxy_reads), |
| 7055 | proxy_writes, arraysize(proxy_writes)); |
| 7056 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7057 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7058 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 7059 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7060 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7061 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 7062 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7063 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 7064 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7065 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7066 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7067 | |
| 7068 | for (int i = 0; i < 2; i++) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7069 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7070 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7071 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 7072 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7073 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7074 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7075 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7076 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7077 | |
| 7078 | rv = callback.WaitForResult(); |
| 7079 | EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, rv); |
| 7080 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7081 | rv = trans->RestartIgnoringLastError(callback.callback()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7082 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7083 | |
| 7084 | rv = callback.WaitForResult(); |
| 7085 | EXPECT_EQ(OK, rv); |
| 7086 | |
| 7087 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7088 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7089 | ASSERT_TRUE(response != NULL); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7090 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7091 | } |
| 7092 | } |
| 7093 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7094 | |
| 7095 | // Test HTTPS connections to a site, going through an HTTPS proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7096 | TEST_P(HttpNetworkTransactionTest, HTTPSViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7097 | session_deps_.proxy_service = |
| 7098 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7099 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7100 | session_deps_.net_log = &net_log; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7101 | |
| 7102 | HttpRequestInfo request; |
| 7103 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7104 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7105 | request.load_flags = 0; |
| 7106 | |
| 7107 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7108 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7109 | "Host: www.example.org:443\r\n" |
| 7110 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 7111 | MockWrite("GET / HTTP/1.1\r\n" |
| 7112 | "Host: www.example.org\r\n" |
| 7113 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7114 | }; |
| 7115 | |
| 7116 | MockRead data_reads[] = { |
| 7117 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 7118 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 7119 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7120 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7121 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7122 | }; |
| 7123 | |
| 7124 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7125 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7126 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
| 7127 | SSLSocketDataProvider tunnel_ssl(ASYNC, OK); // SSL through the tunnel |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7128 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7129 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7130 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
| 7131 | session_deps_.socket_factory->AddSSLSocketDataProvider(&tunnel_ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7132 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7133 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7134 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7135 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7136 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7137 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7138 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7139 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7140 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7141 | |
| 7142 | rv = callback.WaitForResult(); |
| 7143 | EXPECT_EQ(OK, rv); |
| 7144 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7145 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7146 | ASSERT_TRUE(response != NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7147 | |
| 7148 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 7149 | EXPECT_EQ(200, response->headers->response_code()); |
| 7150 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7151 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7152 | |
| 7153 | LoadTimingInfo load_timing_info; |
| 7154 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7155 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 7156 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7157 | } |
| 7158 | |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7159 | // Test an HTTPS Proxy's ability to redirect a CONNECT request |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7160 | TEST_P(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7161 | session_deps_.proxy_service = |
| 7162 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7163 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7164 | session_deps_.net_log = &net_log; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7165 | |
| 7166 | HttpRequestInfo request; |
| 7167 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7168 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7169 | request.load_flags = 0; |
| 7170 | |
| 7171 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7172 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7173 | "Host: www.example.org:443\r\n" |
| 7174 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7175 | }; |
| 7176 | |
| 7177 | MockRead data_reads[] = { |
| 7178 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 7179 | MockRead("Location: http://login.example.com/\r\n"), |
| 7180 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7181 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7182 | }; |
| 7183 | |
| 7184 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7185 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7186 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7187 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7188 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7189 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7190 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7191 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7192 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7193 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7194 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7195 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7196 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7197 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7198 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7199 | |
| 7200 | rv = callback.WaitForResult(); |
| 7201 | EXPECT_EQ(OK, rv); |
| 7202 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7203 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7204 | ASSERT_TRUE(response != NULL); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7205 | |
| 7206 | EXPECT_EQ(302, response->headers->response_code()); |
| 7207 | std::string url; |
| 7208 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 7209 | EXPECT_EQ("http://login.example.com/", url); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7210 | |
| 7211 | // In the case of redirects from proxies, HttpNetworkTransaction returns |
| 7212 | // timing for the proxy connection instead of the connection to the host, |
| 7213 | // and no send / receive times. |
| 7214 | // See HttpNetworkTransaction::OnHttpsProxyTunnelResponse. |
| 7215 | LoadTimingInfo load_timing_info; |
| 7216 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7217 | |
| 7218 | EXPECT_FALSE(load_timing_info.socket_reused); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 7219 | EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7220 | |
| 7221 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 7222 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 7223 | load_timing_info.proxy_resolve_end); |
| 7224 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 7225 | load_timing_info.connect_timing.connect_start); |
| 7226 | ExpectConnectTimingHasTimes( |
| 7227 | load_timing_info.connect_timing, |
| 7228 | CONNECT_TIMING_HAS_DNS_TIMES | CONNECT_TIMING_HAS_SSL_TIMES); |
| 7229 | |
| 7230 | EXPECT_TRUE(load_timing_info.send_start.is_null()); |
| 7231 | EXPECT_TRUE(load_timing_info.send_end.is_null()); |
| 7232 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7233 | } |
| 7234 | |
| 7235 | // Test an HTTPS (SPDY) Proxy's ability to redirect a CONNECT request |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7236 | TEST_P(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaSpdyProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7237 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7238 | |
| 7239 | HttpRequestInfo request; |
| 7240 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7241 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7242 | request.load_flags = 0; |
| 7243 | |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 7244 | scoped_ptr<SpdyFrame> conn(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7245 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 7246 | scoped_ptr<SpdyFrame> goaway( |
| 7247 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7248 | MockWrite data_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7249 | CreateMockWrite(*conn.get(), 0, SYNCHRONOUS), |
| 7250 | CreateMockWrite(*goaway.get(), 2, SYNCHRONOUS), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7251 | }; |
| 7252 | |
| 7253 | static const char* const kExtraHeaders[] = { |
| 7254 | "location", |
| 7255 | "http://login.example.com/", |
| 7256 | }; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 7257 | scoped_ptr<SpdyFrame> resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7258 | spdy_util_.ConstructSpdySynReplyError("302 Redirect", kExtraHeaders, |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7259 | arraysize(kExtraHeaders)/2, 1)); |
| 7260 | MockRead data_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7261 | CreateMockRead(*resp.get(), 1), MockRead(ASYNC, 0, 3), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7262 | }; |
| 7263 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7264 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 7265 | arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7266 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 7267 | proxy_ssl.SetNextProto(GetProtocol()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7268 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7269 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7270 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7271 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7272 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7273 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7274 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7275 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7276 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7277 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7278 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7279 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7280 | |
| 7281 | rv = callback.WaitForResult(); |
| 7282 | EXPECT_EQ(OK, rv); |
| 7283 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7284 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7285 | ASSERT_TRUE(response != NULL); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7286 | |
| 7287 | EXPECT_EQ(302, response->headers->response_code()); |
| 7288 | std::string url; |
| 7289 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 7290 | EXPECT_EQ("http://login.example.com/", url); |
| 7291 | } |
| 7292 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 7293 | // Test that an HTTPS proxy's response to a CONNECT request is filtered. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7294 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 7295 | ErrorResponseToHttpsConnectViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7296 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7297 | |
| 7298 | HttpRequestInfo request; |
| 7299 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7300 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7301 | request.load_flags = 0; |
| 7302 | |
| 7303 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7304 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7305 | "Host: www.example.org:443\r\n" |
| 7306 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7307 | }; |
| 7308 | |
| 7309 | MockRead data_reads[] = { |
| 7310 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 7311 | MockRead("Content-Length: 23\r\n\r\n"), |
| 7312 | MockRead("The host does not exist"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7313 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7314 | }; |
| 7315 | |
| 7316 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7317 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7318 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7319 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7320 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7321 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7322 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7323 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7324 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7325 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7326 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7327 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7328 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7329 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7330 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7331 | |
| 7332 | rv = callback.WaitForResult(); |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 7333 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7334 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 7335 | // TODO(ttuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7336 | } |
| 7337 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 7338 | // Test that a SPDY proxy's response to a CONNECT request is filtered. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7339 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 7340 | ErrorResponseToHttpsConnectViaSpdyProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7341 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7342 | |
| 7343 | HttpRequestInfo request; |
| 7344 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7345 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7346 | request.load_flags = 0; |
| 7347 | |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 7348 | scoped_ptr<SpdyFrame> conn(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7349 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 7350 | scoped_ptr<SpdyFrame> rst( |
| 7351 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7352 | MockWrite data_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7353 | CreateMockWrite(*conn.get(), 0), CreateMockWrite(*rst.get(), 3), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7354 | }; |
| 7355 | |
| 7356 | static const char* const kExtraHeaders[] = { |
| 7357 | "location", |
| 7358 | "http://login.example.com/", |
| 7359 | }; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 7360 | scoped_ptr<SpdyFrame> resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7361 | spdy_util_.ConstructSpdySynReplyError("404 Not Found", kExtraHeaders, |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7362 | arraysize(kExtraHeaders)/2, 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 7363 | scoped_ptr<SpdyFrame> body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7364 | spdy_util_.ConstructSpdyBodyFrame( |
| 7365 | 1, "The host does not exist", 23, true)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7366 | MockRead data_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7367 | CreateMockRead(*resp.get(), 1), |
| 7368 | CreateMockRead(*body.get(), 2), |
| 7369 | MockRead(ASYNC, 0, 4), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7370 | }; |
| 7371 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7372 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 7373 | arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7374 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 7375 | proxy_ssl.SetNextProto(GetProtocol()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7376 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7377 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7378 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7379 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7380 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7381 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7382 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7383 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7384 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7385 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7386 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7387 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7388 | |
| 7389 | rv = callback.WaitForResult(); |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 7390 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7391 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 7392 | // TODO(ttuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7393 | } |
| 7394 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7395 | // Test the request-challenge-retry sequence for basic auth, through |
| 7396 | // a SPDY proxy over a single SPDY session. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7397 | TEST_P(HttpNetworkTransactionTest, BasicAuthSpdyProxy) { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7398 | HttpRequestInfo request; |
| 7399 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7400 | request.url = GURL("https://www.example.org/"); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7401 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 7402 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7403 | |
| 7404 | // Configure against https proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7405 | session_deps_.proxy_service = |
| 7406 | ProxyService::CreateFixedFromPacResult("HTTPS myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7407 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7408 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7409 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7410 | |
| 7411 | // Since we have proxy, should try to establish tunnel. |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 7412 | scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7413 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 7414 | scoped_ptr<SpdyFrame> rst( |
| 7415 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 7416 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7417 | |
| 7418 | // After calling trans->RestartWithAuth(), this is the request we should |
| 7419 | // be issuing -- the final header line contains the credentials. |
| 7420 | const char* const kAuthCredentials[] = { |
| 7421 | "proxy-authorization", "Basic Zm9vOmJhcg==", |
| 7422 | }; |
[email protected] | fba2dbde | 2013-05-24 16:09:01 | [diff] [blame] | 7423 | scoped_ptr<SpdyFrame> connect2(spdy_util_.ConstructSpdyConnect( |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 7424 | kAuthCredentials, arraysize(kAuthCredentials) / 2, 3, LOWEST, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7425 | HostPortPair("www.example.org", 443))); |
| 7426 | // fetch https://www.example.org/ via HTTP |
| 7427 | const char get[] = |
| 7428 | "GET / HTTP/1.1\r\n" |
| 7429 | "Host: www.example.org\r\n" |
| 7430 | "Connection: keep-alive\r\n\r\n"; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 7431 | scoped_ptr<SpdyFrame> wrapped_get( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7432 | spdy_util_.ConstructSpdyBodyFrame(3, get, strlen(get), false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7433 | |
| 7434 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7435 | CreateMockWrite(*req, 0, ASYNC), |
| 7436 | CreateMockWrite(*rst, 2, ASYNC), |
| 7437 | CreateMockWrite(*connect2, 3), |
| 7438 | CreateMockWrite(*wrapped_get, 5), |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7439 | }; |
| 7440 | |
| 7441 | // The proxy responds to the connect with a 407, using a persistent |
| 7442 | // connection. |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 7443 | const char kAuthStatus[] = "407"; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7444 | const char* const kAuthChallenge[] = { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7445 | "proxy-authenticate", "Basic realm=\"MyRealm1\"", |
| 7446 | }; |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 7447 | scoped_ptr<SpdyFrame> conn_auth_resp(spdy_util_.ConstructSpdySynReplyError( |
| 7448 | kAuthStatus, kAuthChallenge, arraysize(kAuthChallenge) / 2, 1)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7449 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7450 | scoped_ptr<SpdyFrame> conn_resp( |
| 7451 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7452 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 7453 | "Content-Length: 5\r\n\r\n"; |
| 7454 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 7455 | scoped_ptr<SpdyFrame> wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7456 | spdy_util_.ConstructSpdyBodyFrame(3, resp, strlen(resp), false)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 7457 | scoped_ptr<SpdyFrame> wrapped_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7458 | spdy_util_.ConstructSpdyBodyFrame(3, "hello", 5, false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7459 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7460 | CreateMockRead(*conn_auth_resp, 1, ASYNC), |
| 7461 | CreateMockRead(*conn_resp, 4, ASYNC), |
| 7462 | CreateMockRead(*wrapped_get_resp, 6, ASYNC), |
| 7463 | CreateMockRead(*wrapped_body, 7, ASYNC), |
| 7464 | MockRead(ASYNC, OK, 8), // EOF. May or may not be read. |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7465 | }; |
| 7466 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7467 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 7468 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7469 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7470 | // Negotiate SPDY to the proxy |
| 7471 | SSLSocketDataProvider proxy(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 7472 | proxy.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7473 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7474 | // Vanilla SSL to the server |
| 7475 | SSLSocketDataProvider server(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7476 | session_deps_.socket_factory->AddSSLSocketDataProvider(&server); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7477 | |
| 7478 | TestCompletionCallback callback1; |
| 7479 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7480 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7481 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7482 | |
| 7483 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 7484 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7485 | |
| 7486 | rv = callback1.WaitForResult(); |
| 7487 | EXPECT_EQ(OK, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 7488 | TestNetLogEntry::List entries; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7489 | log.GetEntries(&entries); |
| 7490 | size_t pos = ExpectLogContainsSomewhere( |
| 7491 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 7492 | NetLog::PHASE_NONE); |
| 7493 | ExpectLogContainsSomewhere( |
| 7494 | entries, pos, |
| 7495 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 7496 | NetLog::PHASE_NONE); |
| 7497 | |
| 7498 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7499 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7500 | ASSERT_FALSE(response->headers.get() == NULL); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7501 | EXPECT_EQ(407, response->headers->response_code()); |
| 7502 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 7503 | EXPECT_TRUE(response->auth_challenge.get() != NULL); |
| 7504 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 7505 | |
| 7506 | TestCompletionCallback callback2; |
| 7507 | |
| 7508 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 7509 | callback2.callback()); |
| 7510 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7511 | |
| 7512 | rv = callback2.WaitForResult(); |
| 7513 | EXPECT_EQ(OK, rv); |
| 7514 | |
| 7515 | response = trans->GetResponseInfo(); |
| 7516 | ASSERT_TRUE(response != NULL); |
| 7517 | |
| 7518 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 7519 | EXPECT_EQ(200, response->headers->response_code()); |
| 7520 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 7521 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 7522 | |
| 7523 | // The password prompt info should not be set. |
| 7524 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 7525 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7526 | LoadTimingInfo load_timing_info; |
| 7527 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7528 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 7529 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 7530 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 7531 | trans.reset(); |
| 7532 | session->CloseAllConnections(); |
| 7533 | } |
| 7534 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7535 | // Test that an explicitly trusted SPDY proxy can push a resource from an |
| 7536 | // origin that is different from that of its associated resource. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7537 | TEST_P(HttpNetworkTransactionTest, CrossOriginProxyPush) { |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7538 | HttpRequestInfo request; |
| 7539 | HttpRequestInfo push_request; |
| 7540 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7541 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7542 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7543 | push_request.method = "GET"; |
| 7544 | push_request.url = GURL("http://www.another-origin.com/foo.dat"); |
| 7545 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7546 | // Configure against https proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7547 | session_deps_.proxy_service = |
| 7548 | ProxyService::CreateFixedFromPacResult("HTTPS myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7549 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7550 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 7551 | |
| 7552 | // Enable cross-origin push. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7553 | session_deps_.trusted_spdy_proxy = "myproxy:70"; |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 7554 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7555 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7556 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 7557 | scoped_ptr<SpdyFrame> stream1_syn( |
| 7558 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7559 | |
| 7560 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7561 | CreateMockWrite(*stream1_syn, 0, ASYNC), |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7562 | }; |
| 7563 | |
| 7564 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7565 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7566 | |
| 7567 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7568 | stream1_body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7569 | |
| 7570 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7571 | stream2_syn(spdy_util_.ConstructSpdyPush(NULL, |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7572 | 0, |
| 7573 | 2, |
| 7574 | 1, |
| 7575 | "http://www.another-origin.com/foo.dat")); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 7576 | const char kPushedData[] = "pushed"; |
| 7577 | scoped_ptr<SpdyFrame> stream2_body( |
| 7578 | spdy_util_.ConstructSpdyBodyFrame( |
| 7579 | 2, kPushedData, strlen(kPushedData), true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7580 | |
| 7581 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7582 | CreateMockRead(*stream1_reply, 1, ASYNC), |
| 7583 | CreateMockRead(*stream2_syn, 2, ASYNC), |
| 7584 | CreateMockRead(*stream1_body, 3, ASYNC), |
| 7585 | CreateMockRead(*stream2_body, 4, ASYNC), |
| 7586 | MockRead(ASYNC, ERR_IO_PENDING, 5), // Force a pause |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7587 | }; |
| 7588 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7589 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 7590 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7591 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7592 | // Negotiate SPDY to the proxy |
| 7593 | SSLSocketDataProvider proxy(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 7594 | proxy.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7595 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7596 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7597 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7598 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7599 | TestCompletionCallback callback; |
| 7600 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
| 7601 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7602 | |
| 7603 | rv = callback.WaitForResult(); |
| 7604 | EXPECT_EQ(OK, rv); |
| 7605 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7606 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7607 | scoped_ptr<HttpTransaction> push_trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7608 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 7609 | rv = push_trans->Start(&push_request, callback.callback(), log.bound()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7610 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7611 | |
| 7612 | rv = callback.WaitForResult(); |
| 7613 | EXPECT_EQ(OK, rv); |
| 7614 | const HttpResponseInfo* push_response = push_trans->GetResponseInfo(); |
| 7615 | |
| 7616 | ASSERT_TRUE(response != NULL); |
| 7617 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 7618 | |
| 7619 | EXPECT_EQ(200, response->headers->response_code()); |
| 7620 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 7621 | |
| 7622 | std::string response_data; |
| 7623 | rv = ReadTransaction(trans.get(), &response_data); |
| 7624 | EXPECT_EQ(OK, rv); |
| 7625 | EXPECT_EQ("hello!", response_data); |
| 7626 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7627 | LoadTimingInfo load_timing_info; |
| 7628 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 7629 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 7630 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 7631 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7632 | // Verify the pushed stream. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7633 | EXPECT_TRUE(push_response->headers.get() != NULL); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7634 | EXPECT_EQ(200, push_response->headers->response_code()); |
| 7635 | |
| 7636 | rv = ReadTransaction(push_trans.get(), &response_data); |
| 7637 | EXPECT_EQ(OK, rv); |
| 7638 | EXPECT_EQ("pushed", response_data); |
| 7639 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7640 | LoadTimingInfo push_load_timing_info; |
| 7641 | EXPECT_TRUE(push_trans->GetLoadTimingInfo(&push_load_timing_info)); |
| 7642 | TestLoadTimingReusedWithPac(push_load_timing_info); |
| 7643 | // The transactions should share a socket ID, despite being for different |
| 7644 | // origins. |
| 7645 | EXPECT_EQ(load_timing_info.socket_log_id, |
| 7646 | push_load_timing_info.socket_log_id); |
| 7647 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 7648 | trans.reset(); |
| 7649 | push_trans.reset(); |
| 7650 | session->CloseAllConnections(); |
| 7651 | } |
| 7652 | |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7653 | // Test that an explicitly trusted SPDY proxy cannot push HTTPS content. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7654 | TEST_P(HttpNetworkTransactionTest, CrossOriginProxyPushCorrectness) { |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7655 | HttpRequestInfo request; |
| 7656 | |
| 7657 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7658 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7659 | |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7660 | // Configure against https proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7661 | session_deps_.proxy_service = ProxyService::CreateFixed("https://myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7662 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7663 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 7664 | |
| 7665 | // Enable cross-origin push. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7666 | session_deps_.trusted_spdy_proxy = "myproxy:70"; |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 7667 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7668 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7669 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 7670 | scoped_ptr<SpdyFrame> stream1_syn( |
| 7671 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, false)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7672 | |
| 7673 | scoped_ptr<SpdyFrame> push_rst( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 7674 | spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_REFUSED_STREAM)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7675 | |
| 7676 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7677 | CreateMockWrite(*stream1_syn, 0, ASYNC), CreateMockWrite(*push_rst, 3), |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7678 | }; |
| 7679 | |
| 7680 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7681 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7682 | |
| 7683 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7684 | stream1_body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7685 | |
| 7686 | scoped_ptr<SpdyFrame> |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7687 | stream2_syn(spdy_util_.ConstructSpdyPush(NULL, |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7688 | 0, |
| 7689 | 2, |
| 7690 | 1, |
| 7691 | "https://www.another-origin.com/foo.dat")); |
| 7692 | |
| 7693 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7694 | CreateMockRead(*stream1_reply, 1, ASYNC), |
| 7695 | CreateMockRead(*stream2_syn, 2, ASYNC), |
| 7696 | CreateMockRead(*stream1_body, 4, ASYNC), |
| 7697 | MockRead(ASYNC, ERR_IO_PENDING, 5), // Force a pause |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7698 | }; |
| 7699 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7700 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 7701 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7702 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7703 | // Negotiate SPDY to the proxy |
| 7704 | SSLSocketDataProvider proxy(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 7705 | proxy.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7706 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7707 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 7708 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7709 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 7710 | TestCompletionCallback callback; |
| 7711 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
| 7712 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7713 | |
| 7714 | rv = callback.WaitForResult(); |
| 7715 | EXPECT_EQ(OK, rv); |
| 7716 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7717 | |
| 7718 | ASSERT_TRUE(response != NULL); |
| 7719 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 7720 | |
| 7721 | EXPECT_EQ(200, response->headers->response_code()); |
| 7722 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 7723 | |
| 7724 | std::string response_data; |
| 7725 | rv = ReadTransaction(trans.get(), &response_data); |
| 7726 | EXPECT_EQ(OK, rv); |
| 7727 | EXPECT_EQ("hello!", response_data); |
| 7728 | |
| 7729 | trans.reset(); |
| 7730 | session->CloseAllConnections(); |
| 7731 | } |
| 7732 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7733 | // Test HTTPS connections to a site with a bad certificate, going through an |
| 7734 | // HTTPS proxy |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7735 | TEST_P(HttpNetworkTransactionTest, HTTPSBadCertificateViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7736 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7737 | |
| 7738 | HttpRequestInfo request; |
| 7739 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7740 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7741 | request.load_flags = 0; |
| 7742 | |
| 7743 | // Attempt to fetch the URL from a server with a bad cert |
| 7744 | MockWrite bad_cert_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7745 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7746 | "Host: www.example.org:443\r\n" |
| 7747 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7748 | }; |
| 7749 | |
| 7750 | MockRead bad_cert_reads[] = { |
| 7751 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7752 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7753 | }; |
| 7754 | |
| 7755 | // Attempt to fetch the URL with a good cert |
| 7756 | MockWrite good_data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7757 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7758 | "Host: www.example.org:443\r\n" |
| 7759 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 7760 | MockWrite("GET / HTTP/1.1\r\n" |
| 7761 | "Host: www.example.org\r\n" |
| 7762 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7763 | }; |
| 7764 | |
| 7765 | MockRead good_cert_reads[] = { |
| 7766 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 7767 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7768 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7769 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7770 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7771 | }; |
| 7772 | |
| 7773 | StaticSocketDataProvider ssl_bad_certificate( |
| 7774 | bad_cert_reads, arraysize(bad_cert_reads), |
| 7775 | bad_cert_writes, arraysize(bad_cert_writes)); |
| 7776 | StaticSocketDataProvider data(good_cert_reads, arraysize(good_cert_reads), |
| 7777 | good_data_writes, arraysize(good_data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7778 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 7779 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7780 | |
| 7781 | // SSL to the proxy, then CONNECT request, then SSL with bad certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7782 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 7783 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 7784 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7785 | |
| 7786 | // SSL to the proxy, then CONNECT request, then valid SSL certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7787 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 7788 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7789 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7790 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7791 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7792 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7793 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7794 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7795 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7796 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7797 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7798 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7799 | |
| 7800 | rv = callback.WaitForResult(); |
| 7801 | EXPECT_EQ(ERR_CERT_AUTHORITY_INVALID, rv); |
| 7802 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7803 | rv = trans->RestartIgnoringLastError(callback.callback()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7804 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7805 | |
| 7806 | rv = callback.WaitForResult(); |
| 7807 | EXPECT_EQ(OK, rv); |
| 7808 | |
| 7809 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 7810 | |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 7811 | ASSERT_TRUE(response != NULL); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7812 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7813 | } |
| 7814 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7815 | TEST_P(HttpNetworkTransactionTest, BuildRequest_UserAgent) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7816 | HttpRequestInfo request; |
| 7817 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7818 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 7819 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 7820 | "Chromium Ultra Awesome X Edition"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7821 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7822 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7823 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7824 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7825 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7826 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7827 | MockWrite( |
| 7828 | "GET / HTTP/1.1\r\n" |
| 7829 | "Host: www.example.org\r\n" |
| 7830 | "Connection: keep-alive\r\n" |
| 7831 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7832 | }; |
| 7833 | |
| 7834 | // Lastly, the server responds with the actual content. |
| 7835 | MockRead data_reads[] = { |
| 7836 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7837 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7838 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7839 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7840 | }; |
| 7841 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7842 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7843 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7844 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7845 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7846 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7847 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7848 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7849 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7850 | |
| 7851 | rv = callback.WaitForResult(); |
| 7852 | EXPECT_EQ(OK, rv); |
| 7853 | } |
| 7854 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7855 | TEST_P(HttpNetworkTransactionTest, BuildRequest_UserAgentOverTunnel) { |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 7856 | HttpRequestInfo request; |
| 7857 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7858 | request.url = GURL("https://www.example.org/"); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 7859 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 7860 | "Chromium Ultra Awesome X Edition"); |
| 7861 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7862 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7863 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7864 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7865 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7866 | |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 7867 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7868 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7869 | "Host: www.example.org:443\r\n" |
| 7870 | "Proxy-Connection: keep-alive\r\n" |
| 7871 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 7872 | }; |
| 7873 | MockRead data_reads[] = { |
| 7874 | // Return an error, so the transaction stops here (this test isn't |
| 7875 | // interested in the rest). |
| 7876 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 7877 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7878 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 7879 | }; |
| 7880 | |
| 7881 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7882 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7883 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 7884 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7885 | TestCompletionCallback callback; |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 7886 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7887 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 7888 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7889 | |
| 7890 | rv = callback.WaitForResult(); |
| 7891 | EXPECT_EQ(OK, rv); |
| 7892 | } |
| 7893 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7894 | TEST_P(HttpNetworkTransactionTest, BuildRequest_Referer) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7895 | HttpRequestInfo request; |
| 7896 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7897 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7898 | request.load_flags = 0; |
[email protected] | c1045010 | 2011-06-27 09:06:16 | [diff] [blame] | 7899 | request.extra_headers.SetHeader(HttpRequestHeaders::kReferer, |
| 7900 | "http://the.previous.site.com/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7901 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7902 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7903 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7904 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7905 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7906 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7907 | MockWrite( |
| 7908 | "GET / HTTP/1.1\r\n" |
| 7909 | "Host: www.example.org\r\n" |
| 7910 | "Connection: keep-alive\r\n" |
| 7911 | "Referer: http://the.previous.site.com/\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7912 | }; |
| 7913 | |
| 7914 | // Lastly, the server responds with the actual content. |
| 7915 | MockRead data_reads[] = { |
| 7916 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7917 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7918 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7919 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7920 | }; |
| 7921 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7922 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7923 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7924 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7925 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7926 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7927 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7928 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7929 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7930 | |
| 7931 | rv = callback.WaitForResult(); |
| 7932 | EXPECT_EQ(OK, rv); |
| 7933 | } |
| 7934 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7935 | TEST_P(HttpNetworkTransactionTest, BuildRequest_PostContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7936 | HttpRequestInfo request; |
| 7937 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7938 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7939 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7940 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7941 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7942 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7943 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7944 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7945 | MockWrite( |
| 7946 | "POST / HTTP/1.1\r\n" |
| 7947 | "Host: www.example.org\r\n" |
| 7948 | "Connection: keep-alive\r\n" |
| 7949 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7950 | }; |
| 7951 | |
| 7952 | // Lastly, the server responds with the actual content. |
| 7953 | MockRead data_reads[] = { |
| 7954 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7955 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7956 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7957 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7958 | }; |
| 7959 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7960 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7961 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7962 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7963 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7964 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7965 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7966 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7967 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 7968 | |
| 7969 | rv = callback.WaitForResult(); |
| 7970 | EXPECT_EQ(OK, rv); |
| 7971 | } |
| 7972 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 7973 | TEST_P(HttpNetworkTransactionTest, BuildRequest_PutContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7974 | HttpRequestInfo request; |
| 7975 | request.method = "PUT"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7976 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7977 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 7978 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7979 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 7980 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7981 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7982 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7983 | MockWrite( |
| 7984 | "PUT / HTTP/1.1\r\n" |
| 7985 | "Host: www.example.org\r\n" |
| 7986 | "Connection: keep-alive\r\n" |
| 7987 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7988 | }; |
| 7989 | |
| 7990 | // Lastly, the server responds with the actual content. |
| 7991 | MockRead data_reads[] = { |
| 7992 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7993 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7994 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7995 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7996 | }; |
| 7997 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7998 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7999 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8000 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8001 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8002 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8003 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8004 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8005 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8006 | |
| 8007 | rv = callback.WaitForResult(); |
| 8008 | EXPECT_EQ(OK, rv); |
| 8009 | } |
| 8010 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8011 | TEST_P(HttpNetworkTransactionTest, BuildRequest_HeadContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8012 | HttpRequestInfo request; |
| 8013 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8014 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8015 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8016 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8017 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8018 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8019 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8020 | MockWrite data_writes[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 8021 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 8022 | "Host: www.example.org\r\n" |
| 8023 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8024 | }; |
| 8025 | |
| 8026 | // Lastly, the server responds with the actual content. |
| 8027 | MockRead data_reads[] = { |
| 8028 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8029 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8030 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8031 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8032 | }; |
| 8033 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8034 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8035 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8036 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8037 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8038 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8039 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8040 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8041 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8042 | |
| 8043 | rv = callback.WaitForResult(); |
| 8044 | EXPECT_EQ(OK, rv); |
| 8045 | } |
| 8046 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8047 | TEST_P(HttpNetworkTransactionTest, BuildRequest_CacheControlNoCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8048 | HttpRequestInfo request; |
| 8049 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8050 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8051 | request.load_flags = LOAD_BYPASS_CACHE; |
| 8052 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8053 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8054 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8055 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8056 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8057 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8058 | MockWrite( |
| 8059 | "GET / HTTP/1.1\r\n" |
| 8060 | "Host: www.example.org\r\n" |
| 8061 | "Connection: keep-alive\r\n" |
| 8062 | "Pragma: no-cache\r\n" |
| 8063 | "Cache-Control: no-cache\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8064 | }; |
| 8065 | |
| 8066 | // Lastly, the server responds with the actual content. |
| 8067 | MockRead data_reads[] = { |
| 8068 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8069 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8070 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8071 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8072 | }; |
| 8073 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8074 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8075 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8076 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8077 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8078 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8079 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8080 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8081 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8082 | |
| 8083 | rv = callback.WaitForResult(); |
| 8084 | EXPECT_EQ(OK, rv); |
| 8085 | } |
| 8086 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8087 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8088 | BuildRequest_CacheControlValidateCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8089 | HttpRequestInfo request; |
| 8090 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8091 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8092 | request.load_flags = LOAD_VALIDATE_CACHE; |
| 8093 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8094 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8095 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8096 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8097 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8098 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8099 | MockWrite( |
| 8100 | "GET / HTTP/1.1\r\n" |
| 8101 | "Host: www.example.org\r\n" |
| 8102 | "Connection: keep-alive\r\n" |
| 8103 | "Cache-Control: max-age=0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8104 | }; |
| 8105 | |
| 8106 | // Lastly, the server responds with the actual content. |
| 8107 | MockRead data_reads[] = { |
| 8108 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8109 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8110 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8111 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8112 | }; |
| 8113 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8114 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8115 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8116 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8117 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8118 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8119 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8120 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8121 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8122 | |
| 8123 | rv = callback.WaitForResult(); |
| 8124 | EXPECT_EQ(OK, rv); |
| 8125 | } |
| 8126 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8127 | TEST_P(HttpNetworkTransactionTest, BuildRequest_ExtraHeaders) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8128 | HttpRequestInfo request; |
| 8129 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8130 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 8131 | request.extra_headers.SetHeader("FooHeader", "Bar"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8132 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8133 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8134 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8135 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8136 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8137 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8138 | MockWrite( |
| 8139 | "GET / HTTP/1.1\r\n" |
| 8140 | "Host: www.example.org\r\n" |
| 8141 | "Connection: keep-alive\r\n" |
| 8142 | "FooHeader: Bar\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8143 | }; |
| 8144 | |
| 8145 | // Lastly, the server responds with the actual content. |
| 8146 | MockRead data_reads[] = { |
| 8147 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8148 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8149 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8150 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8151 | }; |
| 8152 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8153 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8154 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8155 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8156 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8157 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8158 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8159 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8160 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8161 | |
| 8162 | rv = callback.WaitForResult(); |
| 8163 | EXPECT_EQ(OK, rv); |
| 8164 | } |
| 8165 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8166 | TEST_P(HttpNetworkTransactionTest, BuildRequest_ExtraHeadersStripped) { |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8167 | HttpRequestInfo request; |
| 8168 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8169 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 8170 | request.extra_headers.SetHeader("referer", "www.foo.com"); |
| 8171 | request.extra_headers.SetHeader("hEllo", "Kitty"); |
| 8172 | request.extra_headers.SetHeader("FoO", "bar"); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8173 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8174 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8175 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8176 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8177 | |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8178 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8179 | MockWrite( |
| 8180 | "GET / HTTP/1.1\r\n" |
| 8181 | "Host: www.example.org\r\n" |
| 8182 | "Connection: keep-alive\r\n" |
| 8183 | "referer: www.foo.com\r\n" |
| 8184 | "hEllo: Kitty\r\n" |
| 8185 | "FoO: bar\r\n\r\n"), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8186 | }; |
| 8187 | |
| 8188 | // Lastly, the server responds with the actual content. |
| 8189 | MockRead data_reads[] = { |
| 8190 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8191 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8192 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8193 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8194 | }; |
| 8195 | |
| 8196 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8197 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8198 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8199 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8200 | TestCompletionCallback callback; |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8201 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8202 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8203 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8204 | |
| 8205 | rv = callback.WaitForResult(); |
| 8206 | EXPECT_EQ(OK, rv); |
| 8207 | } |
| 8208 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8209 | TEST_P(HttpNetworkTransactionTest, SOCKS4_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8210 | HttpRequestInfo request; |
| 8211 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8212 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8213 | request.load_flags = 0; |
| 8214 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8215 | session_deps_.proxy_service = |
| 8216 | ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8217 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8218 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8219 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8220 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8221 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8222 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8223 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8224 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 8225 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 8226 | |
| 8227 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8228 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
| 8229 | MockWrite( |
| 8230 | "GET / HTTP/1.1\r\n" |
| 8231 | "Host: www.example.org\r\n" |
| 8232 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8233 | |
| 8234 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8235 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8236 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8237 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 8238 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8239 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8240 | }; |
| 8241 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8242 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8243 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8244 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8245 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8246 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8247 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8248 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8249 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8250 | |
| 8251 | rv = callback.WaitForResult(); |
| 8252 | EXPECT_EQ(OK, rv); |
| 8253 | |
| 8254 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8255 | ASSERT_TRUE(response != NULL); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8256 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8257 | LoadTimingInfo load_timing_info; |
| 8258 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 8259 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8260 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 8261 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8262 | std::string response_text; |
| 8263 | rv = ReadTransaction(trans.get(), &response_text); |
| 8264 | EXPECT_EQ(OK, rv); |
| 8265 | EXPECT_EQ("Payload", response_text); |
| 8266 | } |
| 8267 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8268 | TEST_P(HttpNetworkTransactionTest, SOCKS4_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8269 | HttpRequestInfo request; |
| 8270 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8271 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8272 | request.load_flags = 0; |
| 8273 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8274 | session_deps_.proxy_service = |
| 8275 | ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8276 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8277 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8278 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8279 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8280 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8281 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8282 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8283 | unsigned char write_buffer[] = { 0x04, 0x01, 0x01, 0xBB, 127, 0, 0, 1, 0 }; |
| 8284 | unsigned char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 8285 | |
| 8286 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8287 | MockWrite(ASYNC, reinterpret_cast<char*>(write_buffer), |
| 8288 | arraysize(write_buffer)), |
| 8289 | MockWrite( |
| 8290 | "GET / HTTP/1.1\r\n" |
| 8291 | "Host: www.example.org\r\n" |
| 8292 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8293 | |
| 8294 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 8295 | MockRead(ASYNC, reinterpret_cast<char*>(read_buffer), |
| 8296 | arraysize(read_buffer)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8297 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8298 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 8299 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8300 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8301 | }; |
| 8302 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8303 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8304 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8305 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8306 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8307 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8308 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8309 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8310 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8311 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8312 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8313 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8314 | |
| 8315 | rv = callback.WaitForResult(); |
| 8316 | EXPECT_EQ(OK, rv); |
| 8317 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8318 | LoadTimingInfo load_timing_info; |
| 8319 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 8320 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8321 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 8322 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8323 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8324 | ASSERT_TRUE(response != NULL); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8325 | |
| 8326 | std::string response_text; |
| 8327 | rv = ReadTransaction(trans.get(), &response_text); |
| 8328 | EXPECT_EQ(OK, rv); |
| 8329 | EXPECT_EQ("Payload", response_text); |
| 8330 | } |
| 8331 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8332 | TEST_P(HttpNetworkTransactionTest, SOCKS4_HTTP_GET_no_PAC) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8333 | HttpRequestInfo request; |
| 8334 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8335 | request.url = GURL("http://www.example.org/"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8336 | request.load_flags = 0; |
| 8337 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8338 | session_deps_.proxy_service = |
| 8339 | ProxyService::CreateFixed("socks4://myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8340 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8341 | session_deps_.net_log = &net_log; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8342 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8343 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8344 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8345 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8346 | |
| 8347 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 8348 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 8349 | |
| 8350 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8351 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
| 8352 | MockWrite( |
| 8353 | "GET / HTTP/1.1\r\n" |
| 8354 | "Host: www.example.org\r\n" |
| 8355 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8356 | |
| 8357 | MockRead data_reads[] = { |
| 8358 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
| 8359 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8360 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 8361 | MockRead("Payload"), |
| 8362 | MockRead(SYNCHRONOUS, OK) |
| 8363 | }; |
| 8364 | |
| 8365 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8366 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8367 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8368 | |
| 8369 | TestCompletionCallback callback; |
| 8370 | |
| 8371 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 8372 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8373 | |
| 8374 | rv = callback.WaitForResult(); |
| 8375 | EXPECT_EQ(OK, rv); |
| 8376 | |
| 8377 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8378 | ASSERT_TRUE(response != NULL); |
| 8379 | |
| 8380 | LoadTimingInfo load_timing_info; |
| 8381 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 8382 | TestLoadTimingNotReused(load_timing_info, |
| 8383 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 8384 | |
| 8385 | std::string response_text; |
| 8386 | rv = ReadTransaction(trans.get(), &response_text); |
| 8387 | EXPECT_EQ(OK, rv); |
| 8388 | EXPECT_EQ("Payload", response_text); |
| 8389 | } |
| 8390 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8391 | TEST_P(HttpNetworkTransactionTest, SOCKS5_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8392 | HttpRequestInfo request; |
| 8393 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8394 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8395 | request.load_flags = 0; |
| 8396 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8397 | session_deps_.proxy_service = |
| 8398 | ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8399 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8400 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8401 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8402 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8403 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8404 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8405 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8406 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 8407 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 8408 | const char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8409 | 0x05, // Version |
| 8410 | 0x01, // Command (CONNECT) |
| 8411 | 0x00, // Reserved. |
| 8412 | 0x03, // Address type (DOMAINNAME). |
| 8413 | 0x0F, // Length of domain (15) |
| 8414 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 8415 | '.', 'o', 'r', 'g', 0x00, 0x50, // 16-bit port (80) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 8416 | }; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8417 | const char kSOCKS5OkResponse[] = |
| 8418 | { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; |
| 8419 | |
| 8420 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8421 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 8422 | MockWrite(ASYNC, kSOCKS5OkRequest, arraysize(kSOCKS5OkRequest)), |
| 8423 | MockWrite( |
| 8424 | "GET / HTTP/1.1\r\n" |
| 8425 | "Host: www.example.org\r\n" |
| 8426 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8427 | |
| 8428 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 8429 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 8430 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8431 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8432 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 8433 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8434 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8435 | }; |
| 8436 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8437 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8438 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8439 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8440 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8441 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8442 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8443 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8444 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8445 | |
| 8446 | rv = callback.WaitForResult(); |
| 8447 | EXPECT_EQ(OK, rv); |
| 8448 | |
| 8449 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8450 | ASSERT_TRUE(response != NULL); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8451 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8452 | LoadTimingInfo load_timing_info; |
| 8453 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 8454 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8455 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 8456 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8457 | std::string response_text; |
| 8458 | rv = ReadTransaction(trans.get(), &response_text); |
| 8459 | EXPECT_EQ(OK, rv); |
| 8460 | EXPECT_EQ("Payload", response_text); |
| 8461 | } |
| 8462 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8463 | TEST_P(HttpNetworkTransactionTest, SOCKS5_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8464 | HttpRequestInfo request; |
| 8465 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8466 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8467 | request.load_flags = 0; |
| 8468 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8469 | session_deps_.proxy_service = |
| 8470 | ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8471 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8472 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8473 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8474 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8475 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8476 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8477 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8478 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 8479 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 8480 | const unsigned char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8481 | 0x05, // Version |
| 8482 | 0x01, // Command (CONNECT) |
| 8483 | 0x00, // Reserved. |
| 8484 | 0x03, // Address type (DOMAINNAME). |
| 8485 | 0x0F, // Length of domain (15) |
| 8486 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 8487 | '.', 'o', 'r', 'g', 0x01, 0xBB, // 16-bit port (443) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 8488 | }; |
| 8489 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8490 | const char kSOCKS5OkResponse[] = |
| 8491 | { 0x05, 0x00, 0x00, 0x01, 0, 0, 0, 0, 0x00, 0x00 }; |
| 8492 | |
| 8493 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8494 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 8495 | MockWrite(ASYNC, reinterpret_cast<const char*>(kSOCKS5OkRequest), |
| 8496 | arraysize(kSOCKS5OkRequest)), |
| 8497 | MockWrite( |
| 8498 | "GET / HTTP/1.1\r\n" |
| 8499 | "Host: www.example.org\r\n" |
| 8500 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8501 | |
| 8502 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 8503 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 8504 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8505 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8506 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 8507 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8508 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8509 | }; |
| 8510 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8511 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8512 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8513 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8514 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8515 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8516 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8517 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8518 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8519 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8520 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8521 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8522 | |
| 8523 | rv = callback.WaitForResult(); |
| 8524 | EXPECT_EQ(OK, rv); |
| 8525 | |
| 8526 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 8527 | ASSERT_TRUE(response != NULL); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8528 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8529 | LoadTimingInfo load_timing_info; |
| 8530 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 8531 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8532 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 8533 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8534 | std::string response_text; |
| 8535 | rv = ReadTransaction(trans.get(), &response_text); |
| 8536 | EXPECT_EQ(OK, rv); |
| 8537 | EXPECT_EQ("Payload", response_text); |
| 8538 | } |
| 8539 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 8540 | namespace { |
| 8541 | |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 8542 | // Tests that for connection endpoints the group names are correctly set. |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8543 | |
| 8544 | struct GroupNameTest { |
| 8545 | std::string proxy_server; |
| 8546 | std::string url; |
| 8547 | std::string expected_group_name; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 8548 | bool ssl; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8549 | }; |
| 8550 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8551 | scoped_ptr<HttpNetworkSession> SetupSessionForGroupNameTests( |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8552 | NextProto next_proto, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8553 | SpdySessionDependencies* session_deps_) { |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8554 | scoped_ptr<HttpNetworkSession> session(CreateSession(session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8555 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 8556 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 8557 | session->http_server_properties(); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 8558 | AlternativeService alternative_service( |
bnc | 4988e43 | 2015-03-31 03:06:25 | [diff] [blame] | 8559 | AlternateProtocolFromNextProto(next_proto), "", 443); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 8560 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 8561 | http_server_properties->SetAlternativeService( |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 8562 | HostPortPair("host.with.alternate", 80), alternative_service, 1.0, |
| 8563 | expiration); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8564 | |
| 8565 | return session; |
| 8566 | } |
| 8567 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8568 | int GroupNameTransactionHelper(const std::string& url, |
| 8569 | HttpNetworkSession* session) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8570 | HttpRequestInfo request; |
| 8571 | request.method = "GET"; |
| 8572 | request.url = GURL(url); |
| 8573 | request.load_flags = 0; |
| 8574 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8575 | scoped_ptr<HttpTransaction> trans( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8576 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8577 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8578 | TestCompletionCallback callback; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8579 | |
| 8580 | // We do not complete this request, the dtor will clean the transaction up. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8581 | return trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8582 | } |
| 8583 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 8584 | } // namespace |
| 8585 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8586 | TEST_P(HttpNetworkTransactionTest, GroupNameForDirectConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8587 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8588 | { |
| 8589 | "", // unused |
| 8590 | "http://www.example.org/direct", |
| 8591 | "www.example.org:80", |
| 8592 | false, |
| 8593 | }, |
| 8594 | { |
| 8595 | "", // unused |
| 8596 | "http://[2001:1418:13:1::25]/direct", |
| 8597 | "[2001:1418:13:1::25]:80", |
| 8598 | false, |
| 8599 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 8600 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8601 | // SSL Tests |
| 8602 | { |
| 8603 | "", // unused |
| 8604 | "https://www.example.org/direct_ssl", |
| 8605 | "ssl/www.example.org:443", |
| 8606 | true, |
| 8607 | }, |
| 8608 | { |
| 8609 | "", // unused |
| 8610 | "https://[2001:1418:13:1::25]/direct", |
| 8611 | "ssl/[2001:1418:13:1::25]:443", |
| 8612 | true, |
| 8613 | }, |
| 8614 | { |
| 8615 | "", // unused |
| 8616 | "http://host.with.alternate/direct", |
| 8617 | "ssl/host.with.alternate:443", |
| 8618 | true, |
| 8619 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8620 | }; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8621 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 8622 | session_deps_.use_alternative_services = true; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8623 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 8624 | for (size_t i = 0; i < arraysize(tests); ++i) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8625 | session_deps_.proxy_service = |
| 8626 | ProxyService::CreateFixed(tests[i].proxy_server); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8627 | scoped_ptr<HttpNetworkSession> session( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 8628 | SetupSessionForGroupNameTests(GetProtocol(), &session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8629 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8630 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 8631 | CaptureGroupNameTransportSocketPool* transport_conn_pool = |
| 8632 | new CaptureGroupNameTransportSocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 8633 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 8634 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 8635 | scoped_ptr<MockClientSocketPoolManager> mock_pool_manager( |
| 8636 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 8637 | mock_pool_manager->SetTransportSocketPool(transport_conn_pool); |
| 8638 | mock_pool_manager->SetSSLSocketPool(ssl_conn_pool); |
dcheng | e3d1ddc | 2014-10-15 19:30:51 | [diff] [blame] | 8639 | peer.SetClientSocketPoolManager(mock_pool_manager.Pass()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8640 | |
| 8641 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8642 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 8643 | if (tests[i].ssl) |
| 8644 | EXPECT_EQ(tests[i].expected_group_name, |
| 8645 | ssl_conn_pool->last_group_name_received()); |
| 8646 | else |
| 8647 | EXPECT_EQ(tests[i].expected_group_name, |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 8648 | transport_conn_pool->last_group_name_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8649 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8650 | } |
| 8651 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8652 | TEST_P(HttpNetworkTransactionTest, GroupNameForHTTPProxyConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8653 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8654 | { |
| 8655 | "http_proxy", |
| 8656 | "http://www.example.org/http_proxy_normal", |
| 8657 | "www.example.org:80", |
| 8658 | false, |
| 8659 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8660 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8661 | // SSL Tests |
| 8662 | { |
| 8663 | "http_proxy", |
| 8664 | "https://www.example.org/http_connect_ssl", |
| 8665 | "ssl/www.example.org:443", |
| 8666 | true, |
| 8667 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 8668 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8669 | { |
| 8670 | "http_proxy", |
| 8671 | "http://host.with.alternate/direct", |
| 8672 | "ssl/host.with.alternate:443", |
| 8673 | true, |
| 8674 | }, |
[email protected] | 4549925 | 2013-01-23 17:12:56 | [diff] [blame] | 8675 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8676 | { |
| 8677 | "http_proxy", |
| 8678 | "ftp://ftp.google.com/http_proxy_normal", |
| 8679 | "ftp/ftp.google.com:21", |
| 8680 | false, |
| 8681 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8682 | }; |
| 8683 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 8684 | session_deps_.use_alternative_services = true; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8685 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 8686 | for (size_t i = 0; i < arraysize(tests); ++i) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8687 | session_deps_.proxy_service = |
| 8688 | ProxyService::CreateFixed(tests[i].proxy_server); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8689 | scoped_ptr<HttpNetworkSession> session( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 8690 | SetupSessionForGroupNameTests(GetProtocol(), &session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8691 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8692 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8693 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 8694 | HostPortPair proxy_host("http_proxy", 80); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 8695 | CaptureGroupNameHttpProxySocketPool* http_proxy_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 8696 | new CaptureGroupNameHttpProxySocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 8697 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 8698 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 8699 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 8700 | scoped_ptr<MockClientSocketPoolManager> mock_pool_manager( |
| 8701 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 8702 | mock_pool_manager->SetSocketPoolForHTTPProxy(proxy_host, http_proxy_pool); |
| 8703 | mock_pool_manager->SetSocketPoolForSSLWithProxy(proxy_host, ssl_conn_pool); |
dcheng | e3d1ddc | 2014-10-15 19:30:51 | [diff] [blame] | 8704 | peer.SetClientSocketPoolManager(mock_pool_manager.Pass()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8705 | |
| 8706 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8707 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 8708 | if (tests[i].ssl) |
| 8709 | EXPECT_EQ(tests[i].expected_group_name, |
| 8710 | ssl_conn_pool->last_group_name_received()); |
| 8711 | else |
| 8712 | EXPECT_EQ(tests[i].expected_group_name, |
| 8713 | http_proxy_pool->last_group_name_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8714 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8715 | } |
| 8716 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8717 | TEST_P(HttpNetworkTransactionTest, GroupNameForSOCKSConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8718 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8719 | { |
| 8720 | "socks4://socks_proxy:1080", |
| 8721 | "http://www.example.org/socks4_direct", |
| 8722 | "socks4/www.example.org:80", |
| 8723 | false, |
| 8724 | }, |
| 8725 | { |
| 8726 | "socks5://socks_proxy:1080", |
| 8727 | "http://www.example.org/socks5_direct", |
| 8728 | "socks5/www.example.org:80", |
| 8729 | false, |
| 8730 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8731 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8732 | // SSL Tests |
| 8733 | { |
| 8734 | "socks4://socks_proxy:1080", |
| 8735 | "https://www.example.org/socks4_ssl", |
| 8736 | "socks4/ssl/www.example.org:443", |
| 8737 | true, |
| 8738 | }, |
| 8739 | { |
| 8740 | "socks5://socks_proxy:1080", |
| 8741 | "https://www.example.org/socks5_ssl", |
| 8742 | "socks5/ssl/www.example.org:443", |
| 8743 | true, |
| 8744 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 8745 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8746 | { |
| 8747 | "socks4://socks_proxy:1080", |
| 8748 | "http://host.with.alternate/direct", |
| 8749 | "socks4/ssl/host.with.alternate:443", |
| 8750 | true, |
| 8751 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 8752 | }; |
| 8753 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 8754 | session_deps_.use_alternative_services = true; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 8755 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 8756 | for (size_t i = 0; i < arraysize(tests); ++i) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8757 | session_deps_.proxy_service = |
| 8758 | ProxyService::CreateFixed(tests[i].proxy_server); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8759 | scoped_ptr<HttpNetworkSession> session( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 8760 | SetupSessionForGroupNameTests(GetProtocol(), &session_deps_)); |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 8761 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8762 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 8763 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 8764 | HostPortPair proxy_host("socks_proxy", 1080); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 8765 | CaptureGroupNameSOCKSSocketPool* socks_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 8766 | new CaptureGroupNameSOCKSSocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 8767 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 8768 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 8769 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 8770 | scoped_ptr<MockClientSocketPoolManager> mock_pool_manager( |
| 8771 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 8772 | mock_pool_manager->SetSocketPoolForSOCKSProxy(proxy_host, socks_conn_pool); |
| 8773 | mock_pool_manager->SetSocketPoolForSSLWithProxy(proxy_host, ssl_conn_pool); |
dcheng | e3d1ddc | 2014-10-15 19:30:51 | [diff] [blame] | 8774 | peer.SetClientSocketPoolManager(mock_pool_manager.Pass()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 8775 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 8776 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8777 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 8778 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 8779 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8780 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 8781 | if (tests[i].ssl) |
| 8782 | EXPECT_EQ(tests[i].expected_group_name, |
| 8783 | ssl_conn_pool->last_group_name_received()); |
| 8784 | else |
| 8785 | EXPECT_EQ(tests[i].expected_group_name, |
| 8786 | socks_conn_pool->last_group_name_received()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 8787 | } |
| 8788 | } |
| 8789 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8790 | TEST_P(HttpNetworkTransactionTest, ReconsiderProxyAfterFailedConnection) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8791 | HttpRequestInfo request; |
| 8792 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8793 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8794 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8795 | session_deps_.proxy_service = |
| 8796 | ProxyService::CreateFixed("myproxy:70;foobar:80"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 8797 | |
[email protected] | 6971906 | 2010-01-05 20:09:21 | [diff] [blame] | 8798 | // This simulates failure resolving all hostnames; that means we will fail |
| 8799 | // connecting to both proxies (myproxy:70 and foobar:80). |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8800 | session_deps_.host_resolver->rules()->AddSimulatedFailure("*"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 8801 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8802 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 8803 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8804 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 8805 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8806 | TestCompletionCallback callback; |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 8807 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8808 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 8809 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8810 | |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 8811 | rv = callback.WaitForResult(); |
[email protected] | f7fccee | 2010-09-16 20:53:01 | [diff] [blame] | 8812 | EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, rv); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 8813 | } |
| 8814 | |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 8815 | // Base test to make sure that when the load flags for a request specify to |
| 8816 | // bypass the cache, the DNS cache is not used. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8817 | void HttpNetworkTransactionTest::BypassHostCacheOnRefreshHelper( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8818 | int load_flags) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8819 | // Issue a request, asking to bypass the cache(s). |
| 8820 | HttpRequestInfo request; |
| 8821 | request.method = "GET"; |
| 8822 | request.load_flags = load_flags; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8823 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8824 | |
[email protected] | a2c2fb9 | 2009-07-18 07:31:04 | [diff] [blame] | 8825 | // Select a host resolver that does caching. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8826 | session_deps_.host_resolver.reset(new MockCachingHostResolver); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 8827 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8828 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 8829 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8830 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8831 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8832 | // 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] | 8833 | AddressList addrlist; |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 8834 | TestCompletionCallback callback; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8835 | int rv = session_deps_.host_resolver->Resolve( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8836 | HostResolver::RequestInfo(HostPortPair("www.example.org", 80)), |
| 8837 | DEFAULT_PRIORITY, &addrlist, callback.callback(), NULL, BoundNetLog()); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 8838 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8839 | rv = callback.WaitForResult(); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8840 | EXPECT_EQ(OK, rv); |
| 8841 | |
| 8842 | // Verify that it was added to host cache, by doing a subsequent async lookup |
| 8843 | // and confirming it completes synchronously. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8844 | rv = session_deps_.host_resolver->Resolve( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8845 | HostResolver::RequestInfo(HostPortPair("www.example.org", 80)), |
| 8846 | DEFAULT_PRIORITY, &addrlist, callback.callback(), NULL, BoundNetLog()); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 8847 | ASSERT_EQ(OK, rv); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8848 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8849 | // 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] | 8850 | // we can tell if the next lookup hit the cache, or the "network". |
| 8851 | // (cache --> success, "network" --> failure). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8852 | session_deps_.host_resolver->rules()->AddSimulatedFailure("www.example.org"); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8853 | |
| 8854 | // Connect up a mock socket which will fail with ERR_UNEXPECTED during the |
| 8855 | // 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] | 8856 | MockRead data_reads[] = { MockRead(SYNCHRONOUS, ERR_UNEXPECTED) }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8857 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8858 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8859 | |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8860 | // Run the request. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8861 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8862 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8863 | rv = callback.WaitForResult(); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8864 | |
| 8865 | // If we bypassed the cache, we would have gotten a failure while resolving |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8866 | // "www.example.org". |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 8867 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, rv); |
| 8868 | } |
| 8869 | |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 8870 | // There are multiple load flags that should trigger the host cache bypass. |
| 8871 | // Test each in isolation: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8872 | TEST_P(HttpNetworkTransactionTest, BypassHostCacheOnRefresh1) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 8873 | BypassHostCacheOnRefreshHelper(LOAD_BYPASS_CACHE); |
| 8874 | } |
| 8875 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8876 | TEST_P(HttpNetworkTransactionTest, BypassHostCacheOnRefresh2) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 8877 | BypassHostCacheOnRefreshHelper(LOAD_VALIDATE_CACHE); |
| 8878 | } |
| 8879 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8880 | TEST_P(HttpNetworkTransactionTest, BypassHostCacheOnRefresh3) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 8881 | BypassHostCacheOnRefreshHelper(LOAD_DISABLE_CACHE); |
| 8882 | } |
| 8883 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8884 | // Make sure we can handle an error when writing the request. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8885 | TEST_P(HttpNetworkTransactionTest, RequestWriteError) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8886 | HttpRequestInfo request; |
| 8887 | request.method = "GET"; |
| 8888 | request.url = GURL("http://www.foo.com/"); |
| 8889 | request.load_flags = 0; |
| 8890 | |
| 8891 | MockWrite write_failure[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8892 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8893 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8894 | StaticSocketDataProvider data(NULL, 0, |
| 8895 | write_failure, arraysize(write_failure)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8896 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8897 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8898 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8899 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8900 | |
| 8901 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8902 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8903 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8904 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8905 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8906 | |
| 8907 | rv = callback.WaitForResult(); |
| 8908 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 8909 | |
| 8910 | IPEndPoint endpoint; |
| 8911 | EXPECT_TRUE(trans->GetRemoteEndpoint(&endpoint)); |
| 8912 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8913 | } |
| 8914 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 8915 | // Check that a connection closed after the start of the headers finishes ok. |
| 8916 | TEST_P(HttpNetworkTransactionTest, ConnectionClosedAfterStartOfHeaders) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8917 | HttpRequestInfo request; |
| 8918 | request.method = "GET"; |
| 8919 | request.url = GURL("http://www.foo.com/"); |
| 8920 | request.load_flags = 0; |
| 8921 | |
| 8922 | MockRead data_reads[] = { |
| 8923 | MockRead("HTTP/1."), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8924 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8925 | }; |
| 8926 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8927 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8928 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 8929 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8930 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8931 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8932 | |
| 8933 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 8934 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8935 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8936 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8937 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8938 | |
| 8939 | rv = callback.WaitForResult(); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 8940 | EXPECT_EQ(OK, rv); |
| 8941 | |
| 8942 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8943 | ASSERT_TRUE(response != NULL); |
| 8944 | |
| 8945 | EXPECT_TRUE(response->headers.get() != NULL); |
| 8946 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 8947 | |
| 8948 | std::string response_data; |
| 8949 | rv = ReadTransaction(trans.get(), &response_data); |
| 8950 | EXPECT_EQ(OK, rv); |
| 8951 | EXPECT_EQ("", response_data); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 8952 | |
| 8953 | IPEndPoint endpoint; |
| 8954 | EXPECT_TRUE(trans->GetRemoteEndpoint(&endpoint)); |
| 8955 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8956 | } |
| 8957 | |
| 8958 | // Make sure that a dropped connection while draining the body for auth |
| 8959 | // restart does the right thing. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 8960 | TEST_P(HttpNetworkTransactionTest, DrainResetOK) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8961 | HttpRequestInfo request; |
| 8962 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8963 | request.url = GURL("http://www.example.org/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8964 | request.load_flags = 0; |
| 8965 | |
| 8966 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8967 | MockWrite( |
| 8968 | "GET / HTTP/1.1\r\n" |
| 8969 | "Host: www.example.org\r\n" |
| 8970 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8971 | }; |
| 8972 | |
| 8973 | MockRead data_reads1[] = { |
| 8974 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 8975 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8976 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8977 | MockRead("Content-Length: 14\r\n\r\n"), |
| 8978 | MockRead("Unauth"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8979 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8980 | }; |
| 8981 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8982 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 8983 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8984 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8985 | |
| 8986 | // After calling trans->RestartWithAuth(), this is the request we should |
| 8987 | // be issuing -- the final header line contains the credentials. |
| 8988 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8989 | MockWrite( |
| 8990 | "GET / HTTP/1.1\r\n" |
| 8991 | "Host: www.example.org\r\n" |
| 8992 | "Connection: keep-alive\r\n" |
| 8993 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8994 | }; |
| 8995 | |
| 8996 | // Lastly, the server responds with the actual content. |
| 8997 | MockRead data_reads2[] = { |
| 8998 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 8999 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9000 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9001 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9002 | }; |
| 9003 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9004 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 9005 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9006 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9007 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9008 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9009 | TestCompletionCallback callback1; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9010 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9011 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9012 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 9013 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9014 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9015 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9016 | |
| 9017 | rv = callback1.WaitForResult(); |
| 9018 | EXPECT_EQ(OK, rv); |
| 9019 | |
| 9020 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 9021 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9022 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9023 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9024 | TestCompletionCallback callback2; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9025 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9026 | rv = trans->RestartWithAuth( |
| 9027 | AuthCredentials(kFoo, kBar), callback2.callback()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9028 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9029 | |
| 9030 | rv = callback2.WaitForResult(); |
| 9031 | EXPECT_EQ(OK, rv); |
| 9032 | |
| 9033 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 9034 | ASSERT_TRUE(response != NULL); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9035 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 9036 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9037 | } |
| 9038 | |
| 9039 | // Test HTTPS connections going through a proxy that sends extra data. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9040 | TEST_P(HttpNetworkTransactionTest, HTTPSViaProxyWithExtraData) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9041 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9042 | |
| 9043 | HttpRequestInfo request; |
| 9044 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9045 | request.url = GURL("https://www.example.org/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9046 | request.load_flags = 0; |
| 9047 | |
| 9048 | MockRead proxy_reads[] = { |
| 9049 | MockRead("HTTP/1.0 200 Connected\r\n\r\nExtra data"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9050 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9051 | }; |
| 9052 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9053 | StaticSocketDataProvider data(proxy_reads, arraysize(proxy_reads), NULL, 0); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9054 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9055 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9056 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9057 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9058 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9059 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9060 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9061 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9062 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9063 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9064 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 9065 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9066 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9067 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9068 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9069 | |
| 9070 | rv = callback.WaitForResult(); |
| 9071 | EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); |
| 9072 | } |
| 9073 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9074 | TEST_P(HttpNetworkTransactionTest, LargeContentLengthThenClose) { |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9075 | HttpRequestInfo request; |
| 9076 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9077 | request.url = GURL("http://www.example.org/"); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9078 | request.load_flags = 0; |
| 9079 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9080 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9081 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 9082 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9083 | |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 9084 | MockRead data_reads[] = { |
| 9085 | 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] | 9086 | MockRead(SYNCHRONOUS, OK), |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 9087 | }; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9088 | |
| 9089 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9090 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9091 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9092 | TestCompletionCallback callback; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9093 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9094 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9095 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9096 | |
| 9097 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9098 | |
| 9099 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 9100 | ASSERT_TRUE(response != NULL); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9101 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9102 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9103 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 9104 | |
| 9105 | std::string response_data; |
| 9106 | rv = ReadTransaction(trans.get(), &response_data); |
[email protected] | 5543cbb | 2012-04-20 16:35:23 | [diff] [blame] | 9107 | EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, rv); |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 9108 | } |
| 9109 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9110 | TEST_P(HttpNetworkTransactionTest, UploadFileSmallerThanLength) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 9111 | base::FilePath temp_file_path; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 9112 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file_path)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9113 | const uint64 kFakeSize = 100000; // file is actually blank |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 9114 | UploadFileElementReader::ScopedOverridingContentLengthForTests |
| 9115 | overriding_content_length(kFakeSize); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9116 | |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 9117 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 9118 | element_readers.push_back(make_scoped_ptr(new UploadFileElementReader( |
| 9119 | base::ThreadTaskRunnerHandle::Get().get(), temp_file_path, 0, kuint64max, |
| 9120 | base::Time()))); |
| 9121 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9122 | |
| 9123 | HttpRequestInfo request; |
| 9124 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9125 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9126 | request.upload_data_stream = &upload_data_stream; |
| 9127 | request.load_flags = 0; |
| 9128 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9129 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9130 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 9131 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9132 | |
| 9133 | MockRead data_reads[] = { |
| 9134 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 9135 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9136 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9137 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9138 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9139 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9140 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9141 | TestCompletionCallback callback; |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9142 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9143 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9144 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9145 | |
| 9146 | rv = callback.WaitForResult(); |
| 9147 | EXPECT_EQ(OK, rv); |
| 9148 | |
| 9149 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 9150 | ASSERT_TRUE(response != NULL); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9151 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9152 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9153 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 9154 | |
| 9155 | std::string response_data; |
| 9156 | rv = ReadTransaction(trans.get(), &response_data); |
| 9157 | EXPECT_EQ(OK, rv); |
| 9158 | EXPECT_EQ("hello world", response_data); |
| 9159 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 9160 | base::DeleteFile(temp_file_path, false); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9161 | } |
| 9162 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9163 | TEST_P(HttpNetworkTransactionTest, UploadUnreadableFile) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 9164 | base::FilePath temp_file; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 9165 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9166 | std::string temp_file_content("Unreadable file."); |
[email protected] | e5c2a22e | 2014-03-06 20:42:30 | [diff] [blame] | 9167 | ASSERT_TRUE(base::WriteFile(temp_file, temp_file_content.c_str(), |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9168 | temp_file_content.length())); |
[email protected] | 92be8eb | 2014-08-07 22:57:11 | [diff] [blame] | 9169 | ASSERT_TRUE(base::MakeFileUnreadable(temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9170 | |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 9171 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 9172 | element_readers.push_back(make_scoped_ptr( |
skyostil | 4891b25b | 2015-06-11 11:43:45 | [diff] [blame] | 9173 | new UploadFileElementReader(base::ThreadTaskRunnerHandle::Get().get(), |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 9174 | temp_file, 0, kuint64max, base::Time()))); |
| 9175 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9176 | |
| 9177 | HttpRequestInfo request; |
| 9178 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9179 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9180 | request.upload_data_stream = &upload_data_stream; |
| 9181 | request.load_flags = 0; |
| 9182 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 9183 | // If we try to upload an unreadable file, the transaction should fail. |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9184 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9185 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 9186 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9187 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 9188 | StaticSocketDataProvider data(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9189 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9190 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9191 | TestCompletionCallback callback; |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9192 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9193 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9194 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9195 | |
| 9196 | rv = callback.WaitForResult(); |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 9197 | EXPECT_EQ(ERR_ACCESS_DENIED, rv); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9198 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 9199 | base::DeleteFile(temp_file, false); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9200 | } |
| 9201 | |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9202 | TEST_P(HttpNetworkTransactionTest, CancelDuringInitRequestBody) { |
| 9203 | class FakeUploadElementReader : public UploadElementReader { |
| 9204 | public: |
| 9205 | FakeUploadElementReader() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9206 | ~FakeUploadElementReader() override {} |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9207 | |
| 9208 | const CompletionCallback& callback() const { return callback_; } |
| 9209 | |
| 9210 | // UploadElementReader overrides: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9211 | int Init(const CompletionCallback& callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9212 | callback_ = callback; |
| 9213 | return ERR_IO_PENDING; |
| 9214 | } |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9215 | uint64 GetContentLength() const override { return 0; } |
| 9216 | uint64 BytesRemaining() const override { return 0; } |
| 9217 | int Read(IOBuffer* buf, |
| 9218 | int buf_length, |
| 9219 | const CompletionCallback& callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9220 | return ERR_FAILED; |
| 9221 | } |
| 9222 | |
| 9223 | private: |
| 9224 | CompletionCallback callback_; |
| 9225 | }; |
| 9226 | |
| 9227 | FakeUploadElementReader* fake_reader = new FakeUploadElementReader; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 9228 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 9229 | element_readers.push_back(make_scoped_ptr(fake_reader)); |
| 9230 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9231 | |
| 9232 | HttpRequestInfo request; |
| 9233 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9234 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9235 | request.upload_data_stream = &upload_data_stream; |
| 9236 | request.load_flags = 0; |
| 9237 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9238 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9239 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 9240 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9241 | |
| 9242 | StaticSocketDataProvider data; |
| 9243 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9244 | |
| 9245 | TestCompletionCallback callback; |
| 9246 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 9247 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9248 | base::MessageLoop::current()->RunUntilIdle(); |
| 9249 | |
| 9250 | // Transaction is pending on request body initialization. |
| 9251 | ASSERT_FALSE(fake_reader->callback().is_null()); |
| 9252 | |
| 9253 | // Return Init()'s result after the transaction gets destroyed. |
| 9254 | trans.reset(); |
| 9255 | fake_reader->callback().Run(OK); // Should not crash. |
| 9256 | } |
| 9257 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9258 | // Tests that changes to Auth realms are treated like auth rejections. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9259 | TEST_P(HttpNetworkTransactionTest, ChangeAuthRealms) { |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9260 | HttpRequestInfo request; |
| 9261 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9262 | request.url = GURL("http://www.example.org/"); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9263 | request.load_flags = 0; |
| 9264 | |
| 9265 | // First transaction will request a resource and receive a Basic challenge |
| 9266 | // with realm="first_realm". |
| 9267 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9268 | MockWrite( |
| 9269 | "GET / HTTP/1.1\r\n" |
| 9270 | "Host: www.example.org\r\n" |
| 9271 | "Connection: keep-alive\r\n" |
| 9272 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9273 | }; |
| 9274 | MockRead data_reads1[] = { |
| 9275 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 9276 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 9277 | "\r\n"), |
| 9278 | }; |
| 9279 | |
| 9280 | // After calling trans->RestartWithAuth(), provide an Authentication header |
| 9281 | // for first_realm. The server will reject and provide a challenge with |
| 9282 | // second_realm. |
| 9283 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9284 | MockWrite( |
| 9285 | "GET / HTTP/1.1\r\n" |
| 9286 | "Host: www.example.org\r\n" |
| 9287 | "Connection: keep-alive\r\n" |
| 9288 | "Authorization: Basic Zmlyc3Q6YmF6\r\n" |
| 9289 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9290 | }; |
| 9291 | MockRead data_reads2[] = { |
| 9292 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 9293 | "WWW-Authenticate: Basic realm=\"second_realm\"\r\n" |
| 9294 | "\r\n"), |
| 9295 | }; |
| 9296 | |
| 9297 | // This again fails, and goes back to first_realm. Make sure that the |
| 9298 | // entry is removed from cache. |
| 9299 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9300 | MockWrite( |
| 9301 | "GET / HTTP/1.1\r\n" |
| 9302 | "Host: www.example.org\r\n" |
| 9303 | "Connection: keep-alive\r\n" |
| 9304 | "Authorization: Basic c2Vjb25kOmZvdQ==\r\n" |
| 9305 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9306 | }; |
| 9307 | MockRead data_reads3[] = { |
| 9308 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 9309 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 9310 | "\r\n"), |
| 9311 | }; |
| 9312 | |
| 9313 | // Try one last time (with the correct password) and get the resource. |
| 9314 | MockWrite data_writes4[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9315 | MockWrite( |
| 9316 | "GET / HTTP/1.1\r\n" |
| 9317 | "Host: www.example.org\r\n" |
| 9318 | "Connection: keep-alive\r\n" |
| 9319 | "Authorization: Basic Zmlyc3Q6YmFy\r\n" |
| 9320 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9321 | }; |
| 9322 | MockRead data_reads4[] = { |
| 9323 | MockRead("HTTP/1.1 200 OK\r\n" |
| 9324 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 9325 | "Content-Length: 5\r\n" |
| 9326 | "\r\n" |
| 9327 | "hello"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9328 | }; |
| 9329 | |
| 9330 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 9331 | data_writes1, arraysize(data_writes1)); |
| 9332 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 9333 | data_writes2, arraysize(data_writes2)); |
| 9334 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 9335 | data_writes3, arraysize(data_writes3)); |
| 9336 | StaticSocketDataProvider data4(data_reads4, arraysize(data_reads4), |
| 9337 | data_writes4, arraysize(data_writes4)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9338 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 9339 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 9340 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 9341 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9342 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9343 | TestCompletionCallback callback1; |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9344 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9345 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 9346 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 9347 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 9348 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9349 | // Issue the first request with Authorize headers. There should be a |
| 9350 | // password prompt for first_realm waiting to be filled in after the |
| 9351 | // transaction completes. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9352 | int rv = trans->Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9353 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9354 | rv = callback1.WaitForResult(); |
| 9355 | EXPECT_EQ(OK, rv); |
| 9356 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 9357 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9358 | const AuthChallengeInfo* challenge = response->auth_challenge.get(); |
| 9359 | ASSERT_FALSE(challenge == NULL); |
| 9360 | EXPECT_FALSE(challenge->is_proxy); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9361 | EXPECT_EQ("www.example.org:80", challenge->challenger.ToString()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9362 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame^] | 9363 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9364 | |
| 9365 | // Issue the second request with an incorrect password. There should be a |
| 9366 | // password prompt for second_realm waiting to be filled in after the |
| 9367 | // transaction completes. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9368 | TestCompletionCallback callback2; |
| 9369 | rv = trans->RestartWithAuth( |
| 9370 | AuthCredentials(kFirst, kBaz), callback2.callback()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9371 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9372 | rv = callback2.WaitForResult(); |
| 9373 | EXPECT_EQ(OK, rv); |
| 9374 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 9375 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9376 | challenge = response->auth_challenge.get(); |
| 9377 | ASSERT_FALSE(challenge == NULL); |
| 9378 | EXPECT_FALSE(challenge->is_proxy); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9379 | EXPECT_EQ("www.example.org:80", challenge->challenger.ToString()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9380 | EXPECT_EQ("second_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame^] | 9381 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9382 | |
| 9383 | // Issue the third request with another incorrect password. There should be |
| 9384 | // a password prompt for first_realm waiting to be filled in. If the password |
| 9385 | // prompt is not present, it indicates that the HttpAuthCacheEntry for |
| 9386 | // first_realm was not correctly removed. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9387 | TestCompletionCallback callback3; |
| 9388 | rv = trans->RestartWithAuth( |
| 9389 | AuthCredentials(kSecond, kFou), callback3.callback()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9390 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9391 | rv = callback3.WaitForResult(); |
| 9392 | EXPECT_EQ(OK, rv); |
| 9393 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 9394 | ASSERT_TRUE(response != NULL); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9395 | challenge = response->auth_challenge.get(); |
| 9396 | ASSERT_FALSE(challenge == NULL); |
| 9397 | EXPECT_FALSE(challenge->is_proxy); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9398 | EXPECT_EQ("www.example.org:80", challenge->challenger.ToString()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9399 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame^] | 9400 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9401 | |
| 9402 | // Issue the fourth request with the correct password and username. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9403 | TestCompletionCallback callback4; |
| 9404 | rv = trans->RestartWithAuth( |
| 9405 | AuthCredentials(kFirst, kBar), callback4.callback()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9406 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9407 | rv = callback4.WaitForResult(); |
| 9408 | EXPECT_EQ(OK, rv); |
| 9409 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 9410 | ASSERT_TRUE(response != NULL); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9411 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 9412 | } |
| 9413 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9414 | TEST_P(HttpNetworkTransactionTest, HonorAlternativeServiceHeader) { |
| 9415 | session_deps_.next_protos = SpdyNextProtos(); |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9416 | session_deps_.use_alternative_services = true; |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9417 | |
| 9418 | std::string alternative_service_http_header = |
| 9419 | GetAlternativeServiceHttpHeader(); |
| 9420 | |
| 9421 | MockRead data_reads[] = { |
| 9422 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9423 | MockRead(alternative_service_http_header.c_str()), |
| 9424 | MockRead("\r\n"), |
| 9425 | MockRead("hello world"), |
| 9426 | MockRead(SYNCHRONOUS, OK), |
| 9427 | }; |
| 9428 | |
| 9429 | HttpRequestInfo request; |
| 9430 | request.method = "GET"; |
| 9431 | request.url = GURL("http://www.example.org/"); |
| 9432 | request.load_flags = 0; |
| 9433 | |
| 9434 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 9435 | |
| 9436 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9437 | |
| 9438 | TestCompletionCallback callback; |
| 9439 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9440 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9441 | scoped_ptr<HttpTransaction> trans( |
| 9442 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 9443 | |
| 9444 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 9445 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9446 | |
| 9447 | HostPortPair http_host_port_pair("www.example.org", 80); |
| 9448 | HttpServerProperties& http_server_properties = |
| 9449 | *session->http_server_properties(); |
| 9450 | AlternativeServiceVector alternative_service_vector = |
| 9451 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9452 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 9453 | |
| 9454 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9455 | |
| 9456 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9457 | ASSERT_TRUE(response != NULL); |
| 9458 | ASSERT_TRUE(response->headers.get() != NULL); |
| 9459 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9460 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9461 | EXPECT_FALSE(response->was_npn_negotiated); |
| 9462 | |
| 9463 | std::string response_data; |
| 9464 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9465 | EXPECT_EQ("hello world", response_data); |
| 9466 | |
| 9467 | alternative_service_vector = |
| 9468 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9469 | ASSERT_EQ(1u, alternative_service_vector.size()); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 9470 | EXPECT_EQ(AlternateProtocolFromNextProto(GetProtocol()), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9471 | alternative_service_vector[0].protocol); |
| 9472 | EXPECT_EQ("www.example.com", alternative_service_vector[0].host); |
| 9473 | EXPECT_EQ(443, alternative_service_vector[0].port); |
| 9474 | } |
| 9475 | |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 9476 | TEST_P(HttpNetworkTransactionTest, ClearAlternativeServices) { |
| 9477 | session_deps_.next_protos = SpdyNextProtos(); |
| 9478 | session_deps_.use_alternative_services = true; |
| 9479 | |
| 9480 | // Set an alternative service for origin. |
| 9481 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 9482 | HttpServerProperties& http_server_properties = |
| 9483 | *session->http_server_properties(); |
| 9484 | HostPortPair http_host_port_pair("www.example.org", 80); |
| 9485 | AlternativeService alternative_service(QUIC, "", 80); |
| 9486 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 9487 | http_server_properties.SetAlternativeService( |
| 9488 | http_host_port_pair, alternative_service, 1.0, expiration); |
| 9489 | AlternativeServiceVector alternative_service_vector = |
| 9490 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9491 | EXPECT_EQ(1u, alternative_service_vector.size()); |
| 9492 | |
| 9493 | // Send a clear header. |
| 9494 | MockRead data_reads[] = { |
| 9495 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9496 | MockRead("Alt-Svc: clear\r\n"), |
| 9497 | MockRead("\r\n"), |
| 9498 | MockRead("hello world"), |
| 9499 | MockRead(SYNCHRONOUS, OK), |
| 9500 | }; |
| 9501 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), nullptr, 0); |
| 9502 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9503 | |
| 9504 | HttpRequestInfo request; |
| 9505 | request.method = "GET"; |
| 9506 | request.url = GURL("http://www.example.org/"); |
| 9507 | request.load_flags = 0; |
| 9508 | |
| 9509 | TestCompletionCallback callback; |
| 9510 | |
| 9511 | scoped_ptr<HttpTransaction> trans( |
| 9512 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 9513 | |
| 9514 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 9515 | EXPECT_EQ(OK, callback.GetResult(rv)); |
| 9516 | |
| 9517 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9518 | ASSERT_TRUE(response != nullptr); |
| 9519 | ASSERT_TRUE(response->headers.get() != nullptr); |
| 9520 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9521 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9522 | EXPECT_FALSE(response->was_npn_negotiated); |
| 9523 | |
| 9524 | std::string response_data; |
| 9525 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9526 | EXPECT_EQ("hello world", response_data); |
| 9527 | |
| 9528 | alternative_service_vector = |
| 9529 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9530 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 9531 | } |
| 9532 | |
bnc | 54ec34b7 | 2015-08-26 19:34:56 | [diff] [blame] | 9533 | // Alternative Service headers must be ignored when |use_alternative_services| |
| 9534 | // is false. |
| 9535 | TEST_P(HttpNetworkTransactionTest, DoNotHonorAlternativeServiceHeader) { |
| 9536 | session_deps_.next_protos = SpdyNextProtos(); |
| 9537 | session_deps_.use_alternative_services = false; |
| 9538 | |
| 9539 | std::string alternative_service_http_header = |
| 9540 | GetAlternativeServiceHttpHeader(); |
| 9541 | |
| 9542 | MockRead data_reads[] = { |
| 9543 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9544 | MockRead(alternative_service_http_header.c_str()), |
| 9545 | MockRead("\r\n"), |
| 9546 | MockRead("hello world"), |
| 9547 | MockRead(SYNCHRONOUS, OK), |
| 9548 | }; |
| 9549 | |
| 9550 | HttpRequestInfo request; |
| 9551 | request.method = "GET"; |
| 9552 | request.url = GURL("http://www.example.org/"); |
| 9553 | request.load_flags = 0; |
| 9554 | |
| 9555 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), nullptr, 0); |
| 9556 | |
| 9557 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9558 | |
| 9559 | TestCompletionCallback callback; |
| 9560 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9561 | scoped_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
bnc | 54ec34b7 | 2015-08-26 19:34:56 | [diff] [blame] | 9562 | scoped_ptr<HttpTransaction> trans( |
| 9563 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 9564 | |
| 9565 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 9566 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9567 | |
| 9568 | HostPortPair http_host_port_pair("www.example.org", 80); |
| 9569 | HttpServerProperties& http_server_properties = |
| 9570 | *session->http_server_properties(); |
| 9571 | AlternativeServiceVector alternative_service_vector = |
| 9572 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9573 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 9574 | |
| 9575 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9576 | |
| 9577 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9578 | ASSERT_TRUE(response != nullptr); |
| 9579 | ASSERT_TRUE(response->headers.get() != nullptr); |
| 9580 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9581 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9582 | EXPECT_FALSE(response->was_npn_negotiated); |
| 9583 | |
| 9584 | std::string response_data; |
| 9585 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9586 | EXPECT_EQ("hello world", response_data); |
| 9587 | |
| 9588 | alternative_service_vector = |
| 9589 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9590 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 9591 | } |
| 9592 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9593 | TEST_P(HttpNetworkTransactionTest, HonorMultipleAlternativeServiceHeader) { |
| 9594 | session_deps_.next_protos = SpdyNextProtos(); |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9595 | session_deps_.use_alternative_services = true; |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9596 | |
| 9597 | MockRead data_reads[] = { |
| 9598 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9599 | MockRead("Alt-Svc: "), |
| 9600 | MockRead(GetAlternateProtocolFromParam()), |
bnc | 44858c8 | 2015-10-16 11:57:21 | [diff] [blame] | 9601 | MockRead("=\"www.example.com:443\";p=\"1.0\","), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9602 | MockRead("quic=\":1234\"\r\n\r\n"), |
| 9603 | MockRead("hello world"), |
| 9604 | MockRead(SYNCHRONOUS, OK), |
| 9605 | }; |
| 9606 | |
| 9607 | HttpRequestInfo request; |
| 9608 | request.method = "GET"; |
| 9609 | request.url = GURL("http://www.example.org/"); |
| 9610 | request.load_flags = 0; |
| 9611 | |
| 9612 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 9613 | |
| 9614 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9615 | |
| 9616 | TestCompletionCallback callback; |
| 9617 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9618 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9619 | scoped_ptr<HttpTransaction> trans( |
| 9620 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 9621 | |
| 9622 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 9623 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9624 | |
| 9625 | HostPortPair http_host_port_pair("www.example.org", 80); |
| 9626 | HttpServerProperties& http_server_properties = |
| 9627 | *session->http_server_properties(); |
| 9628 | AlternativeServiceVector alternative_service_vector = |
| 9629 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9630 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 9631 | |
| 9632 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9633 | |
| 9634 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9635 | ASSERT_TRUE(response != NULL); |
| 9636 | ASSERT_TRUE(response->headers.get() != NULL); |
| 9637 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9638 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9639 | EXPECT_FALSE(response->was_npn_negotiated); |
| 9640 | |
| 9641 | std::string response_data; |
| 9642 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9643 | EXPECT_EQ("hello world", response_data); |
| 9644 | |
| 9645 | alternative_service_vector = |
| 9646 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9647 | ASSERT_EQ(2u, alternative_service_vector.size()); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 9648 | EXPECT_EQ(AlternateProtocolFromNextProto(GetProtocol()), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9649 | alternative_service_vector[0].protocol); |
| 9650 | EXPECT_EQ("www.example.com", alternative_service_vector[0].host); |
| 9651 | EXPECT_EQ(443, alternative_service_vector[0].port); |
| 9652 | EXPECT_EQ(QUIC, alternative_service_vector[1].protocol); |
| 9653 | EXPECT_EQ("www.example.org", alternative_service_vector[1].host); |
| 9654 | EXPECT_EQ(1234, alternative_service_vector[1].port); |
| 9655 | } |
| 9656 | |
bnc | 54ec34b7 | 2015-08-26 19:34:56 | [diff] [blame] | 9657 | // Alternate Protocol headers must be honored even if |use_alternative_services| |
| 9658 | // is false. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9659 | TEST_P(HttpNetworkTransactionTest, HonorAlternateProtocolHeader) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 9660 | session_deps_.next_protos = SpdyNextProtos(); |
bnc | 54ec34b7 | 2015-08-26 19:34:56 | [diff] [blame] | 9661 | session_deps_.use_alternative_services = false; |
[email protected] | a2cb812 | 2010-03-10 17:22:42 | [diff] [blame] | 9662 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 9663 | std::string alternate_protocol_http_header = |
| 9664 | GetAlternateProtocolHttpHeader(); |
| 9665 | |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9666 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9667 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9668 | MockRead(alternate_protocol_http_header.c_str()), |
| 9669 | MockRead("\r\n"), |
| 9670 | MockRead("hello world"), |
| 9671 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9672 | }; |
| 9673 | |
| 9674 | HttpRequestInfo request; |
| 9675 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9676 | request.url = GURL("http://www.example.org/"); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9677 | request.load_flags = 0; |
| 9678 | |
| 9679 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 9680 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9681 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9682 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9683 | TestCompletionCallback callback; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9684 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9685 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9686 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9687 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9688 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9689 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9690 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 9691 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9692 | HostPortPair http_host_port_pair("www.example.org", 80); |
[email protected] | 9801e370 | 2014-03-07 09:33:55 | [diff] [blame] | 9693 | HttpServerProperties& http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 9694 | *session->http_server_properties(); |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 9695 | AlternativeServiceVector alternative_service_vector = |
| 9696 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9697 | EXPECT_TRUE(alternative_service_vector.empty()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9698 | |
| 9699 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9700 | |
| 9701 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9702 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9703 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9704 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 9705 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9706 | EXPECT_FALSE(response->was_npn_negotiated); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9707 | |
| 9708 | std::string response_data; |
| 9709 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9710 | EXPECT_EQ("hello world", response_data); |
| 9711 | |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 9712 | alternative_service_vector = |
| 9713 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9714 | ASSERT_EQ(1u, alternative_service_vector.size()); |
| 9715 | EXPECT_EQ(443, alternative_service_vector[0].port); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 9716 | EXPECT_EQ(AlternateProtocolFromNextProto(GetProtocol()), |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 9717 | alternative_service_vector[0].protocol); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9718 | } |
| 9719 | |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 9720 | TEST_P(HttpNetworkTransactionTest, EmptyAlternateProtocolHeader) { |
| 9721 | session_deps_.next_protos = SpdyNextProtos(); |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9722 | session_deps_.use_alternative_services = true; |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 9723 | |
| 9724 | MockRead data_reads[] = { |
| 9725 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9726 | MockRead("Alternate-Protocol: \r\n\r\n"), |
| 9727 | MockRead("hello world"), |
| 9728 | MockRead(SYNCHRONOUS, OK), |
| 9729 | }; |
| 9730 | |
| 9731 | HttpRequestInfo request; |
| 9732 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9733 | request.url = GURL("http://www.example.org/"); |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 9734 | request.load_flags = 0; |
| 9735 | |
| 9736 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 9737 | |
| 9738 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9739 | |
| 9740 | TestCompletionCallback callback; |
| 9741 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9742 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 9743 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9744 | HostPortPair http_host_port_pair("www.example.org", 80); |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 9745 | HttpServerProperties& http_server_properties = |
| 9746 | *session->http_server_properties(); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9747 | AlternativeService alternative_service(QUIC, "", 80); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9748 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 9749 | http_server_properties.SetAlternativeService( |
| 9750 | http_host_port_pair, alternative_service, 1.0, expiration); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9751 | |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 9752 | AlternativeServiceVector alternative_service_vector = |
| 9753 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9754 | ASSERT_EQ(1u, alternative_service_vector.size()); |
| 9755 | EXPECT_EQ(QUIC, alternative_service_vector[0].protocol); |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 9756 | |
| 9757 | scoped_ptr<HttpTransaction> trans( |
| 9758 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 9759 | |
| 9760 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 9761 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9762 | |
| 9763 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9764 | |
| 9765 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9766 | ASSERT_TRUE(response != NULL); |
| 9767 | ASSERT_TRUE(response->headers.get() != NULL); |
| 9768 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9769 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9770 | EXPECT_FALSE(response->was_npn_negotiated); |
| 9771 | |
| 9772 | std::string response_data; |
| 9773 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9774 | EXPECT_EQ("hello world", response_data); |
| 9775 | |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 9776 | alternative_service_vector = |
| 9777 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9778 | EXPECT_TRUE(alternative_service_vector.empty()); |
rch | 89c6e10 | 2015-03-18 18:56:52 | [diff] [blame] | 9779 | } |
| 9780 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9781 | TEST_P(HttpNetworkTransactionTest, AltSvcOverwritesAlternateProtocol) { |
| 9782 | session_deps_.next_protos = SpdyNextProtos(); |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9783 | session_deps_.use_alternative_services = true; |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9784 | |
| 9785 | std::string alternative_service_http_header = |
| 9786 | GetAlternativeServiceHttpHeader(); |
| 9787 | std::string alternate_protocol_http_header = GetAlternateProtocolHttpHeader(); |
| 9788 | |
| 9789 | MockRead data_reads[] = { |
| 9790 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9791 | MockRead(alternative_service_http_header.c_str()), |
| 9792 | MockRead(alternate_protocol_http_header.c_str()), |
| 9793 | MockRead("\r\n"), |
| 9794 | MockRead("hello world"), |
| 9795 | MockRead(SYNCHRONOUS, OK), |
| 9796 | }; |
| 9797 | |
| 9798 | HttpRequestInfo request; |
| 9799 | request.method = "GET"; |
| 9800 | request.url = GURL("http://www.example.org/"); |
| 9801 | request.load_flags = 0; |
| 9802 | |
| 9803 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 9804 | |
| 9805 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9806 | |
| 9807 | TestCompletionCallback callback; |
| 9808 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9809 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9810 | scoped_ptr<HttpTransaction> trans( |
| 9811 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 9812 | |
| 9813 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 9814 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9815 | |
| 9816 | HostPortPair http_host_port_pair("www.example.org", 80); |
| 9817 | HttpServerProperties& http_server_properties = |
| 9818 | *session->http_server_properties(); |
| 9819 | AlternativeServiceVector alternative_service_vector = |
| 9820 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9821 | EXPECT_TRUE(alternative_service_vector.empty()); |
| 9822 | |
| 9823 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9824 | |
| 9825 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9826 | ASSERT_TRUE(response != NULL); |
| 9827 | ASSERT_TRUE(response->headers.get() != NULL); |
| 9828 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9829 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 9830 | EXPECT_FALSE(response->was_npn_negotiated); |
| 9831 | |
| 9832 | std::string response_data; |
| 9833 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9834 | EXPECT_EQ("hello world", response_data); |
| 9835 | |
| 9836 | alternative_service_vector = |
| 9837 | http_server_properties.GetAlternativeServices(http_host_port_pair); |
| 9838 | ASSERT_EQ(1u, alternative_service_vector.size()); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 9839 | EXPECT_EQ(AlternateProtocolFromNextProto(GetProtocol()), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 9840 | alternative_service_vector[0].protocol); |
| 9841 | EXPECT_EQ("www.example.com", alternative_service_vector[0].host); |
| 9842 | EXPECT_EQ(443, alternative_service_vector[0].port); |
| 9843 | } |
| 9844 | |
bnc | 54ec34b7 | 2015-08-26 19:34:56 | [diff] [blame] | 9845 | // When |use_alternative_services| is false, do not observe alternative service |
| 9846 | // entries that point to a different host. |
| 9847 | TEST_P(HttpNetworkTransactionTest, DisableAlternativeServiceToDifferentHost) { |
| 9848 | session_deps_.use_alternative_services = false; |
| 9849 | |
| 9850 | HttpRequestInfo request; |
| 9851 | request.method = "GET"; |
| 9852 | request.url = GURL("http://www.example.org/"); |
| 9853 | request.load_flags = 0; |
| 9854 | |
| 9855 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 9856 | StaticSocketDataProvider first_data; |
| 9857 | first_data.set_connect_data(mock_connect); |
| 9858 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
| 9859 | |
| 9860 | MockRead data_reads[] = { |
| 9861 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 9862 | MockRead(ASYNC, OK), |
| 9863 | }; |
| 9864 | StaticSocketDataProvider second_data(data_reads, arraysize(data_reads), |
| 9865 | nullptr, 0); |
| 9866 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 9867 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9868 | scoped_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
bnc | 54ec34b7 | 2015-08-26 19:34:56 | [diff] [blame] | 9869 | |
| 9870 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 9871 | session->http_server_properties(); |
| 9872 | AlternativeService alternative_service( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 9873 | AlternateProtocolFromNextProto(GetProtocol()), "different.example.org", |
| 9874 | 80); |
bnc | 54ec34b7 | 2015-08-26 19:34:56 | [diff] [blame] | 9875 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 9876 | http_server_properties->SetAlternativeService( |
| 9877 | HostPortPair::FromURL(request.url), alternative_service, 1.0, expiration); |
| 9878 | |
| 9879 | scoped_ptr<HttpTransaction> trans( |
| 9880 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 9881 | TestCompletionCallback callback; |
| 9882 | |
| 9883 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 9884 | // The connetion to origin was refused, and the alternative service should not |
| 9885 | // be used (even though mock data are there), therefore the request should |
| 9886 | // fail. |
| 9887 | EXPECT_EQ(ERR_CONNECTION_REFUSED, callback.GetResult(rv)); |
| 9888 | } |
| 9889 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9890 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9891 | MarkBrokenAlternateProtocolAndFallback) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9892 | session_deps_.use_alternative_services = true; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9893 | |
| 9894 | HttpRequestInfo request; |
| 9895 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9896 | request.url = GURL("http://www.example.org/"); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9897 | request.load_flags = 0; |
| 9898 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 9899 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9900 | StaticSocketDataProvider first_data; |
| 9901 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9902 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9903 | |
| 9904 | MockRead data_reads[] = { |
| 9905 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 9906 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9907 | MockRead(ASYNC, OK), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9908 | }; |
| 9909 | StaticSocketDataProvider second_data( |
| 9910 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9911 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9912 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9913 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9914 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 9915 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 9916 | session->http_server_properties(); |
bnc | 8445b300 | 2015-03-13 01:57:09 | [diff] [blame] | 9917 | const HostPortPair host_port_pair = HostPortPair::FromURL(request.url); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9918 | // Port must be < 1024, or the header will be ignored (since initial port was |
| 9919 | // port 80 (another restricted port). |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 9920 | const AlternativeService alternative_service( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 9921 | AlternateProtocolFromNextProto(GetProtocol()), "www.example.org", |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 9922 | 666); // Port is ignored by MockConnect anyway. |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9923 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 9924 | http_server_properties->SetAlternativeService( |
| 9925 | host_port_pair, alternative_service, 1.0, expiration); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9926 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9927 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9928 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9929 | TestCompletionCallback callback; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9930 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9931 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9932 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 9933 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 9934 | |
| 9935 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9936 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9937 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9938 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 9939 | |
| 9940 | std::string response_data; |
| 9941 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 9942 | EXPECT_EQ("hello world", response_data); |
| 9943 | |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 9944 | const AlternativeServiceVector alternative_service_vector = |
| 9945 | http_server_properties->GetAlternativeServices(host_port_pair); |
| 9946 | ASSERT_EQ(1u, alternative_service_vector.size()); |
| 9947 | EXPECT_EQ(alternative_service, alternative_service_vector[0]); |
| 9948 | EXPECT_TRUE(http_server_properties->IsAlternativeServiceBroken( |
| 9949 | alternative_service_vector[0])); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 9950 | } |
| 9951 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9952 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 9953 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 9954 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 9955 | // cases. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9956 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9957 | AlternateProtocolPortRestrictedBlocked) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 9958 | session_deps_.use_alternative_services = true; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9959 | |
| 9960 | HttpRequestInfo restricted_port_request; |
| 9961 | restricted_port_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9962 | restricted_port_request.url = GURL("http://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9963 | restricted_port_request.load_flags = 0; |
| 9964 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 9965 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9966 | StaticSocketDataProvider first_data; |
| 9967 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9968 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9969 | |
| 9970 | MockRead data_reads[] = { |
| 9971 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 9972 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9973 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9974 | }; |
| 9975 | StaticSocketDataProvider second_data( |
| 9976 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9977 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9978 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9979 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9980 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 9981 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 9982 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9983 | const int kUnrestrictedAlternatePort = 1024; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9984 | AlternativeService alternative_service( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 9985 | AlternateProtocolFromNextProto(GetProtocol()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9986 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9987 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9988 | http_server_properties->SetAlternativeService( |
| 9989 | HostPortPair::FromURL(restricted_port_request.url), alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9990 | 1.0, expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9991 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9992 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9993 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9994 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9995 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9996 | int rv = trans->Start( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 9997 | &restricted_port_request, |
| 9998 | callback.callback(), BoundNetLog()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 9999 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10000 | // Invalid change to unrestricted port should fail. |
| 10001 | EXPECT_EQ(ERR_CONNECTION_REFUSED, callback.WaitForResult()); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10002 | } |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10003 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10004 | // Ensure that we are allowed to redirect traffic via an alternate protocol to |
| 10005 | // an unrestricted (port >= 1024) when the original traffic was on a restricted |
| 10006 | // port (port < 1024) if we set |enable_user_alternate_protocol_ports|. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10007 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10008 | AlternateProtocolPortRestrictedPermitted) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10009 | session_deps_.use_alternative_services = true; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10010 | session_deps_.enable_user_alternate_protocol_ports = true; |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10011 | |
| 10012 | HttpRequestInfo restricted_port_request; |
| 10013 | restricted_port_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10014 | restricted_port_request.url = GURL("http://www.example.org:1023/"); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10015 | restricted_port_request.load_flags = 0; |
| 10016 | |
| 10017 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 10018 | StaticSocketDataProvider first_data; |
| 10019 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10020 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10021 | |
| 10022 | MockRead data_reads[] = { |
| 10023 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10024 | MockRead("hello world"), |
| 10025 | MockRead(ASYNC, OK), |
| 10026 | }; |
| 10027 | StaticSocketDataProvider second_data( |
| 10028 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10029 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10030 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10031 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10032 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 10033 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10034 | session->http_server_properties(); |
| 10035 | const int kUnrestrictedAlternatePort = 1024; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10036 | AlternativeService alternative_service( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 10037 | AlternateProtocolFromNextProto(GetProtocol()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10038 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10039 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10040 | http_server_properties->SetAlternativeService( |
| 10041 | HostPortPair::FromURL(restricted_port_request.url), alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10042 | 1.0, expiration); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10043 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10044 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10045 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10046 | TestCompletionCallback callback; |
| 10047 | |
| 10048 | EXPECT_EQ(ERR_IO_PENDING, trans->Start( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10049 | &restricted_port_request, |
| 10050 | callback.callback(), BoundNetLog())); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10051 | // Change to unrestricted port should succeed. |
| 10052 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10053 | } |
| 10054 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10055 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10056 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 10057 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 10058 | // cases. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10059 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 10060 | AlternateProtocolPortRestrictedAllowed) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10061 | session_deps_.use_alternative_services = true; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10062 | |
| 10063 | HttpRequestInfo restricted_port_request; |
| 10064 | restricted_port_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10065 | restricted_port_request.url = GURL("http://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10066 | restricted_port_request.load_flags = 0; |
| 10067 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10068 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10069 | StaticSocketDataProvider first_data; |
| 10070 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10071 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10072 | |
| 10073 | MockRead data_reads[] = { |
| 10074 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10075 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10076 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10077 | }; |
| 10078 | StaticSocketDataProvider second_data( |
| 10079 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10080 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10081 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10082 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10083 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 10084 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10085 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10086 | const int kRestrictedAlternatePort = 80; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10087 | AlternativeService alternative_service( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 10088 | AlternateProtocolFromNextProto(GetProtocol()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10089 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10090 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10091 | http_server_properties->SetAlternativeService( |
| 10092 | HostPortPair::FromURL(restricted_port_request.url), alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10093 | 1.0, expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10094 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10095 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10096 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10097 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10098 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10099 | int rv = trans->Start( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10100 | &restricted_port_request, |
| 10101 | callback.callback(), BoundNetLog()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10102 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10103 | // Valid change to restricted port should pass. |
| 10104 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10105 | } |
| 10106 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10107 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10108 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 10109 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 10110 | // cases. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10111 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 10112 | AlternateProtocolPortUnrestrictedAllowed1) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10113 | session_deps_.use_alternative_services = true; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10114 | |
| 10115 | HttpRequestInfo unrestricted_port_request; |
| 10116 | unrestricted_port_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10117 | unrestricted_port_request.url = GURL("http://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10118 | unrestricted_port_request.load_flags = 0; |
| 10119 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10120 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10121 | StaticSocketDataProvider first_data; |
| 10122 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10123 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10124 | |
| 10125 | MockRead data_reads[] = { |
| 10126 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10127 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10128 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10129 | }; |
| 10130 | StaticSocketDataProvider second_data( |
| 10131 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10132 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10133 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10134 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10135 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 10136 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10137 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10138 | const int kRestrictedAlternatePort = 80; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10139 | AlternativeService alternative_service( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 10140 | AlternateProtocolFromNextProto(GetProtocol()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10141 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10142 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10143 | http_server_properties->SetAlternativeService( |
| 10144 | HostPortPair::FromURL(unrestricted_port_request.url), alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10145 | 1.0, expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10146 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10147 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10148 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10149 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10150 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10151 | int rv = trans->Start( |
| 10152 | &unrestricted_port_request, callback.callback(), BoundNetLog()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10153 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10154 | // Valid change to restricted port should pass. |
| 10155 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10156 | } |
| 10157 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10158 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10159 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 10160 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 10161 | // cases. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10162 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 10163 | AlternateProtocolPortUnrestrictedAllowed2) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10164 | session_deps_.use_alternative_services = true; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10165 | |
| 10166 | HttpRequestInfo unrestricted_port_request; |
| 10167 | unrestricted_port_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10168 | unrestricted_port_request.url = GURL("http://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10169 | unrestricted_port_request.load_flags = 0; |
| 10170 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10171 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10172 | StaticSocketDataProvider first_data; |
| 10173 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10174 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10175 | |
| 10176 | MockRead data_reads[] = { |
| 10177 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10178 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10179 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10180 | }; |
| 10181 | StaticSocketDataProvider second_data( |
| 10182 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10183 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10184 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10185 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10186 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 10187 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10188 | session->http_server_properties(); |
bnc | 0bbb0262 | 2015-07-23 10:06:22 | [diff] [blame] | 10189 | const int kUnrestrictedAlternatePort = 1025; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10190 | AlternativeService alternative_service( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 10191 | AlternateProtocolFromNextProto(GetProtocol()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10192 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10193 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10194 | http_server_properties->SetAlternativeService( |
| 10195 | HostPortPair::FromURL(unrestricted_port_request.url), alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10196 | 1.0, expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10197 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10198 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10199 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10200 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10201 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10202 | int rv = trans->Start( |
| 10203 | &unrestricted_port_request, callback.callback(), BoundNetLog()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10204 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10205 | // Valid change to an unrestricted port should pass. |
| 10206 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10207 | } |
| 10208 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10209 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10210 | // to an unsafe port, and that we resume the second HttpStreamFactoryImpl::Job |
| 10211 | // once the alternate protocol request fails. |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 10212 | TEST_P(HttpNetworkTransactionTest, AlternateProtocolUnsafeBlocked) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10213 | session_deps_.use_alternative_services = true; |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10214 | |
| 10215 | HttpRequestInfo request; |
| 10216 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10217 | request.url = GURL("http://www.example.org/"); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10218 | request.load_flags = 0; |
| 10219 | |
| 10220 | // The alternate protocol request will error out before we attempt to connect, |
| 10221 | // so only the standard HTTP request will try to connect. |
| 10222 | MockRead data_reads[] = { |
| 10223 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10224 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10225 | MockRead(ASYNC, OK), |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10226 | }; |
| 10227 | StaticSocketDataProvider data( |
| 10228 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10229 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10230 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10231 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10232 | |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 10233 | base::WeakPtr<HttpServerProperties> http_server_properties = |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10234 | session->http_server_properties(); |
| 10235 | const int kUnsafePort = 7; |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10236 | AlternativeService alternative_service( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 10237 | AlternateProtocolFromNextProto(GetProtocol()), "www.example.org", |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10238 | kUnsafePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10239 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10240 | http_server_properties->SetAlternativeService( |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10241 | HostPortPair::FromURL(request.url), alternative_service, 1.0, expiration); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10242 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10243 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10244 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10245 | TestCompletionCallback callback; |
| 10246 | |
| 10247 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 10248 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10249 | // The HTTP request should succeed. |
| 10250 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 10251 | |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10252 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10253 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10254 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10255 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10256 | |
| 10257 | std::string response_data; |
| 10258 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10259 | EXPECT_EQ("hello world", response_data); |
| 10260 | } |
| 10261 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10262 | TEST_P(HttpNetworkTransactionTest, UseAlternateProtocolForNpnSpdy) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10263 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 10264 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10265 | |
| 10266 | HttpRequestInfo request; |
| 10267 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10268 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10269 | request.load_flags = 0; |
| 10270 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 10271 | std::string alternate_protocol_http_header = |
| 10272 | GetAlternateProtocolHttpHeader(); |
| 10273 | |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10274 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10275 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10276 | MockRead(alternate_protocol_http_header.c_str()), |
| 10277 | MockRead("\r\n"), |
| 10278 | MockRead("hello world"), |
| 10279 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 10280 | MockRead(ASYNC, OK)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10281 | |
| 10282 | StaticSocketDataProvider first_transaction( |
| 10283 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10284 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10285 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10286 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 10287 | ssl.SetNextProto(GetProtocol()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10288 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 10289 | ASSERT_TRUE(ssl.cert.get()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10290 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10291 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 10292 | scoped_ptr<SpdyFrame> req( |
| 10293 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10294 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10295 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10296 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 10297 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10298 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10299 | CreateMockRead(*resp, 1), CreateMockRead(*data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10300 | }; |
| 10301 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10302 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 10303 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10304 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10305 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10306 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10307 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 10308 | NULL, 0, NULL, 0); |
| 10309 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 10310 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10311 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10312 | &hanging_non_alternate_protocol_socket); |
| 10313 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10314 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10315 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10316 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10317 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10318 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10319 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10320 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10321 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10322 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 10323 | |
| 10324 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10325 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10326 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10327 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10328 | |
| 10329 | std::string response_data; |
| 10330 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10331 | EXPECT_EQ("hello world", response_data); |
| 10332 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10333 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10334 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10335 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10336 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10337 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 10338 | |
| 10339 | response = trans->GetResponseInfo(); |
| 10340 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10341 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 10342 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10343 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 10344 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10345 | |
| 10346 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10347 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10348 | } |
| 10349 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10350 | TEST_P(HttpNetworkTransactionTest, AlternateProtocolWithSpdyLateBinding) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10351 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 10352 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10353 | |
| 10354 | HttpRequestInfo request; |
| 10355 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10356 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10357 | request.load_flags = 0; |
| 10358 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 10359 | std::string alternate_protocol_http_header = |
| 10360 | GetAlternateProtocolHttpHeader(); |
| 10361 | |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10362 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10363 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10364 | MockRead(alternate_protocol_http_header.c_str()), |
| 10365 | MockRead("\r\n"), |
| 10366 | MockRead("hello world"), |
| 10367 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 10368 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10369 | }; |
| 10370 | |
| 10371 | StaticSocketDataProvider first_transaction( |
| 10372 | data_reads, arraysize(data_reads), NULL, 0); |
| 10373 | // Socket 1 is the HTTP transaction with the Alternate-Protocol header. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10374 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10375 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10376 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10377 | StaticSocketDataProvider hanging_socket( |
| 10378 | NULL, 0, NULL, 0); |
| 10379 | hanging_socket.set_connect_data(never_finishing_connect); |
| 10380 | // Socket 2 and 3 are the hanging Alternate-Protocol and |
| 10381 | // non-Alternate-Protocol jobs from the 2nd transaction. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10382 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket); |
| 10383 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10384 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10385 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 10386 | ssl.SetNextProto(GetProtocol()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10387 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 10388 | ASSERT_TRUE(ssl.cert.get()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10389 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10390 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 10391 | scoped_ptr<SpdyFrame> req1( |
| 10392 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 10393 | scoped_ptr<SpdyFrame> req2( |
| 10394 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, LOWEST, true)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10395 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10396 | CreateMockWrite(*req1, 0), CreateMockWrite(*req2, 1), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10397 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10398 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 10399 | scoped_ptr<SpdyFrame> data1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 10400 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 10401 | scoped_ptr<SpdyFrame> data2(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10402 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10403 | CreateMockRead(*resp1, 2), |
| 10404 | CreateMockRead(*data1, 3), |
| 10405 | CreateMockRead(*resp2, 4), |
| 10406 | CreateMockRead(*data2, 5), |
| 10407 | MockRead(ASYNC, 0, 6), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10408 | }; |
| 10409 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10410 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 10411 | arraysize(spdy_writes)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10412 | // Socket 4 is the successful Alternate-Protocol for transaction 3. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10413 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10414 | |
| 10415 | // Socket 5 is the unsuccessful non-Alternate-Protocol for transaction 3. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10416 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10417 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10418 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10419 | TestCompletionCallback callback1; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10420 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10421 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10422 | int rv = trans1.Start(&request, callback1.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10423 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10424 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 10425 | |
| 10426 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 10427 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10428 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10429 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10430 | |
| 10431 | std::string response_data; |
| 10432 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); |
| 10433 | EXPECT_EQ("hello world", response_data); |
| 10434 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10435 | TestCompletionCallback callback2; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10436 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10437 | rv = trans2.Start(&request, callback2.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10438 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10439 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10440 | TestCompletionCallback callback3; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10441 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10442 | rv = trans3.Start(&request, callback3.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10443 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10444 | |
| 10445 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 10446 | EXPECT_EQ(OK, callback3.WaitForResult()); |
| 10447 | |
| 10448 | response = trans2.GetResponseInfo(); |
| 10449 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10450 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 10451 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10452 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 10453 | EXPECT_TRUE(response->was_npn_negotiated); |
| 10454 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 10455 | EXPECT_EQ("hello!", response_data); |
| 10456 | |
| 10457 | response = trans3.GetResponseInfo(); |
| 10458 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10459 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 10460 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10461 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 10462 | EXPECT_TRUE(response->was_npn_negotiated); |
| 10463 | ASSERT_EQ(OK, ReadTransaction(&trans3, &response_data)); |
| 10464 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10465 | } |
| 10466 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10467 | TEST_P(HttpNetworkTransactionTest, StallAlternateProtocolForNpnSpdy) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10468 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 10469 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10470 | |
| 10471 | HttpRequestInfo request; |
| 10472 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10473 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10474 | request.load_flags = 0; |
| 10475 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 10476 | std::string alternate_protocol_http_header = |
| 10477 | GetAlternateProtocolHttpHeader(); |
| 10478 | |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10479 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10480 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10481 | MockRead(alternate_protocol_http_header.c_str()), |
| 10482 | MockRead("\r\n"), |
| 10483 | MockRead("hello world"), |
| 10484 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 10485 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10486 | }; |
| 10487 | |
| 10488 | StaticSocketDataProvider first_transaction( |
| 10489 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10490 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10491 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10492 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 10493 | ssl.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10494 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10495 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10496 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10497 | StaticSocketDataProvider hanging_alternate_protocol_socket( |
| 10498 | NULL, 0, NULL, 0); |
| 10499 | hanging_alternate_protocol_socket.set_connect_data( |
| 10500 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10501 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10502 | &hanging_alternate_protocol_socket); |
| 10503 | |
| 10504 | // 2nd request is just a copy of the first one, over HTTP again. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10505 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10506 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10507 | TestCompletionCallback callback; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10508 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10509 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10510 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10511 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10512 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10513 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10514 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10515 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 10516 | |
| 10517 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10518 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10519 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10520 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10521 | |
| 10522 | std::string response_data; |
| 10523 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10524 | EXPECT_EQ("hello world", response_data); |
| 10525 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10526 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10527 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10528 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10529 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10530 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 10531 | |
| 10532 | response = trans->GetResponseInfo(); |
| 10533 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10534 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10535 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10536 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 10537 | EXPECT_FALSE(response->was_npn_negotiated); |
| 10538 | |
| 10539 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10540 | EXPECT_EQ("hello world", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10541 | } |
| 10542 | |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10543 | class CapturingProxyResolver : public ProxyResolver { |
| 10544 | public: |
sammc | e90c921 | 2015-05-27 23:43:35 | [diff] [blame] | 10545 | CapturingProxyResolver() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 10546 | ~CapturingProxyResolver() override {} |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10547 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 10548 | int GetProxyForURL(const GURL& url, |
| 10549 | ProxyInfo* results, |
| 10550 | const CompletionCallback& callback, |
| 10551 | RequestHandle* request, |
| 10552 | const BoundNetLog& net_log) override { |
[email protected] | fae7669f | 2010-08-02 21:49:40 | [diff] [blame] | 10553 | ProxyServer proxy_server(ProxyServer::SCHEME_HTTP, |
| 10554 | HostPortPair("myproxy", 80)); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 10555 | results->UseProxyServer(proxy_server); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10556 | resolved_.push_back(url); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 10557 | return OK; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10558 | } |
| 10559 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 10560 | void CancelRequest(RequestHandle request) override { NOTREACHED(); } |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10561 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 10562 | LoadState GetLoadState(RequestHandle request) const override { |
[email protected] | f2c971f | 2011-11-08 00:33:17 | [diff] [blame] | 10563 | NOTREACHED(); |
| 10564 | return LOAD_STATE_IDLE; |
| 10565 | } |
| 10566 | |
[email protected] | 2447640 | 2010-07-20 20:55:17 | [diff] [blame] | 10567 | const std::vector<GURL>& resolved() const { return resolved_; } |
| 10568 | |
| 10569 | private: |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10570 | std::vector<GURL> resolved_; |
| 10571 | |
| 10572 | DISALLOW_COPY_AND_ASSIGN(CapturingProxyResolver); |
| 10573 | }; |
| 10574 | |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 10575 | class CapturingProxyResolverFactory : public ProxyResolverFactory { |
| 10576 | public: |
| 10577 | explicit CapturingProxyResolverFactory(CapturingProxyResolver* resolver) |
| 10578 | : ProxyResolverFactory(false), resolver_(resolver) {} |
| 10579 | |
| 10580 | int CreateProxyResolver( |
| 10581 | const scoped_refptr<ProxyResolverScriptData>& pac_script, |
| 10582 | scoped_ptr<ProxyResolver>* resolver, |
| 10583 | const net::CompletionCallback& callback, |
| 10584 | scoped_ptr<Request>* request) override { |
| 10585 | resolver->reset(new ForwardingProxyResolver(resolver_)); |
| 10586 | return OK; |
| 10587 | } |
| 10588 | |
| 10589 | private: |
| 10590 | ProxyResolver* resolver_; |
| 10591 | }; |
| 10592 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10593 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 10594 | UseAlternateProtocolForTunneledNpnSpdy) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10595 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 10596 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10597 | |
| 10598 | ProxyConfig proxy_config; |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 10599 | proxy_config.set_auto_detect(true); |
| 10600 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 10601 | |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 10602 | CapturingProxyResolver capturing_proxy_resolver; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10603 | session_deps_.proxy_service.reset(new ProxyService( |
csharrison | b7e3a08 | 2015-09-22 19:13:04 | [diff] [blame] | 10604 | make_scoped_ptr(new ProxyConfigServiceFixed(proxy_config)), |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 10605 | make_scoped_ptr( |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 10606 | new CapturingProxyResolverFactory(&capturing_proxy_resolver)), |
[email protected] | 66761b95 | 2010-06-25 21:30:38 | [diff] [blame] | 10607 | NULL)); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10608 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10609 | session_deps_.net_log = &net_log; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10610 | |
| 10611 | HttpRequestInfo request; |
| 10612 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10613 | request.url = GURL("http://www.example.org/"); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10614 | request.load_flags = 0; |
| 10615 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 10616 | std::string alternate_protocol_http_header = |
| 10617 | GetAlternateProtocolHttpHeader(); |
| 10618 | |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10619 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10620 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10621 | MockRead(alternate_protocol_http_header.c_str()), |
| 10622 | MockRead("\r\n"), |
| 10623 | MockRead("hello world"), |
| 10624 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 10625 | MockRead(ASYNC, OK), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10626 | }; |
| 10627 | |
| 10628 | StaticSocketDataProvider first_transaction( |
| 10629 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10630 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10631 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10632 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 10633 | ssl.SetNextProto(GetProtocol()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10634 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 10635 | ASSERT_TRUE(ssl.cert.get()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10636 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10637 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 10638 | scoped_ptr<SpdyFrame> req( |
| 10639 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10640 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10641 | MockWrite(ASYNC, 0, |
| 10642 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 10643 | "Host: www.example.org:443\r\n" |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10644 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 10645 | CreateMockWrite(*req, 2), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10646 | }; |
| 10647 | |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 10648 | const char kCONNECTResponse[] = "HTTP/1.1 200 Connected\r\n\r\n"; |
| 10649 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10650 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 10651 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10652 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10653 | MockRead(ASYNC, 1, kCONNECTResponse), |
| 10654 | CreateMockRead(*resp.get(), 3), |
| 10655 | CreateMockRead(*data.get(), 4), |
| 10656 | MockRead(ASYNC, ERR_IO_PENDING, 5), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10657 | }; |
| 10658 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10659 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 10660 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10661 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10662 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10663 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10664 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 10665 | NULL, 0, NULL, 0); |
| 10666 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 10667 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10668 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10669 | &hanging_non_alternate_protocol_socket); |
| 10670 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10671 | TestCompletionCallback callback; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10672 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10673 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10674 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10675 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10676 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10677 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10678 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10679 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 10680 | |
| 10681 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10682 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10683 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10684 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10685 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 10686 | EXPECT_FALSE(response->was_npn_negotiated); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10687 | |
| 10688 | std::string response_data; |
| 10689 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10690 | EXPECT_EQ("hello world", response_data); |
| 10691 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10692 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10693 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10694 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10695 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 10696 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 10697 | |
| 10698 | response = trans->GetResponseInfo(); |
| 10699 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10700 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 10701 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10702 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 10703 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10704 | |
| 10705 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10706 | EXPECT_EQ("hello!", response_data); |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 10707 | ASSERT_EQ(3u, capturing_proxy_resolver.resolved().size()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10708 | EXPECT_EQ("http://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 10709 | capturing_proxy_resolver.resolved()[0].spec()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10710 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 10711 | capturing_proxy_resolver.resolved()[1].spec()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10712 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10713 | LoadTimingInfo load_timing_info; |
| 10714 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 10715 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10716 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10717 | } |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 10718 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10719 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10720 | UseAlternateProtocolForNpnSpdyWithExistingSpdySession) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10721 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 10722 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10723 | |
| 10724 | HttpRequestInfo request; |
| 10725 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10726 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10727 | request.load_flags = 0; |
| 10728 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 10729 | std::string alternate_protocol_http_header = |
| 10730 | GetAlternateProtocolHttpHeader(); |
| 10731 | |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10732 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10733 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10734 | MockRead(alternate_protocol_http_header.c_str()), |
| 10735 | MockRead("\r\n"), |
| 10736 | MockRead("hello world"), |
| 10737 | MockRead(ASYNC, OK), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10738 | }; |
| 10739 | |
| 10740 | StaticSocketDataProvider first_transaction( |
| 10741 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10742 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10743 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10744 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 10745 | ssl.SetNextProto(GetProtocol()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10746 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 10747 | ASSERT_TRUE(ssl.cert.get()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10748 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10749 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 10750 | scoped_ptr<SpdyFrame> req( |
| 10751 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10752 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10753 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10754 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 10755 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10756 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10757 | CreateMockRead(*resp, 1), CreateMockRead(*data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10758 | }; |
| 10759 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10760 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 10761 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10762 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10763 | |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 10764 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10765 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10766 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10767 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 10768 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10769 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10770 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10771 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10772 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10773 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10774 | |
| 10775 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10776 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10777 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10778 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10779 | |
| 10780 | std::string response_data; |
| 10781 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10782 | EXPECT_EQ("hello world", response_data); |
| 10783 | |
| 10784 | // Set up an initial SpdySession in the pool to reuse. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10785 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 10786 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 10787 | PRIVACY_MODE_DISABLED); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 10788 | base::WeakPtr<SpdySession> spdy_session = |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10789 | CreateSecureSpdySession(session.get(), key, BoundNetLog()); |
[email protected] | 02b0c34 | 2010-09-25 21:09:38 | [diff] [blame] | 10790 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10791 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10792 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10793 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10794 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10795 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10796 | |
| 10797 | response = trans->GetResponseInfo(); |
| 10798 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10799 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 10800 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10801 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 10802 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10803 | |
| 10804 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 10805 | EXPECT_EQ("hello!", response_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10806 | } |
| 10807 | |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10808 | // GenerateAuthToken is a mighty big test. |
| 10809 | // It tests all permutation of GenerateAuthToken behavior: |
| 10810 | // - Synchronous and Asynchronous completion. |
| 10811 | // - OK or error on completion. |
| 10812 | // - Direct connection, non-authenticating proxy, and authenticating proxy. |
| 10813 | // - HTTP or HTTPS backend (to include proxy tunneling). |
| 10814 | // - Non-authenticating and authenticating backend. |
| 10815 | // |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 10816 | // In all, there are 44 reasonable permuations (for example, if there are |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10817 | // problems generating an auth token for an authenticating proxy, we don't |
| 10818 | // need to test all permutations of the backend server). |
| 10819 | // |
| 10820 | // The test proceeds by going over each of the configuration cases, and |
| 10821 | // potentially running up to three rounds in each of the tests. The TestConfig |
| 10822 | // specifies both the configuration for the test as well as the expectations |
| 10823 | // for the results. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10824 | TEST_P(HttpNetworkTransactionTest, GenerateAuthToken) { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 10825 | static const char kServer[] = "http://www.example.com"; |
| 10826 | static const char kSecureServer[] = "https://www.example.com"; |
| 10827 | static const char kProxy[] = "myproxy:70"; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10828 | const int kAuthErr = ERR_INVALID_AUTH_CREDENTIALS; |
| 10829 | |
| 10830 | enum AuthTiming { |
| 10831 | AUTH_NONE, |
| 10832 | AUTH_SYNC, |
| 10833 | AUTH_ASYNC, |
| 10834 | }; |
| 10835 | |
| 10836 | const MockWrite kGet( |
| 10837 | "GET / HTTP/1.1\r\n" |
| 10838 | "Host: www.example.com\r\n" |
| 10839 | "Connection: keep-alive\r\n\r\n"); |
| 10840 | const MockWrite kGetProxy( |
| 10841 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 10842 | "Host: www.example.com\r\n" |
| 10843 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 10844 | const MockWrite kGetAuth( |
| 10845 | "GET / HTTP/1.1\r\n" |
| 10846 | "Host: www.example.com\r\n" |
| 10847 | "Connection: keep-alive\r\n" |
| 10848 | "Authorization: auth_token\r\n\r\n"); |
| 10849 | const MockWrite kGetProxyAuth( |
| 10850 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 10851 | "Host: www.example.com\r\n" |
| 10852 | "Proxy-Connection: keep-alive\r\n" |
| 10853 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 10854 | const MockWrite kGetAuthThroughProxy( |
| 10855 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 10856 | "Host: www.example.com\r\n" |
| 10857 | "Proxy-Connection: keep-alive\r\n" |
| 10858 | "Authorization: auth_token\r\n\r\n"); |
| 10859 | const MockWrite kGetAuthWithProxyAuth( |
| 10860 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 10861 | "Host: www.example.com\r\n" |
| 10862 | "Proxy-Connection: keep-alive\r\n" |
| 10863 | "Proxy-Authorization: auth_token\r\n" |
| 10864 | "Authorization: auth_token\r\n\r\n"); |
| 10865 | const MockWrite kConnect( |
| 10866 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 10867 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10868 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 10869 | const MockWrite kConnectProxyAuth( |
| 10870 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 10871 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10872 | "Proxy-Connection: keep-alive\r\n" |
| 10873 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 10874 | |
| 10875 | const MockRead kSuccess( |
| 10876 | "HTTP/1.1 200 OK\r\n" |
| 10877 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 10878 | "Content-Length: 3\r\n\r\n" |
| 10879 | "Yes"); |
| 10880 | const MockRead kFailure( |
| 10881 | "Should not be called."); |
| 10882 | const MockRead kServerChallenge( |
| 10883 | "HTTP/1.1 401 Unauthorized\r\n" |
| 10884 | "WWW-Authenticate: Mock realm=server\r\n" |
| 10885 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 10886 | "Content-Length: 14\r\n\r\n" |
| 10887 | "Unauthorized\r\n"); |
| 10888 | const MockRead kProxyChallenge( |
| 10889 | "HTTP/1.1 407 Unauthorized\r\n" |
| 10890 | "Proxy-Authenticate: Mock realm=proxy\r\n" |
| 10891 | "Proxy-Connection: close\r\n" |
| 10892 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 10893 | "Content-Length: 14\r\n\r\n" |
| 10894 | "Unauthorized\r\n"); |
| 10895 | const MockRead kProxyConnected( |
| 10896 | "HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 10897 | |
| 10898 | // NOTE(cbentzel): I wanted TestReadWriteRound to be a simple struct with |
| 10899 | // no constructors, but the C++ compiler on Windows warns about |
| 10900 | // unspecified data in compound literals. So, moved to using constructors, |
| 10901 | // and TestRound's created with the default constructor should not be used. |
| 10902 | struct TestRound { |
| 10903 | TestRound() |
| 10904 | : expected_rv(ERR_UNEXPECTED), |
| 10905 | extra_write(NULL), |
| 10906 | extra_read(NULL) { |
| 10907 | } |
| 10908 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 10909 | int expected_rv_arg) |
| 10910 | : write(write_arg), |
| 10911 | read(read_arg), |
| 10912 | expected_rv(expected_rv_arg), |
| 10913 | extra_write(NULL), |
| 10914 | extra_read(NULL) { |
| 10915 | } |
| 10916 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 10917 | int expected_rv_arg, const MockWrite* extra_write_arg, |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 10918 | const MockRead* extra_read_arg) |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10919 | : write(write_arg), |
| 10920 | read(read_arg), |
| 10921 | expected_rv(expected_rv_arg), |
| 10922 | extra_write(extra_write_arg), |
| 10923 | extra_read(extra_read_arg) { |
| 10924 | } |
| 10925 | MockWrite write; |
| 10926 | MockRead read; |
| 10927 | int expected_rv; |
| 10928 | const MockWrite* extra_write; |
| 10929 | const MockRead* extra_read; |
| 10930 | }; |
| 10931 | |
| 10932 | static const int kNoSSL = 500; |
| 10933 | |
| 10934 | struct TestConfig { |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 10935 | const char* const proxy_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10936 | AuthTiming proxy_auth_timing; |
| 10937 | int proxy_auth_rv; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 10938 | const char* const server_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 10939 | AuthTiming server_auth_timing; |
| 10940 | int server_auth_rv; |
| 10941 | int num_auth_rounds; |
| 10942 | int first_ssl_round; |
| 10943 | TestRound rounds[3]; |
| 10944 | } test_configs[] = { |
| 10945 | // Non-authenticating HTTP server with a direct connection. |
| 10946 | { NULL, AUTH_NONE, OK, kServer, AUTH_NONE, OK, 1, kNoSSL, |
| 10947 | { TestRound(kGet, kSuccess, OK)}}, |
| 10948 | // Authenticating HTTP server with a direct connection. |
| 10949 | { NULL, AUTH_NONE, OK, kServer, AUTH_SYNC, OK, 2, kNoSSL, |
| 10950 | { TestRound(kGet, kServerChallenge, OK), |
| 10951 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 10952 | { NULL, AUTH_NONE, OK, kServer, AUTH_SYNC, kAuthErr, 2, kNoSSL, |
| 10953 | { TestRound(kGet, kServerChallenge, OK), |
| 10954 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 10955 | { NULL, AUTH_NONE, OK, kServer, AUTH_ASYNC, OK, 2, kNoSSL, |
| 10956 | { TestRound(kGet, kServerChallenge, OK), |
| 10957 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 10958 | { NULL, AUTH_NONE, OK, kServer, AUTH_ASYNC, kAuthErr, 2, kNoSSL, |
| 10959 | { TestRound(kGet, kServerChallenge, OK), |
| 10960 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 10961 | // Non-authenticating HTTP server through a non-authenticating proxy. |
| 10962 | { kProxy, AUTH_NONE, OK, kServer, AUTH_NONE, OK, 1, kNoSSL, |
| 10963 | { TestRound(kGetProxy, kSuccess, OK)}}, |
| 10964 | // Authenticating HTTP server through a non-authenticating proxy. |
| 10965 | { kProxy, AUTH_NONE, OK, kServer, AUTH_SYNC, OK, 2, kNoSSL, |
| 10966 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 10967 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
| 10968 | { kProxy, AUTH_NONE, OK, kServer, AUTH_SYNC, kAuthErr, 2, kNoSSL, |
| 10969 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 10970 | TestRound(kGetAuthThroughProxy, kFailure, kAuthErr)}}, |
| 10971 | { kProxy, AUTH_NONE, OK, kServer, AUTH_ASYNC, OK, 2, kNoSSL, |
| 10972 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 10973 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
| 10974 | { kProxy, AUTH_NONE, OK, kServer, AUTH_ASYNC, kAuthErr, 2, kNoSSL, |
| 10975 | { TestRound(kGetProxy, kServerChallenge, OK), |
| 10976 | TestRound(kGetAuthThroughProxy, kFailure, kAuthErr)}}, |
| 10977 | // Non-authenticating HTTP server through an authenticating proxy. |
| 10978 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 10979 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10980 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
| 10981 | { kProxy, AUTH_SYNC, kAuthErr, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 10982 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10983 | TestRound(kGetProxyAuth, kFailure, kAuthErr)}}, |
| 10984 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 10985 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10986 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
| 10987 | { kProxy, AUTH_ASYNC, kAuthErr, kServer, AUTH_NONE, OK, 2, kNoSSL, |
| 10988 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10989 | TestRound(kGetProxyAuth, kFailure, kAuthErr)}}, |
| 10990 | // Authenticating HTTP server through an authenticating proxy. |
| 10991 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_SYNC, OK, 3, kNoSSL, |
| 10992 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10993 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 10994 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 10995 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_SYNC, kAuthErr, 3, kNoSSL, |
| 10996 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 10997 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 10998 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 10999 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_SYNC, OK, 3, kNoSSL, |
| 11000 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11001 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11002 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 11003 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_SYNC, kAuthErr, 3, kNoSSL, |
| 11004 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11005 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11006 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 11007 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_ASYNC, OK, 3, kNoSSL, |
| 11008 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11009 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11010 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 11011 | { kProxy, AUTH_SYNC, OK, kServer, AUTH_ASYNC, kAuthErr, 3, kNoSSL, |
| 11012 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11013 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11014 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 11015 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_ASYNC, OK, 3, kNoSSL, |
| 11016 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11017 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11018 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 11019 | { kProxy, AUTH_ASYNC, OK, kServer, AUTH_ASYNC, kAuthErr, 3, kNoSSL, |
| 11020 | { TestRound(kGetProxy, kProxyChallenge, OK), |
| 11021 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11022 | TestRound(kGetAuthWithProxyAuth, kFailure, kAuthErr)}}, |
| 11023 | // Non-authenticating HTTPS server with a direct connection. |
| 11024 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_NONE, OK, 1, 0, |
| 11025 | { TestRound(kGet, kSuccess, OK)}}, |
| 11026 | // Authenticating HTTPS server with a direct connection. |
| 11027 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, OK, 2, 0, |
| 11028 | { TestRound(kGet, kServerChallenge, OK), |
| 11029 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11030 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, kAuthErr, 2, 0, |
| 11031 | { TestRound(kGet, kServerChallenge, OK), |
| 11032 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11033 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, OK, 2, 0, |
| 11034 | { TestRound(kGet, kServerChallenge, OK), |
| 11035 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11036 | { NULL, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 2, 0, |
| 11037 | { TestRound(kGet, kServerChallenge, OK), |
| 11038 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11039 | // Non-authenticating HTTPS server with a non-authenticating proxy. |
| 11040 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_NONE, OK, 1, 0, |
| 11041 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 11042 | // Authenticating HTTPS server through a non-authenticating proxy. |
| 11043 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, OK, 2, 0, |
| 11044 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 11045 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11046 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_SYNC, kAuthErr, 2, 0, |
| 11047 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 11048 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11049 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, OK, 2, 0, |
| 11050 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 11051 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11052 | { kProxy, AUTH_NONE, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 2, 0, |
| 11053 | { TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
| 11054 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11055 | // Non-Authenticating HTTPS server through an authenticating proxy. |
| 11056 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_NONE, OK, 2, 1, |
| 11057 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11058 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 11059 | { kProxy, AUTH_SYNC, kAuthErr, kSecureServer, AUTH_NONE, OK, 2, kNoSSL, |
| 11060 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11061 | TestRound(kConnectProxyAuth, kFailure, kAuthErr)}}, |
| 11062 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_NONE, OK, 2, 1, |
| 11063 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11064 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 11065 | { kProxy, AUTH_ASYNC, kAuthErr, kSecureServer, AUTH_NONE, OK, 2, kNoSSL, |
| 11066 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11067 | TestRound(kConnectProxyAuth, kFailure, kAuthErr)}}, |
| 11068 | // Authenticating HTTPS server through an authenticating proxy. |
| 11069 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_SYNC, OK, 3, 1, |
| 11070 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11071 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 11072 | &kGet, &kServerChallenge), |
| 11073 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11074 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_SYNC, kAuthErr, 3, 1, |
| 11075 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11076 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 11077 | &kGet, &kServerChallenge), |
| 11078 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11079 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_SYNC, OK, 3, 1, |
| 11080 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11081 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 11082 | &kGet, &kServerChallenge), |
| 11083 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11084 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_SYNC, kAuthErr, 3, 1, |
| 11085 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11086 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 11087 | &kGet, &kServerChallenge), |
| 11088 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11089 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_ASYNC, OK, 3, 1, |
| 11090 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11091 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 11092 | &kGet, &kServerChallenge), |
| 11093 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11094 | { kProxy, AUTH_SYNC, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 3, 1, |
| 11095 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11096 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 11097 | &kGet, &kServerChallenge), |
| 11098 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11099 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_ASYNC, OK, 3, 1, |
| 11100 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11101 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 11102 | &kGet, &kServerChallenge), |
| 11103 | TestRound(kGetAuth, kSuccess, OK)}}, |
| 11104 | { kProxy, AUTH_ASYNC, OK, kSecureServer, AUTH_ASYNC, kAuthErr, 3, 1, |
| 11105 | { TestRound(kConnect, kProxyChallenge, OK), |
| 11106 | TestRound(kConnectProxyAuth, kProxyConnected, OK, |
| 11107 | &kGet, &kServerChallenge), |
| 11108 | TestRound(kGetAuth, kFailure, kAuthErr)}}, |
| 11109 | }; |
| 11110 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 11111 | for (size_t i = 0; i < arraysize(test_configs); ++i) { |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 11112 | HttpAuthHandlerMock::Factory* auth_factory( |
| 11113 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11114 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11115 | const TestConfig& test_config = test_configs[i]; |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 11116 | |
| 11117 | // Set up authentication handlers as necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11118 | if (test_config.proxy_auth_timing != AUTH_NONE) { |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 11119 | for (int n = 0; n < 2; n++) { |
| 11120 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 11121 | std::string auth_challenge = "Mock realm=proxy"; |
| 11122 | GURL origin(test_config.proxy_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 11123 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 11124 | auth_challenge.end()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 11125 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_PROXY, |
| 11126 | origin, BoundNetLog()); |
| 11127 | auth_handler->SetGenerateExpectation( |
| 11128 | test_config.proxy_auth_timing == AUTH_ASYNC, |
| 11129 | test_config.proxy_auth_rv); |
| 11130 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
| 11131 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11132 | } |
| 11133 | if (test_config.server_auth_timing != AUTH_NONE) { |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 11134 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11135 | std::string auth_challenge = "Mock realm=server"; |
| 11136 | GURL origin(test_config.server_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 11137 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 11138 | auth_challenge.end()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11139 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
| 11140 | origin, BoundNetLog()); |
| 11141 | auth_handler->SetGenerateExpectation( |
| 11142 | test_config.server_auth_timing == AUTH_ASYNC, |
| 11143 | test_config.server_auth_rv); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 11144 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11145 | } |
| 11146 | if (test_config.proxy_url) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 11147 | session_deps_.proxy_service = |
| 11148 | ProxyService::CreateFixed(test_config.proxy_url); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11149 | } else { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 11150 | session_deps_.proxy_service = ProxyService::CreateDirect(); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11151 | } |
| 11152 | |
| 11153 | HttpRequestInfo request; |
| 11154 | request.method = "GET"; |
| 11155 | request.url = GURL(test_config.server_url); |
| 11156 | request.load_flags = 0; |
| 11157 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11158 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 11159 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11160 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11161 | SSLSocketDataProvider ssl_socket_data_provider(SYNCHRONOUS, OK); |
| 11162 | |
| 11163 | std::vector<std::vector<MockRead>> mock_reads(1); |
| 11164 | std::vector<std::vector<MockWrite>> mock_writes(1); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11165 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
| 11166 | const TestRound& read_write_round = test_config.rounds[round]; |
| 11167 | |
| 11168 | // Set up expected reads and writes. |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11169 | mock_reads.back().push_back(read_write_round.read); |
| 11170 | mock_writes.back().push_back(read_write_round.write); |
| 11171 | |
| 11172 | // kProxyChallenge uses Proxy-Connection: close which means that the |
| 11173 | // socket is closed and a new one will be created for the next request. |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 11174 | if (read_write_round.read.data == kProxyChallenge.data) { |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11175 | mock_reads.push_back(std::vector<MockRead>()); |
| 11176 | mock_writes.push_back(std::vector<MockWrite>()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11177 | } |
| 11178 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11179 | if (read_write_round.extra_read) { |
| 11180 | mock_reads.back().push_back(*read_write_round.extra_read); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11181 | } |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11182 | if (read_write_round.extra_write) { |
| 11183 | mock_writes.back().push_back(*read_write_round.extra_write); |
| 11184 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11185 | |
| 11186 | // Add an SSL sequence if necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11187 | if (round >= test_config.first_ssl_round) |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11188 | session_deps_.socket_factory->AddSSLSocketDataProvider( |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11189 | &ssl_socket_data_provider); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11190 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11191 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11192 | ScopedVector<StaticSocketDataProvider> data_providers; |
| 11193 | for (size_t i = 0; i < mock_reads.size(); ++i) { |
| 11194 | data_providers.push_back(new StaticSocketDataProvider( |
davidben | 5f8b6bc | 2015-11-25 03:19:54 | [diff] [blame] | 11195 | mock_reads[i].data(), mock_reads[i].size(), mock_writes[i].data(), |
| 11196 | mock_writes[i].size())); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 11197 | session_deps_.socket_factory->AddSocketDataProvider( |
| 11198 | data_providers.back()); |
| 11199 | } |
| 11200 | |
| 11201 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
| 11202 | const TestRound& read_write_round = test_config.rounds[round]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11203 | // Start or restart the transaction. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11204 | TestCompletionCallback callback; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11205 | int rv; |
| 11206 | if (round == 0) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11207 | rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11208 | } else { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11209 | rv = trans.RestartWithAuth( |
| 11210 | AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11211 | } |
| 11212 | if (rv == ERR_IO_PENDING) |
| 11213 | rv = callback.WaitForResult(); |
| 11214 | |
| 11215 | // Compare results with expected data. |
| 11216 | EXPECT_EQ(read_write_round.expected_rv, rv); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11217 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | c0c82849 | 2015-05-15 01:25:55 | [diff] [blame] | 11218 | if (read_write_round.expected_rv != OK) { |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11219 | EXPECT_EQ(round + 1, test_config.num_auth_rounds); |
| 11220 | continue; |
| 11221 | } |
| 11222 | if (round + 1 < test_config.num_auth_rounds) { |
| 11223 | EXPECT_FALSE(response->auth_challenge.get() == NULL); |
| 11224 | } else { |
| 11225 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 11226 | } |
| 11227 | } |
[email protected] | e5ae96a | 2010-04-14 20:12:45 | [diff] [blame] | 11228 | } |
| 11229 | } |
| 11230 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11231 | TEST_P(HttpNetworkTransactionTest, MultiRoundAuth) { |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11232 | // Do multi-round authentication and make sure it works correctly. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11233 | HttpAuthHandlerMock::Factory* auth_factory( |
| 11234 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11235 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 11236 | session_deps_.proxy_service = ProxyService::CreateDirect(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11237 | session_deps_.host_resolver->rules()->AddRule("www.example.com", "10.0.0.1"); |
| 11238 | session_deps_.host_resolver->set_synchronous_mode(true); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11239 | |
| 11240 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 11241 | auth_handler->set_connection_based(true); |
| 11242 | std::string auth_challenge = "Mock realm=server"; |
| 11243 | GURL origin("http://www.example.com"); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 11244 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 11245 | auth_challenge.end()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11246 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
| 11247 | origin, BoundNetLog()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 11248 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11249 | |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11250 | int rv = OK; |
| 11251 | const HttpResponseInfo* response = NULL; |
| 11252 | HttpRequestInfo request; |
| 11253 | request.method = "GET"; |
| 11254 | request.url = origin; |
| 11255 | request.load_flags = 0; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11256 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11257 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11258 | |
| 11259 | // Use a TCP Socket Pool with only one connection per group. This is used |
| 11260 | // to validate that the TCP socket is not released to the pool between |
| 11261 | // each round of multi-round authentication. |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11262 | HttpNetworkSessionPeer session_peer(session.get()); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 11263 | TransportClientSocketPool* transport_pool = new TransportClientSocketPool( |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11264 | 50, // Max sockets for pool |
| 11265 | 1, // Max sockets per group |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11266 | session_deps_.host_resolver.get(), |
| 11267 | session_deps_.socket_factory.get(), |
| 11268 | session_deps_.net_log); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 11269 | scoped_ptr<MockClientSocketPoolManager> mock_pool_manager( |
| 11270 | new MockClientSocketPoolManager); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 11271 | mock_pool_manager->SetTransportSocketPool(transport_pool); |
dcheng | e3d1ddc | 2014-10-15 19:30:51 | [diff] [blame] | 11272 | session_peer.SetClientSocketPoolManager(mock_pool_manager.Pass()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11273 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11274 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11275 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11276 | TestCompletionCallback callback; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11277 | |
| 11278 | const MockWrite kGet( |
| 11279 | "GET / HTTP/1.1\r\n" |
| 11280 | "Host: www.example.com\r\n" |
| 11281 | "Connection: keep-alive\r\n\r\n"); |
| 11282 | const MockWrite kGetAuth( |
| 11283 | "GET / HTTP/1.1\r\n" |
| 11284 | "Host: www.example.com\r\n" |
| 11285 | "Connection: keep-alive\r\n" |
| 11286 | "Authorization: auth_token\r\n\r\n"); |
| 11287 | |
| 11288 | const MockRead kServerChallenge( |
| 11289 | "HTTP/1.1 401 Unauthorized\r\n" |
| 11290 | "WWW-Authenticate: Mock realm=server\r\n" |
| 11291 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11292 | "Content-Length: 14\r\n\r\n" |
| 11293 | "Unauthorized\r\n"); |
| 11294 | const MockRead kSuccess( |
| 11295 | "HTTP/1.1 200 OK\r\n" |
| 11296 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11297 | "Content-Length: 3\r\n\r\n" |
| 11298 | "Yes"); |
| 11299 | |
| 11300 | MockWrite writes[] = { |
| 11301 | // First round |
| 11302 | kGet, |
| 11303 | // Second round |
| 11304 | kGetAuth, |
| 11305 | // Third round |
| 11306 | kGetAuth, |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 11307 | // Fourth round |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11308 | kGetAuth, |
| 11309 | // Competing request |
| 11310 | kGet, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11311 | }; |
| 11312 | MockRead reads[] = { |
| 11313 | // First round |
| 11314 | kServerChallenge, |
| 11315 | // Second round |
| 11316 | kServerChallenge, |
| 11317 | // Third round |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 11318 | kServerChallenge, |
| 11319 | // Fourth round |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11320 | kSuccess, |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11321 | // Competing response |
| 11322 | kSuccess, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11323 | }; |
| 11324 | StaticSocketDataProvider data_provider(reads, arraysize(reads), |
| 11325 | writes, arraysize(writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11326 | session_deps_.socket_factory->AddSocketDataProvider(&data_provider); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11327 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 11328 | const char kSocketGroup[] = "www.example.com:80"; |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11329 | |
| 11330 | // First round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11331 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11332 | rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11333 | if (rv == ERR_IO_PENDING) |
| 11334 | rv = callback.WaitForResult(); |
| 11335 | EXPECT_EQ(OK, rv); |
| 11336 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 11337 | ASSERT_TRUE(response != NULL); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11338 | EXPECT_FALSE(response->auth_challenge.get() == NULL); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 11339 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11340 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11341 | // In between rounds, another request comes in for the same domain. |
| 11342 | // It should not be able to grab the TCP socket that trans has already |
| 11343 | // claimed. |
| 11344 | scoped_ptr<HttpTransaction> trans_compete( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11345 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11346 | TestCompletionCallback callback_compete; |
| 11347 | rv = trans_compete->Start( |
| 11348 | &request, callback_compete.callback(), BoundNetLog()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11349 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11350 | // callback_compete.WaitForResult at this point would stall forever, |
| 11351 | // since the HttpNetworkTransaction does not release the request back to |
| 11352 | // the pool until after authentication completes. |
| 11353 | |
| 11354 | // Second round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11355 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11356 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11357 | if (rv == ERR_IO_PENDING) |
| 11358 | rv = callback.WaitForResult(); |
| 11359 | EXPECT_EQ(OK, rv); |
| 11360 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 11361 | ASSERT_TRUE(response != NULL); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11362 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 11363 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11364 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11365 | // Third round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11366 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11367 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11368 | if (rv == ERR_IO_PENDING) |
| 11369 | rv = callback.WaitForResult(); |
| 11370 | EXPECT_EQ(OK, rv); |
| 11371 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 11372 | ASSERT_TRUE(response != NULL); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11373 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 11374 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 11375 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11376 | // Fourth round of authentication, which completes successfully. |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 11377 | auth_handler->SetGenerateExpectation(false, OK); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11378 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 11379 | if (rv == ERR_IO_PENDING) |
| 11380 | rv = callback.WaitForResult(); |
| 11381 | EXPECT_EQ(OK, rv); |
| 11382 | response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 11383 | ASSERT_TRUE(response != NULL); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 11384 | EXPECT_TRUE(response->auth_challenge.get() == NULL); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 11385 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11386 | |
| 11387 | // Read the body since the fourth round was successful. This will also |
| 11388 | // release the socket back to the pool. |
| 11389 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(50)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11390 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11391 | if (rv == ERR_IO_PENDING) |
| 11392 | rv = callback.WaitForResult(); |
| 11393 | EXPECT_EQ(3, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11394 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11395 | EXPECT_EQ(0, rv); |
| 11396 | // There are still 0 idle sockets, since the trans_compete transaction |
| 11397 | // will be handed it immediately after trans releases it to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 11398 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11399 | |
| 11400 | // The competing request can now finish. Wait for the headers and then |
| 11401 | // read the body. |
| 11402 | rv = callback_compete.WaitForResult(); |
| 11403 | EXPECT_EQ(OK, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11404 | rv = trans_compete->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11405 | if (rv == ERR_IO_PENDING) |
| 11406 | rv = callback.WaitForResult(); |
| 11407 | EXPECT_EQ(3, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11408 | rv = trans_compete->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 11409 | EXPECT_EQ(0, rv); |
| 11410 | |
| 11411 | // Finally, the socket is released to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 11412 | EXPECT_EQ(1, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 11413 | } |
| 11414 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11415 | // This tests the case that a request is issued via http instead of spdy after |
| 11416 | // npn is negotiated. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11417 | TEST_P(HttpNetworkTransactionTest, NpnWithHttpOverSSL) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11418 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 11419 | NextProtoVector next_protos; |
[email protected] | 0ce3af8 | 2013-07-22 16:17:16 | [diff] [blame] | 11420 | next_protos.push_back(kProtoHTTP11); |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 11421 | session_deps_.next_protos = next_protos; |
| 11422 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11423 | HttpRequestInfo request; |
| 11424 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11425 | request.url = GURL("https://www.example.org/"); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11426 | request.load_flags = 0; |
| 11427 | |
| 11428 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11429 | MockWrite( |
| 11430 | "GET / HTTP/1.1\r\n" |
| 11431 | "Host: www.example.org\r\n" |
| 11432 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11433 | }; |
| 11434 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 11435 | std::string alternate_protocol_http_header = |
| 11436 | GetAlternateProtocolHttpHeader(); |
| 11437 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11438 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11439 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 11440 | MockRead(alternate_protocol_http_header.c_str()), |
| 11441 | MockRead("\r\n"), |
| 11442 | MockRead("hello world"), |
| 11443 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11444 | }; |
| 11445 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11446 | SSLSocketDataProvider ssl(ASYNC, OK); |
davidben | 6974bf7 | 2015-04-27 17:52:48 | [diff] [blame] | 11447 | ssl.SetNextProto(kProtoHTTP11); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11448 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11449 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11450 | |
| 11451 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 11452 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11453 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11454 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11455 | TestCompletionCallback callback; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11456 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11457 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11458 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11459 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11460 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11461 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11462 | |
| 11463 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11464 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 11465 | |
| 11466 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 11467 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11468 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11469 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11470 | |
| 11471 | std::string response_data; |
| 11472 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 11473 | EXPECT_EQ("hello world", response_data); |
| 11474 | |
| 11475 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 11476 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11477 | } |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11478 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11479 | // Simulate the SSL handshake completing with an NPN negotiation followed by an |
| 11480 | // immediate server closing of the socket. |
| 11481 | // Regression test for https://crbug.com/46369. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11482 | TEST_P(HttpNetworkTransactionTest, SpdyPostNPNServerHangup) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11483 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 11484 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11485 | |
| 11486 | HttpRequestInfo request; |
| 11487 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11488 | request.url = GURL("https://www.example.org/"); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11489 | request.load_flags = 0; |
| 11490 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11491 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 11492 | ssl.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11493 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11494 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11495 | scoped_ptr<SpdyFrame> req( |
| 11496 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11497 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 1)}; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11498 | |
| 11499 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11500 | MockRead(SYNCHRONOUS, 0, 0) // Not async - return 0 immediately. |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11501 | }; |
| 11502 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11503 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 11504 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11505 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11506 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11507 | TestCompletionCallback callback; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11508 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11509 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11510 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11511 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11512 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11513 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11514 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11515 | EXPECT_EQ(ERR_CONNECTION_CLOSED, callback.WaitForResult()); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 11516 | } |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 11517 | |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 11518 | // A subclass of HttpAuthHandlerMock that records the request URL when |
| 11519 | // it gets it. This is needed since the auth handler may get destroyed |
| 11520 | // before we get a chance to query it. |
| 11521 | class UrlRecordingHttpAuthHandlerMock : public HttpAuthHandlerMock { |
| 11522 | public: |
| 11523 | explicit UrlRecordingHttpAuthHandlerMock(GURL* url) : url_(url) {} |
| 11524 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11525 | ~UrlRecordingHttpAuthHandlerMock() override {} |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 11526 | |
| 11527 | protected: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11528 | int GenerateAuthTokenImpl(const AuthCredentials* credentials, |
| 11529 | const HttpRequestInfo* request, |
| 11530 | const CompletionCallback& callback, |
| 11531 | std::string* auth_token) override { |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 11532 | *url_ = request->url; |
| 11533 | return HttpAuthHandlerMock::GenerateAuthTokenImpl( |
| 11534 | credentials, request, callback, auth_token); |
| 11535 | } |
| 11536 | |
| 11537 | private: |
| 11538 | GURL* url_; |
| 11539 | }; |
| 11540 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11541 | // This test ensures that the URL passed into the proxy is upgraded to https |
| 11542 | // when doing an Alternate Protocol upgrade. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11543 | TEST_P(HttpNetworkTransactionTest, SpdyAlternateProtocolThroughProxy) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11544 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 11545 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11546 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 11547 | session_deps_.proxy_service = |
| 11548 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11549 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11550 | session_deps_.net_log = &net_log; |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 11551 | GURL request_url; |
| 11552 | { |
| 11553 | HttpAuthHandlerMock::Factory* auth_factory = |
| 11554 | new HttpAuthHandlerMock::Factory(); |
| 11555 | UrlRecordingHttpAuthHandlerMock* auth_handler = |
| 11556 | new UrlRecordingHttpAuthHandlerMock(&request_url); |
| 11557 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
| 11558 | auth_factory->set_do_init_from_challenge(true); |
| 11559 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
| 11560 | } |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11561 | |
| 11562 | HttpRequestInfo request; |
| 11563 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11564 | request.url = GURL("http://www.example.org"); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11565 | request.load_flags = 0; |
| 11566 | |
| 11567 | // First round goes unauthenticated through the proxy. |
| 11568 | MockWrite data_writes_1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11569 | MockWrite( |
| 11570 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 11571 | "Host: www.example.org\r\n" |
| 11572 | "Proxy-Connection: keep-alive\r\n" |
| 11573 | "\r\n"), |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11574 | }; |
| 11575 | MockRead data_reads_1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11576 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
bnc | 33b8cef4 | 2014-11-19 17:30:38 | [diff] [blame] | 11577 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 11578 | MockRead("Alternate-Protocol: 443:"), |
| 11579 | MockRead(GetAlternateProtocolFromParam()), |
| 11580 | MockRead("\r\n"), |
| 11581 | MockRead("Proxy-Connection: close\r\n"), |
| 11582 | MockRead("\r\n"), |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11583 | }; |
| 11584 | StaticSocketDataProvider data_1(data_reads_1, arraysize(data_reads_1), |
| 11585 | data_writes_1, arraysize(data_writes_1)); |
| 11586 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11587 | // Second round tries to tunnel to www.example.org due to the |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11588 | // Alternate-Protocol announcement in the first round. It fails due |
| 11589 | // to a proxy authentication challenge. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11590 | // After the failure, a tunnel is established to www.example.org using |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 11591 | // Proxy-Authorization headers. There is then a SPDY request round. |
| 11592 | // |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 11593 | // NOTE: Despite the "Proxy-Connection: Close", these are done on the |
| 11594 | // same MockTCPClientSocket since the underlying HttpNetworkClientSocket |
| 11595 | // does a Disconnect and Connect on the same socket, rather than trying |
| 11596 | // to obtain a new one. |
| 11597 | // |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 11598 | // NOTE: Originally, the proxy response to the second CONNECT request |
| 11599 | // simply returned another 407 so the unit test could skip the SSL connection |
| 11600 | // establishment and SPDY framing issues. Alas, the |
| 11601 | // retry-http-when-alternate-protocol fails logic kicks in, which was more |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11602 | // complicated to set up expectations for than the SPDY session. |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 11603 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 11604 | scoped_ptr<SpdyFrame> req( |
| 11605 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11606 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11607 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11608 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 11609 | MockWrite data_writes_2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11610 | // First connection attempt without Proxy-Authorization. |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11611 | MockWrite(ASYNC, 0, |
| 11612 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 11613 | "Host: www.example.org:443\r\n" |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11614 | "Proxy-Connection: keep-alive\r\n" |
| 11615 | "\r\n"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 11616 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11617 | // Second connection attempt with Proxy-Authorization. |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11618 | MockWrite(ASYNC, 2, |
| 11619 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 11620 | "Host: www.example.org:443\r\n" |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11621 | "Proxy-Connection: keep-alive\r\n" |
| 11622 | "Proxy-Authorization: auth_token\r\n" |
| 11623 | "\r\n"), |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11624 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11625 | // SPDY request |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11626 | CreateMockWrite(*req, 4), |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11627 | }; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 11628 | MockRead data_reads_2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11629 | // First connection attempt fails |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 11630 | MockRead(ASYNC, 1, |
| 11631 | "HTTP/1.1 407 Unauthorized\r\n" |
| 11632 | "Proxy-Authenticate: Mock\r\n" |
| 11633 | "Content-Length: 0\r\n" |
| 11634 | "Proxy-Connection: keep-alive\r\n" |
| 11635 | "\r\n"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 11636 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11637 | // Second connection attempt passes |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 11638 | MockRead(ASYNC, 3, "HTTP/1.1 200 Connected\r\n\r\n"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 11639 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11640 | // SPDY response |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 11641 | CreateMockRead(*resp.get(), 5), CreateMockRead(*data.get(), 6), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11642 | MockRead(ASYNC, 0, 0, 7), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 11643 | }; |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11644 | SequencedSocketData data_2(data_reads_2, arraysize(data_reads_2), |
| 11645 | data_writes_2, arraysize(data_writes_2)); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11646 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11647 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 11648 | ssl.SetNextProto(GetProtocol()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11649 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 11650 | ASSERT_TRUE(ssl.cert.get()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11651 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11652 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11653 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 11654 | NULL, 0, NULL, 0); |
| 11655 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 11656 | never_finishing_connect); |
| 11657 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11658 | session_deps_.socket_factory->AddSocketDataProvider(&data_1); |
| 11659 | session_deps_.socket_factory->AddSocketDataProvider(&data_2); |
| 11660 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11661 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11662 | &hanging_non_alternate_protocol_socket); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11663 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11664 | |
| 11665 | // First round should work and provide the Alternate-Protocol state. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11666 | TestCompletionCallback callback_1; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11667 | scoped_ptr<HttpTransaction> trans_1( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11668 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11669 | int rv = trans_1->Start(&request, callback_1.callback(), BoundNetLog()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11670 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11671 | EXPECT_EQ(OK, callback_1.WaitForResult()); |
| 11672 | |
| 11673 | // Second round should attempt a tunnel connect and get an auth challenge. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11674 | TestCompletionCallback callback_2; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11675 | scoped_ptr<HttpTransaction> trans_2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11676 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11677 | rv = trans_2->Start(&request, callback_2.callback(), BoundNetLog()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11678 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11679 | EXPECT_EQ(OK, callback_2.WaitForResult()); |
| 11680 | const HttpResponseInfo* response = trans_2->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 11681 | ASSERT_TRUE(response != NULL); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11682 | ASSERT_FALSE(response->auth_challenge.get() == NULL); |
| 11683 | |
| 11684 | // Restart with auth. Tunnel should work and response received. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11685 | TestCompletionCallback callback_3; |
| 11686 | rv = trans_2->RestartWithAuth( |
| 11687 | AuthCredentials(kFoo, kBar), callback_3.callback()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11688 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11689 | EXPECT_EQ(OK, callback_3.WaitForResult()); |
| 11690 | |
| 11691 | // After all that work, these two lines (or actually, just the scheme) are |
| 11692 | // what this test is all about. Make sure it happens correctly. |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11693 | EXPECT_EQ("https", request_url.scheme()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11694 | EXPECT_EQ("www.example.org", request_url.host()); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11695 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11696 | LoadTimingInfo load_timing_info; |
| 11697 | EXPECT_TRUE(trans_2->GetLoadTimingInfo(&load_timing_info)); |
| 11698 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 11699 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 11700 | } |
| 11701 | |
| 11702 | // Test that if we cancel the transaction as the connection is completing, that |
| 11703 | // everything tears down correctly. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11704 | TEST_P(HttpNetworkTransactionTest, SimpleCancel) { |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 11705 | // Setup everything about the connection to complete synchronously, so that |
| 11706 | // after calling HttpNetworkTransaction::Start, the only thing we're waiting |
| 11707 | // for is the callback from the HttpStreamRequest. |
| 11708 | // Then cancel the transaction. |
| 11709 | // Verify that we don't crash. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11710 | MockConnect mock_connect(SYNCHRONOUS, OK); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 11711 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11712 | MockRead(SYNCHRONOUS, "HTTP/1.0 200 OK\r\n\r\n"), |
| 11713 | MockRead(SYNCHRONOUS, "hello world"), |
| 11714 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 11715 | }; |
| 11716 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 11717 | HttpRequestInfo request; |
| 11718 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11719 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 11720 | request.load_flags = 0; |
| 11721 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11722 | session_deps_.host_resolver->set_synchronous_mode(true); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11723 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11724 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 11725 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11726 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 11727 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 11728 | data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11729 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 11730 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11731 | TestCompletionCallback callback; |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 11732 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11733 | BoundTestNetLog log; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11734 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 11735 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11736 | trans.reset(); // Cancel the transaction here. |
| 11737 | |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 11738 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 11739 | } |
| 11740 | |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 11741 | // Test that if a transaction is cancelled after receiving the headers, the |
| 11742 | // stream is drained properly and added back to the socket pool. The main |
| 11743 | // purpose of this test is to make sure that an HttpStreamParser can be read |
| 11744 | // from after the HttpNetworkTransaction and the objects it owns have been |
| 11745 | // deleted. |
| 11746 | // See http://crbug.com/368418 |
| 11747 | TEST_P(HttpNetworkTransactionTest, CancelAfterHeaders) { |
| 11748 | MockRead data_reads[] = { |
| 11749 | MockRead(ASYNC, "HTTP/1.1 200 OK\r\n"), |
| 11750 | MockRead(ASYNC, "Content-Length: 2\r\n"), |
| 11751 | MockRead(ASYNC, "Connection: Keep-Alive\r\n\r\n"), |
| 11752 | MockRead(ASYNC, "1"), |
| 11753 | // 2 async reads are necessary to trigger a ReadResponseBody call after the |
| 11754 | // HttpNetworkTransaction has been deleted. |
| 11755 | MockRead(ASYNC, "2"), |
| 11756 | MockRead(SYNCHRONOUS, ERR_IO_PENDING), // Should never read this. |
| 11757 | }; |
| 11758 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 11759 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11760 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11761 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 11762 | |
| 11763 | { |
| 11764 | HttpRequestInfo request; |
| 11765 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11766 | request.url = GURL("http://www.example.org/"); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 11767 | request.load_flags = 0; |
| 11768 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 11769 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 11770 | TestCompletionCallback callback; |
| 11771 | |
| 11772 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
| 11773 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11774 | callback.WaitForResult(); |
| 11775 | |
| 11776 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 11777 | ASSERT_TRUE(response != NULL); |
| 11778 | EXPECT_TRUE(response->headers.get() != NULL); |
| 11779 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11780 | |
| 11781 | // The transaction and HttpRequestInfo are deleted. |
| 11782 | } |
| 11783 | |
| 11784 | // Let the HttpResponseBodyDrainer drain the socket. |
| 11785 | base::MessageLoop::current()->RunUntilIdle(); |
| 11786 | |
| 11787 | // Socket should now be idle, waiting to be reused. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 11788 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 11789 | } |
| 11790 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11791 | // Test a basic GET request through a proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11792 | TEST_P(HttpNetworkTransactionTest, ProxyGet) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 11793 | session_deps_.proxy_service = |
| 11794 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11795 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11796 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11797 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11798 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11799 | HttpRequestInfo request; |
| 11800 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11801 | request.url = GURL("http://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11802 | |
| 11803 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11804 | MockWrite( |
| 11805 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 11806 | "Host: www.example.org\r\n" |
| 11807 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11808 | }; |
| 11809 | |
| 11810 | MockRead data_reads1[] = { |
| 11811 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 11812 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 11813 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11814 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11815 | }; |
| 11816 | |
| 11817 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 11818 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11819 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11820 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11821 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11822 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11823 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11824 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 11825 | BeforeProxyHeadersSentHandler proxy_headers_handler; |
| 11826 | trans->SetBeforeProxyHeadersSentCallback( |
| 11827 | base::Bind(&BeforeProxyHeadersSentHandler::OnBeforeProxyHeadersSent, |
| 11828 | base::Unretained(&proxy_headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11829 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11830 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11831 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11832 | |
| 11833 | rv = callback1.WaitForResult(); |
| 11834 | EXPECT_EQ(OK, rv); |
| 11835 | |
| 11836 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 11837 | ASSERT_TRUE(response != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11838 | |
| 11839 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 11840 | EXPECT_EQ(200, response->headers->response_code()); |
| 11841 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 11842 | EXPECT_TRUE(response->was_fetched_via_proxy); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 11843 | EXPECT_TRUE( |
| 11844 | response->proxy_server.Equals(HostPortPair::FromString("myproxy:70"))); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 11845 | EXPECT_TRUE(proxy_headers_handler.observed_before_proxy_headers_sent()); |
| 11846 | EXPECT_EQ("myproxy:70", proxy_headers_handler.observed_proxy_server_uri()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11847 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11848 | |
| 11849 | LoadTimingInfo load_timing_info; |
| 11850 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 11851 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 11852 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11853 | } |
| 11854 | |
| 11855 | // Test a basic HTTPS GET request through a proxy. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 11856 | TEST_P(HttpNetworkTransactionTest, ProxyTunnelGet) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 11857 | session_deps_.proxy_service = |
| 11858 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11859 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11860 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11861 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11862 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11863 | HttpRequestInfo request; |
| 11864 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11865 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11866 | |
| 11867 | // Since we have proxy, should try to establish tunnel. |
| 11868 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 11869 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 11870 | "Host: www.example.org:443\r\n" |
| 11871 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11872 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 11873 | MockWrite("GET / HTTP/1.1\r\n" |
| 11874 | "Host: www.example.org\r\n" |
| 11875 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11876 | }; |
| 11877 | |
| 11878 | MockRead data_reads1[] = { |
| 11879 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 11880 | |
| 11881 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 11882 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 11883 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11884 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11885 | }; |
| 11886 | |
| 11887 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 11888 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11889 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11890 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11891 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11892 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11893 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11894 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 11895 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11896 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11897 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11898 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11899 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11900 | |
| 11901 | rv = callback1.WaitForResult(); |
| 11902 | EXPECT_EQ(OK, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 11903 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 11904 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11905 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 11906 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11907 | NetLog::PHASE_NONE); |
| 11908 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 11909 | entries, pos, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11910 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 11911 | NetLog::PHASE_NONE); |
| 11912 | |
| 11913 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 11914 | ASSERT_TRUE(response != NULL); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11915 | |
| 11916 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 11917 | EXPECT_EQ(200, response->headers->response_code()); |
| 11918 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 11919 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 11920 | EXPECT_TRUE(response->was_fetched_via_proxy); |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 11921 | EXPECT_TRUE( |
| 11922 | response->proxy_server.Equals(HostPortPair::FromString("myproxy:70"))); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11923 | |
| 11924 | LoadTimingInfo load_timing_info; |
| 11925 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 11926 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 11927 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 11928 | } |
| 11929 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 11930 | // Test a basic HTTPS GET request through a proxy, connecting to an IPv6 |
| 11931 | // literal host. |
| 11932 | TEST_P(HttpNetworkTransactionTest, ProxyTunnelGetIPv6) { |
| 11933 | session_deps_.proxy_service = |
| 11934 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 11935 | BoundTestNetLog log; |
| 11936 | session_deps_.net_log = log.bound().net_log(); |
| 11937 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 11938 | |
| 11939 | HttpRequestInfo request; |
| 11940 | request.method = "GET"; |
| 11941 | request.url = GURL("https://[::1]:443/"); |
| 11942 | |
| 11943 | // Since we have proxy, should try to establish tunnel. |
| 11944 | MockWrite data_writes1[] = { |
| 11945 | MockWrite("CONNECT [::1]:443 HTTP/1.1\r\n" |
| 11946 | "Host: [::1]:443\r\n" |
| 11947 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 11948 | |
| 11949 | MockWrite("GET / HTTP/1.1\r\n" |
| 11950 | "Host: [::1]\r\n" |
| 11951 | "Connection: keep-alive\r\n\r\n"), |
| 11952 | }; |
| 11953 | |
| 11954 | MockRead data_reads1[] = { |
| 11955 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 11956 | |
| 11957 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 11958 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 11959 | MockRead("Content-Length: 100\r\n\r\n"), |
| 11960 | MockRead(SYNCHRONOUS, OK), |
| 11961 | }; |
| 11962 | |
| 11963 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 11964 | data_writes1, arraysize(data_writes1)); |
| 11965 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 11966 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 11967 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11968 | |
| 11969 | TestCompletionCallback callback1; |
| 11970 | |
| 11971 | scoped_ptr<HttpTransaction> trans( |
| 11972 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 11973 | |
| 11974 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
| 11975 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 11976 | |
| 11977 | rv = callback1.WaitForResult(); |
| 11978 | EXPECT_EQ(OK, rv); |
| 11979 | TestNetLogEntry::List entries; |
| 11980 | log.GetEntries(&entries); |
| 11981 | size_t pos = ExpectLogContainsSomewhere( |
| 11982 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 11983 | NetLog::PHASE_NONE); |
| 11984 | ExpectLogContainsSomewhere( |
| 11985 | entries, pos, NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 11986 | NetLog::PHASE_NONE); |
| 11987 | |
| 11988 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 11989 | ASSERT_TRUE(response != NULL); |
| 11990 | |
| 11991 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 11992 | EXPECT_EQ(200, response->headers->response_code()); |
| 11993 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 11994 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 11995 | EXPECT_TRUE(response->was_fetched_via_proxy); |
| 11996 | EXPECT_TRUE( |
| 11997 | response->proxy_server.Equals(HostPortPair::FromString("myproxy:70"))); |
| 11998 | |
| 11999 | LoadTimingInfo load_timing_info; |
| 12000 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 12001 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 12002 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 12003 | } |
| 12004 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12005 | // Test a basic HTTPS GET request through a proxy, but the server hangs up |
| 12006 | // while establishing the tunnel. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12007 | TEST_P(HttpNetworkTransactionTest, ProxyTunnelGetHangup) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12008 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12009 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12010 | session_deps_.net_log = log.bound().net_log(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12011 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12012 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12013 | HttpRequestInfo request; |
| 12014 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12015 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12016 | |
| 12017 | // Since we have proxy, should try to establish tunnel. |
| 12018 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12019 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 12020 | "Host: www.example.org:443\r\n" |
| 12021 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12022 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12023 | MockWrite("GET / HTTP/1.1\r\n" |
| 12024 | "Host: www.example.org\r\n" |
| 12025 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12026 | }; |
| 12027 | |
| 12028 | MockRead data_reads1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12029 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12030 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12031 | MockRead(ASYNC, 0, 0), // EOF |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12032 | }; |
| 12033 | |
| 12034 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 12035 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12036 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12037 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12038 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12039 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12040 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12041 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 12042 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12043 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 12044 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12045 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12046 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12047 | |
| 12048 | rv = callback1.WaitForResult(); |
| 12049 | EXPECT_EQ(ERR_EMPTY_RESPONSE, rv); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 12050 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 12051 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12052 | size_t pos = ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 12053 | entries, 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12054 | NetLog::PHASE_NONE); |
| 12055 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 12056 | entries, pos, |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12057 | NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 12058 | NetLog::PHASE_NONE); |
| 12059 | } |
| 12060 | |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12061 | // Test for crbug.com/55424. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12062 | TEST_P(HttpNetworkTransactionTest, PreconnectWithExistingSpdySession) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12063 | scoped_ptr<SpdyFrame> req( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12064 | spdy_util_.ConstructSpdyGet("https://www.example.org", false, 1, LOWEST)); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12065 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12066 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12067 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12068 | scoped_ptr<SpdyFrame> data(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12069 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12070 | CreateMockRead(*resp, 1), CreateMockRead(*data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12071 | }; |
| 12072 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12073 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 12074 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12075 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12076 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12077 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 12078 | ssl.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12079 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12080 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12081 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12082 | |
| 12083 | // Set up an initial SpdySession in the pool to reuse. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12084 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 12085 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 12086 | PRIVACY_MODE_DISABLED); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 12087 | base::WeakPtr<SpdySession> spdy_session = |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12088 | CreateInsecureSpdySession(session.get(), key, BoundNetLog()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12089 | |
| 12090 | HttpRequestInfo request; |
| 12091 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12092 | request.url = GURL("https://www.example.org/"); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12093 | request.load_flags = 0; |
| 12094 | |
| 12095 | // This is the important line that marks this as a preconnect. |
| 12096 | request.motivation = HttpRequestInfo::PRECONNECT_MOTIVATED; |
| 12097 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 12098 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12099 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12100 | |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 12101 | TestCompletionCallback callback; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12102 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12103 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12104 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 12105 | } |
| 12106 | |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 12107 | // Given a net error, cause that error to be returned from the first Write() |
| 12108 | // call and verify that the HttpTransaction fails with that error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12109 | void HttpNetworkTransactionTest::CheckErrorIsPassedBack( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12110 | int error, IoMode mode) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12111 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12112 | request_info.url = GURL("https://www.example.com/"); |
| 12113 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12114 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12115 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12116 | SSLSocketDataProvider ssl_data(mode, OK); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12117 | MockWrite data_writes[] = { |
| 12118 | MockWrite(mode, error), |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 12119 | }; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12120 | StaticSocketDataProvider data(NULL, 0, data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12121 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12122 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 12123 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12124 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 12125 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12126 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 12127 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12128 | TestCompletionCallback callback; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12129 | int rv = trans->Start(&request_info, callback.callback(), BoundNetLog()); |
| 12130 | if (rv == ERR_IO_PENDING) |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 12131 | rv = callback.WaitForResult(); |
| 12132 | ASSERT_EQ(error, rv); |
| 12133 | } |
| 12134 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12135 | TEST_P(HttpNetworkTransactionTest, SSLWriteCertError) { |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 12136 | // Just check a grab bag of cert errors. |
| 12137 | static const int kErrors[] = { |
| 12138 | ERR_CERT_COMMON_NAME_INVALID, |
| 12139 | ERR_CERT_AUTHORITY_INVALID, |
| 12140 | ERR_CERT_DATE_INVALID, |
| 12141 | }; |
| 12142 | for (size_t i = 0; i < arraysize(kErrors); i++) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12143 | CheckErrorIsPassedBack(kErrors[i], ASYNC); |
| 12144 | CheckErrorIsPassedBack(kErrors[i], SYNCHRONOUS); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 12145 | } |
| 12146 | } |
| 12147 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12148 | // Ensure that a client certificate is removed from the SSL client auth |
| 12149 | // cache when: |
| 12150 | // 1) No proxy is involved. |
| 12151 | // 2) TLS False Start is disabled. |
| 12152 | // 3) The initial TLS handshake requests a client certificate. |
| 12153 | // 4) The client supplies an invalid/unacceptable certificate. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12154 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 12155 | ClientAuthCertCache_Direct_NoFalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12156 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12157 | request_info.url = GURL("https://www.example.com/"); |
| 12158 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12159 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12160 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12161 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12162 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12163 | |
| 12164 | // [ssl_]data1 contains the data for the first SSL handshake. When a |
| 12165 | // CertificateRequest is received for the first time, the handshake will |
| 12166 | // be aborted to allow the caller to provide a certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12167 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12168 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12169 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12170 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12171 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12172 | |
| 12173 | // [ssl_]data2 contains the data for the second SSL handshake. When TLS |
| 12174 | // False Start is not being used, the result of the SSL handshake will be |
| 12175 | // returned as part of the SSLClientSocket::Connect() call. This test |
| 12176 | // matches the result of a server sending a handshake_failure alert, |
| 12177 | // rather than a Finished message, because it requires a client |
| 12178 | // certificate and none was supplied. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12179 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12180 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12181 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12182 | StaticSocketDataProvider data2(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12183 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12184 | |
| 12185 | // [ssl_]data3 contains the data for the third SSL handshake. When a |
| 12186 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 12187 | // HttpNetworkTransaction will attempt to fallback to TLSv1.1 if the previous |
| 12188 | // connection was attempted with TLSv1.2. This is transparent to the caller |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12189 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 12190 | // requiring a client certificate, this fallback handshake should also |
| 12191 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12192 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12193 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12194 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12195 | StaticSocketDataProvider data3(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12196 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12197 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12198 | // [ssl_]data4 contains the data for the fourth SSL handshake. When a |
| 12199 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 12200 | // HttpNetworkTransaction will attempt to fallback to TLSv1 if the previous |
| 12201 | // connection was attempted with TLSv1.1. This is transparent to the caller |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12202 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 12203 | // requiring a client certificate, this fallback handshake should also |
| 12204 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12205 | SSLSocketDataProvider ssl_data4(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12206 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12207 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12208 | StaticSocketDataProvider data4(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12209 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12210 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12211 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 12212 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12213 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12214 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12215 | // Begin the SSL handshake with the peer. This consumes ssl_data1. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12216 | TestCompletionCallback callback; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12217 | int rv = trans->Start(&request_info, callback.callback(), BoundNetLog()); |
| 12218 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12219 | |
| 12220 | // Complete the SSL handshake, which should abort due to requiring a |
| 12221 | // client certificate. |
| 12222 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12223 | ASSERT_EQ(ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12224 | |
| 12225 | // Indicate that no certificate should be supplied. From the perspective |
| 12226 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 12227 | // certificate, so this is the same as supply a |
| 12228 | // legitimate-but-unacceptable certificate. |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12229 | rv = trans->RestartWithCertificate(NULL, NULL, callback.callback()); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12230 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12231 | |
| 12232 | // Ensure the certificate was added to the client auth cache before |
| 12233 | // allowing the connection to continue restarting. |
| 12234 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12235 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12236 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12237 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12238 | ASSERT_EQ(NULL, client_cert.get()); |
| 12239 | |
| 12240 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12241 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 12242 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12243 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12244 | ASSERT_EQ(ERR_SSL_PROTOCOL_ERROR, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12245 | |
| 12246 | // Ensure that the client certificate is removed from the cache on a |
| 12247 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12248 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12249 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12250 | } |
| 12251 | |
| 12252 | // Ensure that a client certificate is removed from the SSL client auth |
| 12253 | // cache when: |
| 12254 | // 1) No proxy is involved. |
| 12255 | // 2) TLS False Start is enabled. |
| 12256 | // 3) The initial TLS handshake requests a client certificate. |
| 12257 | // 4) The client supplies an invalid/unacceptable certificate. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12258 | TEST_P(HttpNetworkTransactionTest, |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 12259 | ClientAuthCertCache_Direct_FalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12260 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12261 | request_info.url = GURL("https://www.example.com/"); |
| 12262 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12263 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12264 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12265 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12266 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12267 | |
| 12268 | // When TLS False Start is used, SSLClientSocket::Connect() calls will |
| 12269 | // return successfully after reading up to the peer's Certificate message. |
| 12270 | // This is to allow the caller to call SSLClientSocket::Write(), which can |
| 12271 | // enqueue application data to be sent in the same packet as the |
| 12272 | // ChangeCipherSpec and Finished messages. |
| 12273 | // The actual handshake will be finished when SSLClientSocket::Read() is |
| 12274 | // called, which expects to process the peer's ChangeCipherSpec and |
| 12275 | // Finished messages. If there was an error negotiating with the peer, |
| 12276 | // such as due to the peer requiring a client certificate when none was |
| 12277 | // supplied, the alert sent by the peer won't be processed until Read() is |
| 12278 | // called. |
| 12279 | |
| 12280 | // Like the non-False Start case, when a client certificate is requested by |
| 12281 | // the peer, the handshake is aborted during the Connect() call. |
| 12282 | // [ssl_]data1 represents the initial SSL handshake with the peer. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12283 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12284 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12285 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12286 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12287 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12288 | |
| 12289 | // When a client certificate is supplied, Connect() will not be aborted |
| 12290 | // when the peer requests the certificate. Instead, the handshake will |
| 12291 | // artificially succeed, allowing the caller to write the HTTP request to |
| 12292 | // the socket. The handshake messages are not processed until Read() is |
| 12293 | // called, which then detects that the handshake was aborted, due to the |
| 12294 | // peer sending a handshake_failure because it requires a client |
| 12295 | // certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12296 | SSLSocketDataProvider ssl_data2(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12297 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12298 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12299 | MockRead data2_reads[] = { |
| 12300 | MockRead(ASYNC /* async */, ERR_SSL_PROTOCOL_ERROR), |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12301 | }; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12302 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12303 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12304 | |
| 12305 | // As described in ClientAuthCertCache_Direct_NoFalseStart, [ssl_]data3 is |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12306 | // the data for the SSL handshake once the TLSv1.1 connection falls back to |
| 12307 | // TLSv1. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12308 | SSLSocketDataProvider ssl_data3(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12309 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12310 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12311 | StaticSocketDataProvider data3(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12312 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12313 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12314 | // [ssl_]data4 is the data for the SSL handshake once the TLSv1 connection |
| 12315 | // falls back to SSLv3. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12316 | SSLSocketDataProvider ssl_data4(ASYNC, OK); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12317 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12318 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12319 | StaticSocketDataProvider data4(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12320 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12321 | |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 12322 | // Need one more if TLSv1.2 is enabled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12323 | SSLSocketDataProvider ssl_data5(ASYNC, OK); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 12324 | ssl_data5.cert_request_info = cert_request.get(); |
| 12325 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data5); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12326 | StaticSocketDataProvider data5(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 12327 | session_deps_.socket_factory->AddSocketDataProvider(&data5); |
| 12328 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12329 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 12330 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12331 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12332 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12333 | // Begin the initial SSL handshake. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12334 | TestCompletionCallback callback; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12335 | int rv = trans->Start(&request_info, callback.callback(), BoundNetLog()); |
| 12336 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12337 | |
| 12338 | // Complete the SSL handshake, which should abort due to requiring a |
| 12339 | // client certificate. |
| 12340 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12341 | ASSERT_EQ(ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12342 | |
| 12343 | // Indicate that no certificate should be supplied. From the perspective |
| 12344 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 12345 | // certificate, so this is the same as supply a |
| 12346 | // legitimate-but-unacceptable certificate. |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12347 | rv = trans->RestartWithCertificate(NULL, NULL, callback.callback()); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12348 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12349 | |
| 12350 | // Ensure the certificate was added to the client auth cache before |
| 12351 | // allowing the connection to continue restarting. |
| 12352 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12353 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12354 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12355 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12356 | ASSERT_EQ(NULL, client_cert.get()); |
| 12357 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12358 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12359 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 12360 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12361 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12362 | ASSERT_EQ(ERR_SSL_PROTOCOL_ERROR, rv); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12363 | |
| 12364 | // Ensure that the client certificate is removed from the cache on a |
| 12365 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12366 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12367 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 12368 | } |
| 12369 | |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12370 | // Ensure that a client certificate is removed from the SSL client auth |
| 12371 | // cache when: |
| 12372 | // 1) An HTTPS proxy is involved. |
| 12373 | // 3) The HTTPS proxy requests a client certificate. |
| 12374 | // 4) The client supplies an invalid/unacceptable certificate for the |
| 12375 | // proxy. |
| 12376 | // The test is repeated twice, first for connecting to an HTTPS endpoint, |
| 12377 | // then for connecting to an HTTP endpoint. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12378 | TEST_P(HttpNetworkTransactionTest, ClientAuthCertCache_Proxy_Fail) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12379 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12380 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12381 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12382 | |
| 12383 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12384 | cert_request->host_and_port = HostPortPair("proxy", 70); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12385 | |
| 12386 | // See ClientAuthCertCache_Direct_NoFalseStart for the explanation of |
| 12387 | // [ssl_]data[1-3]. Rather than represending the endpoint |
| 12388 | // (www.example.com:443), they represent failures with the HTTPS proxy |
| 12389 | // (proxy:70). |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12390 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12391 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12392 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12393 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12394 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12395 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12396 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12397 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12398 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12399 | StaticSocketDataProvider data2(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12400 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12401 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12402 | // TODO(wtc): find out why this unit test doesn't need [ssl_]data3. |
| 12403 | #if 0 |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12404 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12405 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12406 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12407 | StaticSocketDataProvider data3(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12408 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 12409 | #endif |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12410 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12411 | HttpRequestInfo requests[2]; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12412 | requests[0].url = GURL("https://www.example.com/"); |
| 12413 | requests[0].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12414 | requests[0].load_flags = LOAD_NORMAL; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12415 | |
| 12416 | requests[1].url = GURL("http://www.example.com/"); |
| 12417 | requests[1].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12418 | requests[1].load_flags = LOAD_NORMAL; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12419 | |
| 12420 | for (size_t i = 0; i < arraysize(requests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12421 | session_deps_.socket_factory->ResetNextMockIndexes(); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12422 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12423 | scoped_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12424 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12425 | |
| 12426 | // Begin the SSL handshake with the proxy. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12427 | TestCompletionCallback callback; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12428 | int rv = trans->Start(&requests[i], callback.callback(), BoundNetLog()); |
| 12429 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12430 | |
| 12431 | // Complete the SSL handshake, which should abort due to requiring a |
| 12432 | // client certificate. |
| 12433 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12434 | ASSERT_EQ(ERR_SSL_CLIENT_AUTH_CERT_NEEDED, rv); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12435 | |
| 12436 | // Indicate that no certificate should be supplied. From the perspective |
| 12437 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 12438 | // certificate, so this is the same as supply a |
| 12439 | // legitimate-but-unacceptable certificate. |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12440 | rv = trans->RestartWithCertificate(NULL, NULL, callback.callback()); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12441 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12442 | |
| 12443 | // Ensure the certificate was added to the client auth cache before |
| 12444 | // allowing the connection to continue restarting. |
| 12445 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12446 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12447 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12448 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12449 | ASSERT_EQ(NULL, client_cert.get()); |
| 12450 | // Ensure the certificate was NOT cached for the endpoint. This only |
| 12451 | // applies to HTTPS requests, but is fine to check for HTTP requests. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12452 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12453 | HostPortPair("www.example.com", 443), &client_cert, |
| 12454 | &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12455 | |
| 12456 | // Restart the handshake. This will consume ssl_data2, which fails, and |
| 12457 | // then consume ssl_data3, which should also fail. The result code is |
| 12458 | // checked against what ssl_data3 should return. |
| 12459 | rv = callback.WaitForResult(); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12460 | ASSERT_EQ(ERR_PROXY_CONNECTION_FAILED, rv); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12461 | |
| 12462 | // Now that the new handshake has failed, ensure that the client |
| 12463 | // certificate was removed from the client auth cache. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12464 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12465 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 12466 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 12467 | HostPortPair("www.example.com", 443), &client_cert, |
| 12468 | &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 12469 | } |
| 12470 | } |
| 12471 | |
mmenke | 5c64213 | 2015-06-02 16:05:13 | [diff] [blame] | 12472 | TEST_P(HttpNetworkTransactionTest, UseIPConnectionPooling) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12473 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 12474 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12475 | |
| 12476 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12477 | session_deps_.host_resolver.reset(new MockCachingHostResolver()); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12478 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | b9ec688 | 2011-07-01 07:40:26 | [diff] [blame] | 12479 | SpdySessionPoolPeer pool_peer(session->spdy_session_pool()); |
| 12480 | pool_peer.DisableDomainAuthenticationVerification(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12481 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12482 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 12483 | ssl.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12484 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12485 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12486 | scoped_ptr<SpdyFrame> host1_req( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12487 | spdy_util_.ConstructSpdyGet("https://www.example.org", false, 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 12488 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12489 | scoped_ptr<SpdyFrame> host2_req( |
| 12490 | spdy_util_.ConstructSpdyGet("https://www.gmail.com", false, 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12491 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12492 | CreateMockWrite(*host1_req, 0), CreateMockWrite(*host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12493 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12494 | scoped_ptr<SpdyFrame> host1_resp( |
| 12495 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12496 | scoped_ptr<SpdyFrame> host1_resp_body( |
| 12497 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 12498 | scoped_ptr<SpdyFrame> host2_resp( |
| 12499 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 12500 | scoped_ptr<SpdyFrame> host2_resp_body( |
| 12501 | spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12502 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12503 | CreateMockRead(*host1_resp, 1), |
| 12504 | CreateMockRead(*host1_resp_body, 2), |
| 12505 | CreateMockRead(*host2_resp, 4), |
| 12506 | CreateMockRead(*host2_resp_body, 5), |
| 12507 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12508 | }; |
| 12509 | |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12510 | IPAddressNumber ip; |
| 12511 | ASSERT_TRUE(ParseIPLiteralToNumber("127.0.0.1", &ip)); |
| 12512 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 12513 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12514 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 12515 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12516 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12517 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 12518 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12519 | HttpRequestInfo request1; |
| 12520 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12521 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12522 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12523 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12524 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12525 | int rv = trans1.Start(&request1, callback.callback(), BoundNetLog()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12526 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12527 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12528 | |
| 12529 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 12530 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12531 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12532 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12533 | |
| 12534 | std::string response_data; |
| 12535 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); |
| 12536 | EXPECT_EQ("hello!", response_data); |
| 12537 | |
| 12538 | // Preload www.gmail.com into HostCache. |
| 12539 | HostPortPair host_port("www.gmail.com", 443); |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 12540 | HostResolver::RequestInfo resolve_info(host_port); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12541 | AddressList ignored; |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 12542 | rv = session_deps_.host_resolver->Resolve(resolve_info, |
| 12543 | DEFAULT_PRIORITY, |
| 12544 | &ignored, |
| 12545 | callback.callback(), |
| 12546 | NULL, |
| 12547 | BoundNetLog()); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 12548 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12549 | rv = callback.WaitForResult(); |
| 12550 | EXPECT_EQ(OK, rv); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12551 | |
| 12552 | HttpRequestInfo request2; |
| 12553 | request2.method = "GET"; |
| 12554 | request2.url = GURL("https://www.gmail.com/"); |
| 12555 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12556 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12557 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12558 | rv = trans2.Start(&request2, callback.callback(), BoundNetLog()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12559 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12560 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12561 | |
| 12562 | response = trans2.GetResponseInfo(); |
| 12563 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12564 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12565 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12566 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 12567 | EXPECT_TRUE(response->was_npn_negotiated); |
| 12568 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 12569 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12570 | } |
| 12571 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12572 | TEST_P(HttpNetworkTransactionTest, UseIPConnectionPoolingAfterResolution) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12573 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 12574 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12575 | |
| 12576 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12577 | session_deps_.host_resolver.reset(new MockCachingHostResolver()); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12578 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12579 | SpdySessionPoolPeer pool_peer(session->spdy_session_pool()); |
| 12580 | pool_peer.DisableDomainAuthenticationVerification(); |
| 12581 | |
| 12582 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 12583 | ssl.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12584 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12585 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12586 | scoped_ptr<SpdyFrame> host1_req( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12587 | spdy_util_.ConstructSpdyGet("https://www.example.org", false, 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 12588 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12589 | scoped_ptr<SpdyFrame> host2_req( |
| 12590 | spdy_util_.ConstructSpdyGet("https://www.gmail.com", false, 3, LOWEST)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12591 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12592 | CreateMockWrite(*host1_req, 0), CreateMockWrite(*host2_req, 3), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12593 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12594 | scoped_ptr<SpdyFrame> host1_resp( |
| 12595 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12596 | scoped_ptr<SpdyFrame> host1_resp_body( |
| 12597 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 12598 | scoped_ptr<SpdyFrame> host2_resp( |
| 12599 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 12600 | scoped_ptr<SpdyFrame> host2_resp_body( |
| 12601 | spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12602 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12603 | CreateMockRead(*host1_resp, 1), |
| 12604 | CreateMockRead(*host1_resp_body, 2), |
| 12605 | CreateMockRead(*host2_resp, 4), |
| 12606 | CreateMockRead(*host2_resp_body, 5), |
| 12607 | MockRead(ASYNC, 0, 6), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12608 | }; |
| 12609 | |
| 12610 | IPAddressNumber ip; |
| 12611 | ASSERT_TRUE(ParseIPLiteralToNumber("127.0.0.1", &ip)); |
| 12612 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 12613 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12614 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 12615 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12616 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12617 | |
| 12618 | TestCompletionCallback callback; |
| 12619 | HttpRequestInfo request1; |
| 12620 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12621 | request1.url = GURL("https://www.example.org/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12622 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12623 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12624 | |
| 12625 | int rv = trans1.Start(&request1, callback.callback(), BoundNetLog()); |
| 12626 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12627 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 12628 | |
| 12629 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 12630 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12631 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12632 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12633 | |
| 12634 | std::string response_data; |
| 12635 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); |
| 12636 | EXPECT_EQ("hello!", response_data); |
| 12637 | |
| 12638 | HttpRequestInfo request2; |
| 12639 | request2.method = "GET"; |
| 12640 | request2.url = GURL("https://www.gmail.com/"); |
| 12641 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12642 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12643 | |
| 12644 | rv = trans2.Start(&request2, callback.callback(), BoundNetLog()); |
| 12645 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12646 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 12647 | |
| 12648 | response = trans2.GetResponseInfo(); |
| 12649 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12650 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12651 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12652 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 12653 | EXPECT_TRUE(response->was_npn_negotiated); |
| 12654 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 12655 | EXPECT_EQ("hello!", response_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12656 | } |
| 12657 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 12658 | class OneTimeCachingHostResolver : public HostResolver { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12659 | public: |
| 12660 | explicit OneTimeCachingHostResolver(const HostPortPair& host_port) |
| 12661 | : host_port_(host_port) {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12662 | ~OneTimeCachingHostResolver() override {} |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12663 | |
| 12664 | RuleBasedHostResolverProc* rules() { return host_resolver_.rules(); } |
| 12665 | |
| 12666 | // HostResolver methods: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12667 | int Resolve(const RequestInfo& info, |
| 12668 | RequestPriority priority, |
| 12669 | AddressList* addresses, |
| 12670 | const CompletionCallback& callback, |
| 12671 | RequestHandle* out_req, |
| 12672 | const BoundNetLog& net_log) override { |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 12673 | return host_resolver_.Resolve( |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 12674 | info, priority, addresses, callback, out_req, net_log); |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 12675 | } |
| 12676 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12677 | int ResolveFromCache(const RequestInfo& info, |
| 12678 | AddressList* addresses, |
| 12679 | const BoundNetLog& net_log) override { |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 12680 | int rv = host_resolver_.ResolveFromCache(info, addresses, net_log); |
| 12681 | if (rv == OK && info.host_port_pair().Equals(host_port_)) |
[email protected] | 98e1cd01 | 2011-11-08 15:33:09 | [diff] [blame] | 12682 | host_resolver_.GetHostCache()->clear(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12683 | return rv; |
| 12684 | } |
| 12685 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12686 | void CancelRequest(RequestHandle req) override { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12687 | host_resolver_.CancelRequest(req); |
| 12688 | } |
| 12689 | |
[email protected] | 46da33be | 2011-07-19 21:58:04 | [diff] [blame] | 12690 | MockCachingHostResolver* GetMockHostResolver() { |
| 12691 | return &host_resolver_; |
| 12692 | } |
| 12693 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12694 | private: |
| 12695 | MockCachingHostResolver host_resolver_; |
| 12696 | const HostPortPair host_port_; |
| 12697 | }; |
| 12698 | |
mmenke | 5c64213 | 2015-06-02 16:05:13 | [diff] [blame] | 12699 | TEST_P(HttpNetworkTransactionTest, |
| 12700 | UseIPConnectionPoolingWithHostCacheExpiration) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12701 | session_deps_.use_alternative_services = true; |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 12702 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12703 | |
| 12704 | // Set up a special HttpNetworkSession with a OneTimeCachingHostResolver. |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12705 | OneTimeCachingHostResolver host_resolver(HostPortPair("www.gmail.com", 443)); |
[email protected] | c6bf815 | 2012-12-02 07:43:34 | [diff] [blame] | 12706 | HttpNetworkSession::Params params = |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12707 | SpdySessionDependencies::CreateSessionParams(&session_deps_); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12708 | params.host_resolver = &host_resolver; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12709 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | b9ec688 | 2011-07-01 07:40:26 | [diff] [blame] | 12710 | SpdySessionPoolPeer pool_peer(session->spdy_session_pool()); |
| 12711 | pool_peer.DisableDomainAuthenticationVerification(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12712 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12713 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 12714 | ssl.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12715 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12716 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12717 | scoped_ptr<SpdyFrame> host1_req( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12718 | spdy_util_.ConstructSpdyGet("https://www.example.org", false, 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 12719 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12720 | scoped_ptr<SpdyFrame> host2_req( |
| 12721 | spdy_util_.ConstructSpdyGet("https://www.gmail.com", false, 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12722 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12723 | CreateMockWrite(*host1_req, 0), CreateMockWrite(*host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12724 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12725 | scoped_ptr<SpdyFrame> host1_resp( |
| 12726 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12727 | scoped_ptr<SpdyFrame> host1_resp_body( |
| 12728 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 12729 | scoped_ptr<SpdyFrame> host2_resp( |
| 12730 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 12731 | scoped_ptr<SpdyFrame> host2_resp_body( |
| 12732 | spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12733 | MockRead spdy_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12734 | CreateMockRead(*host1_resp, 1), |
| 12735 | CreateMockRead(*host1_resp_body, 2), |
| 12736 | CreateMockRead(*host2_resp, 4), |
| 12737 | CreateMockRead(*host2_resp_body, 5), |
| 12738 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12739 | }; |
| 12740 | |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 12741 | IPAddressNumber ip; |
| 12742 | ASSERT_TRUE(ParseIPLiteralToNumber("127.0.0.1", &ip)); |
| 12743 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 12744 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12745 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 12746 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12747 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12748 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 12749 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12750 | HttpRequestInfo request1; |
| 12751 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12752 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12753 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12754 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12755 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12756 | int rv = trans1.Start(&request1, callback.callback(), BoundNetLog()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12757 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12758 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12759 | |
| 12760 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 12761 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12762 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12763 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12764 | |
| 12765 | std::string response_data; |
| 12766 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); |
| 12767 | EXPECT_EQ("hello!", response_data); |
| 12768 | |
| 12769 | // Preload cache entries into HostCache. |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 12770 | HostResolver::RequestInfo resolve_info(HostPortPair("www.gmail.com", 443)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12771 | AddressList ignored; |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 12772 | rv = host_resolver.Resolve(resolve_info, |
| 12773 | DEFAULT_PRIORITY, |
| 12774 | &ignored, |
| 12775 | callback.callback(), |
| 12776 | NULL, |
| 12777 | BoundNetLog()); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 12778 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12779 | rv = callback.WaitForResult(); |
| 12780 | EXPECT_EQ(OK, rv); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12781 | |
| 12782 | HttpRequestInfo request2; |
| 12783 | request2.method = "GET"; |
| 12784 | request2.url = GURL("https://www.gmail.com/"); |
| 12785 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12786 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12787 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12788 | rv = trans2.Start(&request2, callback.callback(), BoundNetLog()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12789 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12790 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12791 | |
| 12792 | response = trans2.GetResponseInfo(); |
| 12793 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12794 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12795 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12796 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 12797 | EXPECT_TRUE(response->was_npn_negotiated); |
| 12798 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); |
| 12799 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 12800 | } |
| 12801 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12802 | TEST_P(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttp) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12803 | const std::string https_url = "https://www.example.org:8080/"; |
| 12804 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12805 | |
| 12806 | // SPDY GET for HTTPS URL |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 12807 | scoped_ptr<SpdyFrame> req1( |
| 12808 | spdy_util_.ConstructSpdyGet(https_url.c_str(), false, 1, LOWEST)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12809 | |
| 12810 | MockWrite writes1[] = { |
| 12811 | CreateMockWrite(*req1, 0), |
| 12812 | }; |
| 12813 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 12814 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12815 | scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12816 | MockRead reads1[] = { |
| 12817 | CreateMockRead(*resp1, 1), |
| 12818 | CreateMockRead(*body1, 2), |
| 12819 | MockRead(ASYNC, ERR_IO_PENDING, 3) |
| 12820 | }; |
| 12821 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12822 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 12823 | arraysize(writes1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12824 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 12825 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12826 | |
| 12827 | // HTTP GET for the HTTP URL |
| 12828 | MockWrite writes2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12829 | MockWrite(ASYNC, 0, |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 12830 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12831 | "Host: www.example.org:8080\r\n" |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 12832 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12833 | }; |
| 12834 | |
| 12835 | MockRead reads2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12836 | MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 12837 | MockRead(ASYNC, 2, "hello"), |
| 12838 | MockRead(ASYNC, OK, 3), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12839 | }; |
| 12840 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12841 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 12842 | arraysize(writes2)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12843 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12844 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 12845 | ssl.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12846 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12847 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 12848 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12849 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12850 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12851 | |
| 12852 | // Start the first transaction to set up the SpdySession |
| 12853 | HttpRequestInfo request1; |
| 12854 | request1.method = "GET"; |
| 12855 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12856 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12857 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12858 | TestCompletionCallback callback1; |
| 12859 | EXPECT_EQ(ERR_IO_PENDING, |
| 12860 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 12861 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12862 | |
| 12863 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 12864 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 12865 | |
| 12866 | // Now, start the HTTP request |
| 12867 | HttpRequestInfo request2; |
| 12868 | request2.method = "GET"; |
| 12869 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12870 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12871 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12872 | TestCompletionCallback callback2; |
| 12873 | EXPECT_EQ(ERR_IO_PENDING, |
| 12874 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 12875 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 12876 | |
| 12877 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 12878 | EXPECT_FALSE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 12879 | } |
| 12880 | |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 12881 | class AltSvcCertificateVerificationTest : public HttpNetworkTransactionTest { |
| 12882 | public: |
| 12883 | void Run(bool pooling, bool valid) { |
| 12884 | HostPortPair origin(valid ? "mail.example.org" : "invalid.example.org", |
| 12885 | 443); |
| 12886 | HostPortPair alternative("www.example.org", 443); |
| 12887 | |
| 12888 | base::FilePath certs_dir = GetTestCertsDirectory(); |
| 12889 | scoped_refptr<X509Certificate> cert( |
| 12890 | ImportCertFromFile(certs_dir, "spdy_pooling.pem")); |
| 12891 | ASSERT_TRUE(cert.get()); |
| 12892 | bool common_name_fallback_used; |
| 12893 | EXPECT_EQ(valid, |
| 12894 | cert->VerifyNameMatch(origin.host(), &common_name_fallback_used)); |
| 12895 | EXPECT_TRUE( |
| 12896 | cert->VerifyNameMatch(alternative.host(), &common_name_fallback_used)); |
| 12897 | SSLSocketDataProvider ssl(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 12898 | ssl.SetNextProto(GetProtocol()); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 12899 | ssl.cert = cert; |
| 12900 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12901 | |
| 12902 | // If pooling, then start a request to alternative first to create a |
| 12903 | // SpdySession. |
| 12904 | std::string url0 = "https://www.example.org:443"; |
| 12905 | // Second request to origin, which has an alternative service, and could |
| 12906 | // open a connection to the alternative host or pool to the existing one. |
| 12907 | std::string url1("https://"); |
| 12908 | url1.append(origin.host()); |
| 12909 | url1.append(":443"); |
| 12910 | |
| 12911 | scoped_ptr<SpdyFrame> req0; |
| 12912 | scoped_ptr<SpdyFrame> req1; |
| 12913 | scoped_ptr<SpdyFrame> resp0; |
| 12914 | scoped_ptr<SpdyFrame> body0; |
| 12915 | scoped_ptr<SpdyFrame> resp1; |
| 12916 | scoped_ptr<SpdyFrame> body1; |
| 12917 | std::vector<MockWrite> writes; |
| 12918 | std::vector<MockRead> reads; |
| 12919 | |
| 12920 | if (pooling) { |
| 12921 | req0.reset(spdy_util_.ConstructSpdyGet(url0.c_str(), false, 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 12922 | spdy_util_.UpdateWithStreamDestruction(1); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 12923 | req1.reset(spdy_util_.ConstructSpdyGet(url1.c_str(), false, 3, LOWEST)); |
| 12924 | |
| 12925 | writes.push_back(CreateMockWrite(*req0, 0)); |
| 12926 | writes.push_back(CreateMockWrite(*req1, 3)); |
| 12927 | |
| 12928 | resp0.reset(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12929 | body0.reset(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 12930 | resp1.reset(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 12931 | body1.reset(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
| 12932 | |
| 12933 | reads.push_back(CreateMockRead(*resp0, 1)); |
| 12934 | reads.push_back(CreateMockRead(*body0, 2)); |
| 12935 | reads.push_back(MockRead(ASYNC, ERR_IO_PENDING, 4)); |
| 12936 | reads.push_back(CreateMockRead(*resp1, 5)); |
| 12937 | reads.push_back(CreateMockRead(*body1, 6)); |
| 12938 | reads.push_back(MockRead(ASYNC, OK, 7)); |
| 12939 | } else { |
| 12940 | req1.reset(spdy_util_.ConstructSpdyGet(url1.c_str(), false, 1, LOWEST)); |
| 12941 | |
| 12942 | writes.push_back(CreateMockWrite(*req1, 0)); |
| 12943 | |
| 12944 | resp1.reset(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 12945 | body1.reset(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 12946 | |
| 12947 | reads.push_back(CreateMockRead(*resp1, 1)); |
| 12948 | reads.push_back(CreateMockRead(*body1, 2)); |
| 12949 | reads.push_back(MockRead(ASYNC, OK, 3)); |
| 12950 | } |
| 12951 | |
davidben | 5f8b6bc | 2015-11-25 03:19:54 | [diff] [blame] | 12952 | SequencedSocketData data(reads.data(), reads.size(), writes.data(), |
| 12953 | writes.size()); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 12954 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12955 | |
| 12956 | // Connection to the origin fails. |
| 12957 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 12958 | StaticSocketDataProvider data_refused; |
| 12959 | data_refused.set_connect_data(mock_connect); |
| 12960 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 12961 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12962 | session_deps_.use_alternative_services = true; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12963 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 12964 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 12965 | session->http_server_properties(); |
| 12966 | AlternativeService alternative_service( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 12967 | AlternateProtocolFromNextProto(GetProtocol()), alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12968 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 12969 | http_server_properties->SetAlternativeService(origin, alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12970 | 1.0, expiration); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 12971 | |
| 12972 | // First request to alternative. |
| 12973 | if (pooling) { |
| 12974 | scoped_ptr<HttpTransaction> trans0( |
| 12975 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 12976 | HttpRequestInfo request0; |
| 12977 | request0.method = "GET"; |
| 12978 | request0.url = GURL(url0); |
| 12979 | request0.load_flags = 0; |
| 12980 | TestCompletionCallback callback0; |
| 12981 | |
| 12982 | int rv = trans0->Start(&request0, callback0.callback(), BoundNetLog()); |
| 12983 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 12984 | rv = callback0.WaitForResult(); |
| 12985 | EXPECT_EQ(OK, rv); |
| 12986 | } |
| 12987 | |
| 12988 | // Second request to origin. |
| 12989 | scoped_ptr<HttpTransaction> trans1( |
| 12990 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 12991 | HttpRequestInfo request1; |
| 12992 | request1.method = "GET"; |
| 12993 | request1.url = GURL(url1); |
| 12994 | request1.load_flags = 0; |
| 12995 | TestCompletionCallback callback1; |
| 12996 | |
| 12997 | int rv = trans1->Start(&request1, callback1.callback(), BoundNetLog()); |
| 12998 | EXPECT_EQ(ERR_IO_PENDING, rv); |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 12999 | base::MessageLoop::current()->RunUntilIdle(); |
| 13000 | if (data.IsReadPaused()) { |
| 13001 | data.CompleteRead(); |
| 13002 | } |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 13003 | rv = callback1.WaitForResult(); |
| 13004 | if (valid) { |
| 13005 | EXPECT_EQ(OK, rv); |
| 13006 | } else { |
| 13007 | if (pooling) { |
| 13008 | EXPECT_EQ(ERR_CONNECTION_REFUSED, rv); |
| 13009 | } else { |
| 13010 | EXPECT_EQ(ERR_ALTERNATIVE_CERT_NOT_VALID_FOR_ORIGIN, rv); |
| 13011 | } |
| 13012 | } |
| 13013 | } |
| 13014 | }; |
| 13015 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13016 | INSTANTIATE_TEST_CASE_P(ProtoPlusDepend, |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 13017 | AltSvcCertificateVerificationTest, |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13018 | testing::Values(kTestCaseSPDY31, |
| 13019 | kTestCaseHTTP2NoPriorityDependencies, |
| 13020 | kTestCaseHTTP2PriorityDependencies)); |
bnc | 1b0e3685 | 2015-04-28 15:32:59 | [diff] [blame] | 13021 | |
| 13022 | // The alternative service host must exhibit a certificate that is valid for the |
| 13023 | // origin host. Test that this is enforced when pooling to an existing |
| 13024 | // connection. |
| 13025 | TEST_P(AltSvcCertificateVerificationTest, PoolingValid) { |
| 13026 | Run(true, true); |
| 13027 | } |
| 13028 | |
| 13029 | TEST_P(AltSvcCertificateVerificationTest, PoolingInvalid) { |
| 13030 | Run(true, false); |
| 13031 | } |
| 13032 | |
| 13033 | // The alternative service host must exhibit a certificate that is valid for the |
| 13034 | // origin host. Test that this is enforced when opening a new connection. |
| 13035 | TEST_P(AltSvcCertificateVerificationTest, NewConnectionValid) { |
| 13036 | Run(false, true); |
| 13037 | } |
| 13038 | |
| 13039 | TEST_P(AltSvcCertificateVerificationTest, NewConnectionInvalid) { |
| 13040 | Run(false, false); |
| 13041 | } |
| 13042 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13043 | // Alternative service requires HTTP/2 (or SPDY), but HTTP/1.1 is negotiated |
| 13044 | // with the alternative server. That connection should not be used. |
| 13045 | TEST_P(HttpNetworkTransactionTest, AlternativeServiceNotOnHttp11) { |
| 13046 | HostPortPair origin("origin.example.org", 443); |
| 13047 | HostPortPair alternative("alternative.example.org", 443); |
| 13048 | |
| 13049 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 13050 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 13051 | ssl.SetNextProto(kProtoHTTP11); |
| 13052 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13053 | |
| 13054 | // No data should be read from the alternative, because HTTP/1.1 is |
| 13055 | // negotiated. |
| 13056 | StaticSocketDataProvider data; |
| 13057 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13058 | |
| 13059 | // This test documents that an alternate Job should not be used if HTTP/1.1 is |
| 13060 | // negotiated. In order to test this, a failed connection to the origin is |
| 13061 | // mocked. This way the request relies on the alternate Job. |
| 13062 | StaticSocketDataProvider data_refused; |
| 13063 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 13064 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 13065 | |
| 13066 | // Set up alternative service for origin. |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 13067 | session_deps_.use_alternative_services = true; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 13068 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13069 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 13070 | session->http_server_properties(); |
| 13071 | AlternativeService alternative_service( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13072 | AlternateProtocolFromNextProto(GetProtocol()), alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 13073 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13074 | http_server_properties->SetAlternativeService(origin, alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 13075 | 1.0, expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13076 | |
| 13077 | scoped_ptr<HttpTransaction> trans( |
| 13078 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 13079 | HttpRequestInfo request; |
| 13080 | request.method = "GET"; |
| 13081 | request.url = GURL("https://origin.example.org:443"); |
| 13082 | request.load_flags = 0; |
| 13083 | TestCompletionCallback callback; |
| 13084 | |
| 13085 | // HTTP/2 (or SPDY) is required for alternative service, if HTTP/1.1 is |
| 13086 | // negotiated, the alternate Job should fail with ERR_NPN_NEGOTIATION_FAILED. |
| 13087 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13088 | EXPECT_EQ(ERR_NPN_NEGOTIATION_FAILED, callback.GetResult(rv)); |
| 13089 | } |
| 13090 | |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13091 | // A request to a server with an alternative service fires two Jobs: one to the |
| 13092 | // origin, and an alternate one to the alternative server. If the former |
| 13093 | // succeeds, the request should succeed, even if the latter fails because |
| 13094 | // HTTP/1.1 is negotiated which is insufficient for alternative service. |
| 13095 | TEST_P(HttpNetworkTransactionTest, FailedAlternativeServiceIsNotUserVisible) { |
| 13096 | HostPortPair origin("origin.example.org", 443); |
| 13097 | HostPortPair alternative("alternative.example.org", 443); |
| 13098 | |
| 13099 | // Negotiate HTTP/1.1 with alternative. |
| 13100 | SSLSocketDataProvider alternative_ssl(ASYNC, OK); |
| 13101 | alternative_ssl.SetNextProto(kProtoHTTP11); |
| 13102 | session_deps_.socket_factory->AddSSLSocketDataProvider(&alternative_ssl); |
| 13103 | |
| 13104 | // No data should be read from the alternative, because HTTP/1.1 is |
| 13105 | // negotiated. |
| 13106 | StaticSocketDataProvider data; |
| 13107 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13108 | |
| 13109 | // Negotiate HTTP/1.1 with origin. |
| 13110 | SSLSocketDataProvider origin_ssl(ASYNC, OK); |
| 13111 | origin_ssl.SetNextProto(kProtoHTTP11); |
| 13112 | session_deps_.socket_factory->AddSSLSocketDataProvider(&origin_ssl); |
| 13113 | |
| 13114 | MockWrite http_writes[] = { |
| 13115 | MockWrite( |
| 13116 | "GET / HTTP/1.1\r\n" |
| 13117 | "Host: origin.example.org\r\n" |
| 13118 | "Connection: keep-alive\r\n\r\n"), |
| 13119 | MockWrite( |
| 13120 | "GET /second HTTP/1.1\r\n" |
| 13121 | "Host: origin.example.org\r\n" |
| 13122 | "Connection: keep-alive\r\n\r\n"), |
| 13123 | }; |
| 13124 | |
| 13125 | MockRead http_reads[] = { |
| 13126 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13127 | MockRead("Content-Type: text/html\r\n"), |
| 13128 | MockRead("Content-Length: 6\r\n\r\n"), |
| 13129 | MockRead("foobar"), |
| 13130 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13131 | MockRead("Content-Type: text/html\r\n"), |
| 13132 | MockRead("Content-Length: 7\r\n\r\n"), |
| 13133 | MockRead("another"), |
| 13134 | }; |
| 13135 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 13136 | http_writes, arraysize(http_writes)); |
| 13137 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 13138 | |
| 13139 | // Set up alternative service for origin. |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 13140 | session_deps_.use_alternative_services = true; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 13141 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13142 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 13143 | session->http_server_properties(); |
| 13144 | AlternativeService alternative_service( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13145 | AlternateProtocolFromNextProto(GetProtocol()), alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 13146 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13147 | http_server_properties->SetAlternativeService(origin, alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 13148 | 1.0, expiration); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 13149 | |
| 13150 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 13151 | HttpRequestInfo request1; |
| 13152 | request1.method = "GET"; |
| 13153 | request1.url = GURL("https://origin.example.org:443"); |
| 13154 | request1.load_flags = 0; |
| 13155 | TestCompletionCallback callback1; |
| 13156 | |
| 13157 | int rv = trans1.Start(&request1, callback1.callback(), BoundNetLog()); |
| 13158 | rv = callback1.GetResult(rv); |
| 13159 | EXPECT_EQ(OK, rv); |
| 13160 | |
| 13161 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
| 13162 | ASSERT_TRUE(response1 != nullptr); |
| 13163 | ASSERT_TRUE(response1->headers.get() != nullptr); |
| 13164 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
| 13165 | |
| 13166 | std::string response_data1; |
| 13167 | ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data1)); |
| 13168 | EXPECT_EQ("foobar", response_data1); |
| 13169 | |
| 13170 | // Alternative should be marked as broken, because HTTP/1.1 is not sufficient |
| 13171 | // for alternative service. |
| 13172 | EXPECT_TRUE( |
| 13173 | http_server_properties->IsAlternativeServiceBroken(alternative_service)); |
| 13174 | |
| 13175 | // Since |alternative_service| is broken, a second transaction to origin |
| 13176 | // should not start an alternate Job. It should pool to existing connection |
| 13177 | // to origin. |
| 13178 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 13179 | HttpRequestInfo request2; |
| 13180 | request2.method = "GET"; |
| 13181 | request2.url = GURL("https://origin.example.org:443/second"); |
| 13182 | request2.load_flags = 0; |
| 13183 | TestCompletionCallback callback2; |
| 13184 | |
| 13185 | rv = trans2.Start(&request2, callback2.callback(), BoundNetLog()); |
| 13186 | rv = callback2.GetResult(rv); |
| 13187 | EXPECT_EQ(OK, rv); |
| 13188 | |
| 13189 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
| 13190 | ASSERT_TRUE(response2 != nullptr); |
| 13191 | ASSERT_TRUE(response2->headers.get() != nullptr); |
| 13192 | EXPECT_EQ("HTTP/1.1 200 OK", response2->headers->GetStatusLine()); |
| 13193 | |
| 13194 | std::string response_data2; |
| 13195 | ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data2)); |
| 13196 | EXPECT_EQ("another", response_data2); |
| 13197 | } |
| 13198 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13199 | // Alternative service requires HTTP/2 (or SPDY), but there is already a |
| 13200 | // HTTP/1.1 socket open to the alternative server. That socket should not be |
| 13201 | // used. |
| 13202 | TEST_P(HttpNetworkTransactionTest, AlternativeServiceShouldNotPoolToHttp11) { |
| 13203 | HostPortPair origin("origin.example.org", 443); |
| 13204 | HostPortPair alternative("alternative.example.org", 443); |
| 13205 | std::string origin_url = "https://origin.example.org:443"; |
| 13206 | std::string alternative_url = "https://alternative.example.org:443"; |
| 13207 | |
| 13208 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 13209 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 13210 | ssl.SetNextProto(kProtoHTTP11); |
| 13211 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13212 | |
| 13213 | // HTTP/1.1 data for |request1| and |request2|. |
| 13214 | MockWrite http_writes[] = { |
| 13215 | MockWrite( |
| 13216 | "GET / HTTP/1.1\r\n" |
| 13217 | "Host: alternative.example.org\r\n" |
| 13218 | "Connection: keep-alive\r\n\r\n"), |
| 13219 | MockWrite( |
| 13220 | "GET / HTTP/1.1\r\n" |
| 13221 | "Host: alternative.example.org\r\n" |
| 13222 | "Connection: keep-alive\r\n\r\n"), |
| 13223 | }; |
| 13224 | |
| 13225 | MockRead http_reads[] = { |
| 13226 | MockRead( |
| 13227 | "HTTP/1.1 200 OK\r\n" |
| 13228 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13229 | "Content-Length: 40\r\n\r\n" |
| 13230 | "first HTTP/1.1 response from alternative"), |
| 13231 | MockRead( |
| 13232 | "HTTP/1.1 200 OK\r\n" |
| 13233 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13234 | "Content-Length: 41\r\n\r\n" |
| 13235 | "second HTTP/1.1 response from alternative"), |
| 13236 | }; |
| 13237 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 13238 | http_writes, arraysize(http_writes)); |
| 13239 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 13240 | |
| 13241 | // This test documents that an alternate Job should not pool to an already |
| 13242 | // existing HTTP/1.1 connection. In order to test this, a failed connection |
| 13243 | // to the origin is mocked. This way |request2| relies on the alternate Job. |
| 13244 | StaticSocketDataProvider data_refused; |
| 13245 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 13246 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 13247 | |
| 13248 | // Set up alternative service for origin. |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 13249 | session_deps_.use_alternative_services = true; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 13250 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13251 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 13252 | session->http_server_properties(); |
| 13253 | AlternativeService alternative_service( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13254 | AlternateProtocolFromNextProto(GetProtocol()), alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 13255 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13256 | http_server_properties->SetAlternativeService(origin, alternative_service, |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 13257 | 1.0, expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 13258 | |
| 13259 | // First transaction to alternative to open an HTTP/1.1 socket. |
| 13260 | scoped_ptr<HttpTransaction> trans1( |
| 13261 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 13262 | HttpRequestInfo request1; |
| 13263 | request1.method = "GET"; |
| 13264 | request1.url = GURL(alternative_url); |
| 13265 | request1.load_flags = 0; |
| 13266 | TestCompletionCallback callback1; |
| 13267 | |
| 13268 | int rv = trans1->Start(&request1, callback1.callback(), BoundNetLog()); |
| 13269 | EXPECT_EQ(OK, callback1.GetResult(rv)); |
| 13270 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 13271 | ASSERT_TRUE(response1); |
| 13272 | ASSERT_TRUE(response1->headers.get()); |
| 13273 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
| 13274 | EXPECT_TRUE(response1->was_npn_negotiated); |
| 13275 | EXPECT_FALSE(response1->was_fetched_via_spdy); |
| 13276 | std::string response_data1; |
| 13277 | ASSERT_EQ(OK, ReadTransaction(trans1.get(), &response_data1)); |
| 13278 | EXPECT_EQ("first HTTP/1.1 response from alternative", response_data1); |
| 13279 | |
| 13280 | // Request for origin.example.org, which has an alternative service. This |
| 13281 | // will start two Jobs: the alternative looks for connections to pool to, |
| 13282 | // finds one which is HTTP/1.1, and should ignore it, and should not try to |
| 13283 | // open other connections to alternative server. The Job to origin fails, so |
| 13284 | // this request fails. |
| 13285 | scoped_ptr<HttpTransaction> trans2( |
| 13286 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 13287 | HttpRequestInfo request2; |
| 13288 | request2.method = "GET"; |
| 13289 | request2.url = GURL(origin_url); |
| 13290 | request2.load_flags = 0; |
| 13291 | TestCompletionCallback callback2; |
| 13292 | |
| 13293 | rv = trans2->Start(&request2, callback2.callback(), BoundNetLog()); |
| 13294 | EXPECT_EQ(ERR_CONNECTION_REFUSED, callback2.GetResult(rv)); |
| 13295 | |
| 13296 | // Another transaction to alternative. This is to test that the HTTP/1.1 |
| 13297 | // socket is still open and in the pool. |
| 13298 | scoped_ptr<HttpTransaction> trans3( |
| 13299 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 13300 | HttpRequestInfo request3; |
| 13301 | request3.method = "GET"; |
| 13302 | request3.url = GURL(alternative_url); |
| 13303 | request3.load_flags = 0; |
| 13304 | TestCompletionCallback callback3; |
| 13305 | |
| 13306 | rv = trans3->Start(&request3, callback3.callback(), BoundNetLog()); |
| 13307 | EXPECT_EQ(OK, callback3.GetResult(rv)); |
| 13308 | const HttpResponseInfo* response3 = trans3->GetResponseInfo(); |
| 13309 | ASSERT_TRUE(response3); |
| 13310 | ASSERT_TRUE(response3->headers.get()); |
| 13311 | EXPECT_EQ("HTTP/1.1 200 OK", response3->headers->GetStatusLine()); |
| 13312 | EXPECT_TRUE(response3->was_npn_negotiated); |
| 13313 | EXPECT_FALSE(response3->was_fetched_via_spdy); |
| 13314 | std::string response_data3; |
| 13315 | ASSERT_EQ(OK, ReadTransaction(trans3.get(), &response_data3)); |
| 13316 | EXPECT_EQ("second HTTP/1.1 response from alternative", response_data3); |
| 13317 | } |
| 13318 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13319 | TEST_P(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttpOverTunnel) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13320 | const std::string https_url = "https://www.example.org:8080/"; |
| 13321 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13322 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13323 | // Separate SPDY util instance for naked and wrapped requests. |
| 13324 | SpdyTestUtil spdy_util_wrapped(GetProtocol(), GetDependenciesFromPriority()); |
| 13325 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13326 | // SPDY GET for HTTPS URL (through CONNECT tunnel) |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13327 | const HostPortPair host_port_pair("www.example.org", 8080); |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 13328 | scoped_ptr<SpdyFrame> connect( |
| 13329 | spdy_util_.ConstructSpdyConnect(NULL, 0, 1, LOWEST, host_port_pair)); |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 13330 | scoped_ptr<SpdyFrame> req1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13331 | spdy_util_wrapped.ConstructSpdyGet(https_url.c_str(), false, 1, LOWEST)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13332 | scoped_ptr<SpdyFrame> wrapped_req1( |
| 13333 | spdy_util_.ConstructWrappedSpdyFrame(req1, 1)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 13334 | |
| 13335 | // SPDY GET for HTTP URL (through the proxy, but not the tunnel). |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 13336 | SpdyHeaderBlock req2_block; |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 13337 | spdy_util_.MaybeAddVersionHeader(&req2_block); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 13338 | req2_block[spdy_util_.GetMethodKey()] = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13339 | req2_block[spdy_util_.GetHostKey()] = "www.example.org:8080"; |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 13340 | req2_block[spdy_util_.GetSchemeKey()] = "http"; |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 13341 | req2_block[spdy_util_.GetPathKey()] = "/"; |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 13342 | scoped_ptr<SpdyFrame> req2( |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 13343 | spdy_util_.ConstructSpdySyn(3, req2_block, MEDIUM, false, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13344 | |
| 13345 | MockWrite writes1[] = { |
| 13346 | CreateMockWrite(*connect, 0), |
| 13347 | CreateMockWrite(*wrapped_req1, 2), |
| 13348 | CreateMockWrite(*req2, 5), |
| 13349 | }; |
| 13350 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13351 | scoped_ptr<SpdyFrame> conn_resp( |
| 13352 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 13353 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 13354 | scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 13355 | scoped_ptr<SpdyFrame> wrapped_resp1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13356 | spdy_util_wrapped.ConstructWrappedSpdyFrame(resp1, 1)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13357 | scoped_ptr<SpdyFrame> wrapped_body1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13358 | spdy_util_wrapped.ConstructWrappedSpdyFrame(body1, 1)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13359 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 13360 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13361 | MockRead reads1[] = { |
| 13362 | CreateMockRead(*conn_resp, 1), |
| 13363 | CreateMockRead(*wrapped_resp1, 3), |
| 13364 | CreateMockRead(*wrapped_body1, 4), |
| 13365 | CreateMockRead(*resp2, 6), |
| 13366 | CreateMockRead(*body2, 7), |
| 13367 | MockRead(ASYNC, ERR_IO_PENDING, 8) |
| 13368 | }; |
| 13369 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 13370 | DeterministicSocketData data1(reads1, arraysize(reads1), |
| 13371 | writes1, arraysize(writes1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13372 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 13373 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13374 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 13375 | session_deps_.proxy_service = |
| 13376 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 13377 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13378 | session_deps_.net_log = &log; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13379 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13380 | ssl1.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13381 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13382 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13383 | ssl2.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13384 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 13385 | session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13386 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 13387 | scoped_ptr<HttpNetworkSession> session( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13388 | SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13389 | |
| 13390 | // Start the first transaction to set up the SpdySession |
| 13391 | HttpRequestInfo request1; |
| 13392 | request1.method = "GET"; |
| 13393 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13394 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13395 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13396 | TestCompletionCallback callback1; |
| 13397 | EXPECT_EQ(ERR_IO_PENDING, |
| 13398 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 13399 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 13400 | data1.RunFor(4); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13401 | |
| 13402 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 13403 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 13404 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 13405 | LoadTimingInfo load_timing_info1; |
| 13406 | EXPECT_TRUE(trans1.GetLoadTimingInfo(&load_timing_info1)); |
| 13407 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 13408 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 13409 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13410 | // Now, start the HTTP request |
| 13411 | HttpRequestInfo request2; |
| 13412 | request2.method = "GET"; |
| 13413 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13414 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13415 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13416 | TestCompletionCallback callback2; |
| 13417 | EXPECT_EQ(ERR_IO_PENDING, |
| 13418 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 13419 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 13420 | data1.RunFor(3); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13421 | |
| 13422 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 13423 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 13424 | |
| 13425 | LoadTimingInfo load_timing_info2; |
| 13426 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
| 13427 | // The established SPDY sessions is considered reused by the HTTP request. |
| 13428 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 13429 | // HTTP requests over a SPDY session should have a different connection |
| 13430 | // socket_log_id than requests over a tunnel. |
| 13431 | 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] | 13432 | } |
| 13433 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13434 | // Test that in the case where we have a SPDY session to a SPDY proxy |
| 13435 | // that we do not pool other origins that resolve to the same IP when |
| 13436 | // the certificate does not match the new origin. |
| 13437 | // http://crbug.com/134690 |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13438 | TEST_P(HttpNetworkTransactionTest, DoNotUseSpdySessionIfCertDoesNotMatch) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13439 | const std::string url1 = "http://www.example.org/"; |
| 13440 | const std::string url2 = "https://news.example.org/"; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13441 | const std::string ip_addr = "1.2.3.4"; |
| 13442 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13443 | // Second SpdyTestUtil instance for the second socket. |
| 13444 | SpdyTestUtil spdy_util_secure(GetProtocol(), GetDependenciesFromPriority()); |
| 13445 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13446 | // SPDY GET for HTTP URL (through SPDY proxy) |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13447 | scoped_ptr<SpdyHeaderBlock> headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13448 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 13449 | scoped_ptr<SpdyFrame> req1( |
| 13450 | spdy_util_.ConstructSpdySyn(1, *headers, LOWEST, false, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13451 | |
| 13452 | MockWrite writes1[] = { |
| 13453 | CreateMockWrite(*req1, 0), |
| 13454 | }; |
| 13455 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13456 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 13457 | scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13458 | MockRead reads1[] = { |
bnc | b9e20fc6 | 2015-08-17 17:19:37 | [diff] [blame] | 13459 | CreateMockRead(*resp1, 1), |
| 13460 | CreateMockRead(*body1, 2), |
| 13461 | MockRead(ASYNC, OK, 3) // EOF |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13462 | }; |
| 13463 | |
| 13464 | scoped_ptr<DeterministicSocketData> data1( |
| 13465 | new DeterministicSocketData(reads1, arraysize(reads1), |
| 13466 | writes1, arraysize(writes1))); |
| 13467 | IPAddressNumber ip; |
| 13468 | ASSERT_TRUE(ParseIPLiteralToNumber(ip_addr, &ip)); |
| 13469 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 13470 | MockConnect connect_data1(ASYNC, OK, peer_addr); |
| 13471 | data1->set_connect_data(connect_data1); |
| 13472 | |
| 13473 | // SPDY GET for HTTPS URL (direct) |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 13474 | scoped_ptr<SpdyFrame> req2( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13475 | spdy_util_secure.ConstructSpdyGet(url2.c_str(), false, 1, MEDIUM)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13476 | |
| 13477 | MockWrite writes2[] = { |
| 13478 | CreateMockWrite(*req2, 0), |
| 13479 | }; |
| 13480 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13481 | scoped_ptr<SpdyFrame> resp2( |
| 13482 | spdy_util_secure.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 13483 | scoped_ptr<SpdyFrame> body2(spdy_util_secure.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13484 | MockRead reads2[] = { |
bnc | b9e20fc6 | 2015-08-17 17:19:37 | [diff] [blame] | 13485 | CreateMockRead(*resp2, 1), |
| 13486 | CreateMockRead(*body2, 2), |
| 13487 | MockRead(ASYNC, OK, 3) // EOF |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13488 | }; |
| 13489 | |
| 13490 | scoped_ptr<DeterministicSocketData> data2( |
| 13491 | new DeterministicSocketData(reads2, arraysize(reads2), |
| 13492 | writes2, arraysize(writes2))); |
| 13493 | MockConnect connect_data2(ASYNC, OK); |
| 13494 | data2->set_connect_data(connect_data2); |
| 13495 | |
| 13496 | // Set up a proxy config that sends HTTP requests to a proxy, and |
| 13497 | // all others direct. |
| 13498 | ProxyConfig proxy_config; |
| 13499 | proxy_config.proxy_rules().ParseFromString("http=https://proxy:443"); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13500 | session_deps_.proxy_service.reset(new ProxyService( |
csharrison | b7e3a08 | 2015-09-22 19:13:04 | [diff] [blame] | 13501 | make_scoped_ptr(new ProxyConfigServiceFixed(proxy_config)), nullptr, |
| 13502 | NULL)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13503 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13504 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13505 | ssl1.SetNextProto(GetProtocol()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13506 | // Load a valid cert. Note, that this does not need to |
| 13507 | // be valid for proxy because the MockSSLClientSocket does |
| 13508 | // not actually verify it. But SpdySession will use this |
| 13509 | // to see if it is valid for the new origin |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13510 | ssl1.cert = ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem"); |
| 13511 | ASSERT_TRUE(ssl1.cert.get()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13512 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 13513 | session_deps_.deterministic_socket_factory->AddSocketDataProvider( |
| 13514 | data1.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13515 | |
| 13516 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13517 | ssl2.SetNextProto(GetProtocol()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13518 | session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 13519 | session_deps_.deterministic_socket_factory->AddSocketDataProvider( |
| 13520 | data2.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13521 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13522 | session_deps_.host_resolver.reset(new MockCachingHostResolver()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13523 | session_deps_.host_resolver->rules()->AddRule("news.example.org", ip_addr); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13524 | session_deps_.host_resolver->rules()->AddRule("proxy", ip_addr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13525 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 13526 | scoped_ptr<HttpNetworkSession> session( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13527 | SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13528 | |
| 13529 | // Start the first transaction to set up the SpdySession |
| 13530 | HttpRequestInfo request1; |
| 13531 | request1.method = "GET"; |
| 13532 | request1.url = GURL(url1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13533 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13534 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13535 | TestCompletionCallback callback1; |
| 13536 | ASSERT_EQ(ERR_IO_PENDING, |
| 13537 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
| 13538 | data1->RunFor(3); |
| 13539 | |
| 13540 | ASSERT_TRUE(callback1.have_result()); |
| 13541 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 13542 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 13543 | |
| 13544 | // Now, start the HTTP request |
| 13545 | HttpRequestInfo request2; |
| 13546 | request2.method = "GET"; |
| 13547 | request2.url = GURL(url2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13548 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13549 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13550 | TestCompletionCallback callback2; |
| 13551 | EXPECT_EQ(ERR_IO_PENDING, |
| 13552 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 13553 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 13554 | data2->RunFor(3); |
| 13555 | |
| 13556 | ASSERT_TRUE(callback2.have_result()); |
| 13557 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 13558 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 13559 | } |
| 13560 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13561 | // Test to verify that a failed socket read (due to an ERR_CONNECTION_CLOSED |
| 13562 | // error) in SPDY session, removes the socket from pool and closes the SPDY |
| 13563 | // session. Verify that new url's from the same HttpNetworkSession (and a new |
| 13564 | // SpdySession) do work. http://crbug.com/224701 |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13565 | TEST_P(HttpNetworkTransactionTest, ErrorSocketNotConnected) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13566 | const std::string https_url = "https://www.example.org/"; |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13567 | |
| 13568 | MockRead reads1[] = { |
| 13569 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED, 0) |
| 13570 | }; |
| 13571 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 13572 | SequencedSocketData data1(reads1, arraysize(reads1), NULL, 0); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13573 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 13574 | scoped_ptr<SpdyFrame> req2( |
| 13575 | spdy_util_.ConstructSpdyGet(https_url.c_str(), false, 1, MEDIUM)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13576 | MockWrite writes2[] = { |
| 13577 | CreateMockWrite(*req2, 0), |
| 13578 | }; |
| 13579 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13580 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 13581 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13582 | MockRead reads2[] = { |
| 13583 | CreateMockRead(*resp2, 1), |
| 13584 | CreateMockRead(*body2, 2), |
| 13585 | MockRead(ASYNC, OK, 3) // EOF |
| 13586 | }; |
| 13587 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 13588 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 13589 | arraysize(writes2)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13590 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13591 | SSLSocketDataProvider ssl1(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13592 | ssl1.SetNextProto(GetProtocol()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 13593 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 13594 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13595 | |
| 13596 | SSLSocketDataProvider ssl2(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13597 | ssl2.SetNextProto(GetProtocol()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 13598 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 13599 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13600 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 13601 | scoped_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 13602 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13603 | |
| 13604 | // Start the first transaction to set up the SpdySession and verify that |
| 13605 | // connection was closed. |
| 13606 | HttpRequestInfo request1; |
| 13607 | request1.method = "GET"; |
| 13608 | request1.url = GURL(https_url); |
| 13609 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13610 | HttpNetworkTransaction trans1(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13611 | TestCompletionCallback callback1; |
| 13612 | EXPECT_EQ(ERR_IO_PENDING, |
| 13613 | trans1.Start(&request1, callback1.callback(), BoundNetLog())); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13614 | EXPECT_EQ(ERR_CONNECTION_CLOSED, callback1.WaitForResult()); |
| 13615 | |
| 13616 | // Now, start the second request and make sure it succeeds. |
| 13617 | HttpRequestInfo request2; |
| 13618 | request2.method = "GET"; |
| 13619 | request2.url = GURL(https_url); |
| 13620 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13621 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13622 | TestCompletionCallback callback2; |
| 13623 | EXPECT_EQ(ERR_IO_PENDING, |
| 13624 | trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13625 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 13626 | ASSERT_EQ(OK, callback2.WaitForResult()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 13627 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 13628 | } |
| 13629 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13630 | TEST_P(HttpNetworkTransactionTest, CloseIdleSpdySessionToOpenNewOne) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 13631 | session_deps_.next_protos = SpdyNextProtos(); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13632 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 13633 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 13634 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 13635 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 13636 | |
| 13637 | // Use two different hosts with different IPs so they don't get pooled. |
| 13638 | session_deps_.host_resolver->rules()->AddRule("www.a.com", "10.0.0.1"); |
| 13639 | session_deps_.host_resolver->rules()->AddRule("www.b.com", "10.0.0.2"); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 13640 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13641 | |
| 13642 | SSLSocketDataProvider ssl1(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13643 | ssl1.SetNextProto(GetProtocol()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13644 | SSLSocketDataProvider ssl2(ASYNC, OK); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13645 | ssl2.SetNextProto(GetProtocol()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13646 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 13647 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 13648 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 13649 | scoped_ptr<SpdyFrame> host1_req(spdy_util_.ConstructSpdyGet( |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13650 | "https://www.a.com", false, 1, DEFAULT_PRIORITY)); |
| 13651 | MockWrite spdy1_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13652 | CreateMockWrite(*host1_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13653 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13654 | scoped_ptr<SpdyFrame> host1_resp( |
| 13655 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 13656 | scoped_ptr<SpdyFrame> host1_resp_body( |
| 13657 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13658 | MockRead spdy1_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13659 | CreateMockRead(*host1_resp, 1), |
| 13660 | CreateMockRead(*host1_resp_body, 2), |
| 13661 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13662 | }; |
| 13663 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13664 | // Use a separate test instance for the separate SpdySession that will be |
| 13665 | // created. |
| 13666 | SpdyTestUtil spdy_util_2(GetProtocol(), GetDependenciesFromPriority()); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13667 | scoped_ptr<SequencedSocketData> spdy1_data( |
| 13668 | new SequencedSocketData(spdy1_reads, arraysize(spdy1_reads), spdy1_writes, |
| 13669 | arraysize(spdy1_writes))); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13670 | session_deps_.socket_factory->AddSocketDataProvider(spdy1_data.get()); |
| 13671 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13672 | scoped_ptr<SpdyFrame> host2_req(spdy_util_2.ConstructSpdyGet( |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13673 | "https://www.b.com", false, 1, DEFAULT_PRIORITY)); |
| 13674 | MockWrite spdy2_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13675 | CreateMockWrite(*host2_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13676 | }; |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13677 | scoped_ptr<SpdyFrame> host2_resp( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13678 | spdy_util_2.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13679 | scoped_ptr<SpdyFrame> host2_resp_body( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13680 | spdy_util_2.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13681 | MockRead spdy2_reads[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13682 | CreateMockRead(*host2_resp, 1), |
| 13683 | CreateMockRead(*host2_resp_body, 2), |
| 13684 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13685 | }; |
| 13686 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13687 | scoped_ptr<SequencedSocketData> spdy2_data( |
| 13688 | new SequencedSocketData(spdy2_reads, arraysize(spdy2_reads), spdy2_writes, |
| 13689 | arraysize(spdy2_writes))); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13690 | session_deps_.socket_factory->AddSocketDataProvider(spdy2_data.get()); |
| 13691 | |
| 13692 | MockWrite http_write[] = { |
| 13693 | MockWrite("GET / HTTP/1.1\r\n" |
| 13694 | "Host: www.a.com\r\n" |
| 13695 | "Connection: keep-alive\r\n\r\n"), |
| 13696 | }; |
| 13697 | |
| 13698 | MockRead http_read[] = { |
| 13699 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13700 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 13701 | MockRead("Content-Length: 6\r\n\r\n"), |
| 13702 | MockRead("hello!"), |
| 13703 | }; |
| 13704 | StaticSocketDataProvider http_data(http_read, arraysize(http_read), |
| 13705 | http_write, arraysize(http_write)); |
| 13706 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 13707 | |
| 13708 | HostPortPair host_port_pair_a("www.a.com", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 13709 | SpdySessionKey spdy_session_key_a( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 13710 | host_port_pair_a, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13711 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13712 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13713 | |
| 13714 | TestCompletionCallback callback; |
| 13715 | HttpRequestInfo request1; |
| 13716 | request1.method = "GET"; |
| 13717 | request1.url = GURL("https://www.a.com/"); |
| 13718 | request1.load_flags = 0; |
| 13719 | scoped_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13720 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13721 | |
| 13722 | int rv = trans->Start(&request1, callback.callback(), BoundNetLog()); |
| 13723 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13724 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 13725 | |
| 13726 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 13727 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13728 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13729 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13730 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 13731 | EXPECT_TRUE(response->was_npn_negotiated); |
| 13732 | |
| 13733 | std::string response_data; |
| 13734 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 13735 | EXPECT_EQ("hello!", response_data); |
| 13736 | trans.reset(); |
| 13737 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13738 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13739 | |
| 13740 | HostPortPair host_port_pair_b("www.b.com", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 13741 | SpdySessionKey spdy_session_key_b( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 13742 | host_port_pair_b, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13743 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13744 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13745 | HttpRequestInfo request2; |
| 13746 | request2.method = "GET"; |
| 13747 | request2.url = GURL("https://www.b.com/"); |
| 13748 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13749 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13750 | |
| 13751 | rv = trans->Start(&request2, callback.callback(), BoundNetLog()); |
| 13752 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13753 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 13754 | |
| 13755 | response = trans->GetResponseInfo(); |
| 13756 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13757 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13758 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13759 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 13760 | EXPECT_TRUE(response->was_npn_negotiated); |
| 13761 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 13762 | EXPECT_EQ("hello!", response_data); |
| 13763 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13764 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13765 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13766 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13767 | |
| 13768 | HostPortPair host_port_pair_a1("www.a.com", 80); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 13769 | SpdySessionKey spdy_session_key_a1( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 13770 | host_port_pair_a1, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13771 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13772 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a1)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13773 | HttpRequestInfo request3; |
| 13774 | request3.method = "GET"; |
| 13775 | request3.url = GURL("http://www.a.com/"); |
| 13776 | request3.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13777 | trans.reset(new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13778 | |
| 13779 | rv = trans->Start(&request3, callback.callback(), BoundNetLog()); |
| 13780 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13781 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 13782 | |
| 13783 | response = trans->GetResponseInfo(); |
| 13784 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13785 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13786 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13787 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 13788 | EXPECT_FALSE(response->was_npn_negotiated); |
| 13789 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 13790 | EXPECT_EQ("hello!", response_data); |
| 13791 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13792 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13793 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13794 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 13795 | } |
| 13796 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13797 | TEST_P(HttpNetworkTransactionTest, HttpSyncConnectError) { |
| 13798 | HttpRequestInfo request; |
| 13799 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13800 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13801 | request.load_flags = 0; |
| 13802 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 13803 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13804 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13805 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13806 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 13807 | MockConnect mock_connect(SYNCHRONOUS, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13808 | StaticSocketDataProvider data; |
| 13809 | data.set_connect_data(mock_connect); |
| 13810 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13811 | |
| 13812 | TestCompletionCallback callback; |
| 13813 | |
| 13814 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13815 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13816 | |
| 13817 | rv = callback.WaitForResult(); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 13818 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, rv); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13819 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13820 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 13821 | HttpRequestHeaders request_headers; |
| 13822 | trans->GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 13823 | |
| 13824 | ConnectionAttempts attempts; |
| 13825 | trans->GetConnectionAttempts(&attempts); |
| 13826 | ASSERT_EQ(1u, attempts.size()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 13827 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, attempts[0].result); |
| 13828 | |
| 13829 | IPEndPoint endpoint; |
| 13830 | EXPECT_FALSE(trans->GetRemoteEndpoint(&endpoint)); |
| 13831 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13832 | } |
| 13833 | |
| 13834 | TEST_P(HttpNetworkTransactionTest, HttpAsyncConnectError) { |
| 13835 | HttpRequestInfo request; |
| 13836 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13837 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13838 | request.load_flags = 0; |
| 13839 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 13840 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13841 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13842 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13843 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 13844 | MockConnect mock_connect(ASYNC, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13845 | StaticSocketDataProvider data; |
| 13846 | data.set_connect_data(mock_connect); |
| 13847 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13848 | |
| 13849 | TestCompletionCallback callback; |
| 13850 | |
| 13851 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13852 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13853 | |
| 13854 | rv = callback.WaitForResult(); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 13855 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, rv); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13856 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13857 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 13858 | HttpRequestHeaders request_headers; |
| 13859 | trans->GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 13860 | |
| 13861 | ConnectionAttempts attempts; |
| 13862 | trans->GetConnectionAttempts(&attempts); |
| 13863 | ASSERT_EQ(1u, attempts.size()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 13864 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, attempts[0].result); |
| 13865 | |
| 13866 | IPEndPoint endpoint; |
| 13867 | EXPECT_FALSE(trans->GetRemoteEndpoint(&endpoint)); |
| 13868 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13869 | } |
| 13870 | |
| 13871 | TEST_P(HttpNetworkTransactionTest, HttpSyncWriteError) { |
| 13872 | HttpRequestInfo request; |
| 13873 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13874 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13875 | request.load_flags = 0; |
| 13876 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 13877 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13878 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13879 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13880 | |
| 13881 | MockWrite data_writes[] = { |
| 13882 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 13883 | }; |
| 13884 | MockRead data_reads[] = { |
| 13885 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 13886 | }; |
| 13887 | |
| 13888 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 13889 | data_writes, arraysize(data_writes)); |
| 13890 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13891 | |
| 13892 | TestCompletionCallback callback; |
| 13893 | |
| 13894 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13895 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13896 | |
| 13897 | rv = callback.WaitForResult(); |
| 13898 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 13899 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13900 | HttpRequestHeaders request_headers; |
| 13901 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 13902 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 13903 | } |
| 13904 | |
| 13905 | TEST_P(HttpNetworkTransactionTest, HttpAsyncWriteError) { |
| 13906 | HttpRequestInfo request; |
| 13907 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13908 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13909 | request.load_flags = 0; |
| 13910 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 13911 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13912 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13913 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13914 | |
| 13915 | MockWrite data_writes[] = { |
| 13916 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
| 13917 | }; |
| 13918 | MockRead data_reads[] = { |
| 13919 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 13920 | }; |
| 13921 | |
| 13922 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 13923 | data_writes, arraysize(data_writes)); |
| 13924 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13925 | |
| 13926 | TestCompletionCallback callback; |
| 13927 | |
| 13928 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13929 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13930 | |
| 13931 | rv = callback.WaitForResult(); |
| 13932 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 13933 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13934 | HttpRequestHeaders request_headers; |
| 13935 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 13936 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 13937 | } |
| 13938 | |
| 13939 | TEST_P(HttpNetworkTransactionTest, HttpSyncReadError) { |
| 13940 | HttpRequestInfo request; |
| 13941 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13942 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13943 | request.load_flags = 0; |
| 13944 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 13945 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13946 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13947 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13948 | |
| 13949 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13950 | MockWrite( |
| 13951 | "GET / HTTP/1.1\r\n" |
| 13952 | "Host: www.example.org\r\n" |
| 13953 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13954 | }; |
| 13955 | MockRead data_reads[] = { |
| 13956 | MockRead(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 13957 | }; |
| 13958 | |
| 13959 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 13960 | data_writes, arraysize(data_writes)); |
| 13961 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13962 | |
| 13963 | TestCompletionCallback callback; |
| 13964 | |
| 13965 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 13966 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13967 | |
| 13968 | rv = callback.WaitForResult(); |
| 13969 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 13970 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13971 | HttpRequestHeaders request_headers; |
| 13972 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 13973 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 13974 | } |
| 13975 | |
| 13976 | TEST_P(HttpNetworkTransactionTest, HttpAsyncReadError) { |
| 13977 | HttpRequestInfo request; |
| 13978 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13979 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13980 | request.load_flags = 0; |
| 13981 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 13982 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13983 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13984 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13985 | |
| 13986 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13987 | MockWrite( |
| 13988 | "GET / HTTP/1.1\r\n" |
| 13989 | "Host: www.example.org\r\n" |
| 13990 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 13991 | }; |
| 13992 | MockRead data_reads[] = { |
| 13993 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
| 13994 | }; |
| 13995 | |
| 13996 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 13997 | data_writes, arraysize(data_writes)); |
| 13998 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13999 | |
| 14000 | TestCompletionCallback callback; |
| 14001 | |
| 14002 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14003 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14004 | |
| 14005 | rv = callback.WaitForResult(); |
| 14006 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 14007 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14008 | HttpRequestHeaders request_headers; |
| 14009 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 14010 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 14011 | } |
| 14012 | |
| 14013 | TEST_P(HttpNetworkTransactionTest, GetFullRequestHeadersIncludesExtraHeader) { |
| 14014 | HttpRequestInfo request; |
| 14015 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14016 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14017 | request.load_flags = 0; |
| 14018 | request.extra_headers.SetHeader("X-Foo", "bar"); |
| 14019 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14020 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14021 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14022 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14023 | |
| 14024 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14025 | MockWrite( |
| 14026 | "GET / HTTP/1.1\r\n" |
| 14027 | "Host: www.example.org\r\n" |
| 14028 | "Connection: keep-alive\r\n" |
| 14029 | "X-Foo: bar\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14030 | }; |
| 14031 | MockRead data_reads[] = { |
| 14032 | MockRead("HTTP/1.1 200 OK\r\n" |
| 14033 | "Content-Length: 5\r\n\r\n" |
| 14034 | "hello"), |
| 14035 | MockRead(ASYNC, ERR_UNEXPECTED), |
| 14036 | }; |
| 14037 | |
| 14038 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 14039 | data_writes, arraysize(data_writes)); |
| 14040 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14041 | |
| 14042 | TestCompletionCallback callback; |
| 14043 | |
| 14044 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14045 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14046 | |
| 14047 | rv = callback.WaitForResult(); |
| 14048 | EXPECT_EQ(OK, rv); |
| 14049 | |
| 14050 | HttpRequestHeaders request_headers; |
| 14051 | EXPECT_TRUE(trans->GetFullRequestHeaders(&request_headers)); |
| 14052 | std::string foo; |
| 14053 | EXPECT_TRUE(request_headers.GetHeader("X-Foo", &foo)); |
| 14054 | EXPECT_EQ("bar", foo); |
| 14055 | } |
| 14056 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14057 | namespace { |
| 14058 | |
yhirano | a7e05bb | 2014-11-06 05:40:39 | [diff] [blame] | 14059 | // Fake HttpStream that simply records calls to SetPriority(). |
| 14060 | class FakeStream : public HttpStream, |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14061 | public base::SupportsWeakPtr<FakeStream> { |
| 14062 | public: |
| 14063 | explicit FakeStream(RequestPriority priority) : priority_(priority) {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14064 | ~FakeStream() override {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14065 | |
| 14066 | RequestPriority priority() const { return priority_; } |
| 14067 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14068 | int InitializeStream(const HttpRequestInfo* request_info, |
| 14069 | RequestPriority priority, |
| 14070 | const BoundNetLog& net_log, |
| 14071 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14072 | return ERR_IO_PENDING; |
| 14073 | } |
| 14074 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14075 | int SendRequest(const HttpRequestHeaders& request_headers, |
| 14076 | HttpResponseInfo* response, |
| 14077 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14078 | ADD_FAILURE(); |
| 14079 | return ERR_UNEXPECTED; |
| 14080 | } |
| 14081 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14082 | int ReadResponseHeaders(const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14083 | ADD_FAILURE(); |
| 14084 | return ERR_UNEXPECTED; |
| 14085 | } |
| 14086 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14087 | int ReadResponseBody(IOBuffer* buf, |
| 14088 | int buf_len, |
| 14089 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14090 | ADD_FAILURE(); |
| 14091 | return ERR_UNEXPECTED; |
| 14092 | } |
| 14093 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14094 | void Close(bool not_reusable) override {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14095 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14096 | bool IsResponseBodyComplete() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14097 | ADD_FAILURE(); |
| 14098 | return false; |
| 14099 | } |
| 14100 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14101 | bool IsConnectionReused() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14102 | ADD_FAILURE(); |
| 14103 | return false; |
| 14104 | } |
| 14105 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14106 | void SetConnectionReused() override { ADD_FAILURE(); } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14107 | |
mmenke | bd84c39 | 2015-09-02 14:12:34 | [diff] [blame] | 14108 | bool CanReuseConnection() const override { return false; } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14109 | |
sclittle | 4de1bab9 | 2015-09-22 21:28:24 | [diff] [blame] | 14110 | int64_t GetTotalReceivedBytes() const override { |
[email protected] | bc92bc97 | 2013-12-13 08:32:59 | [diff] [blame] | 14111 | ADD_FAILURE(); |
| 14112 | return 0; |
| 14113 | } |
| 14114 | |
sclittle | be1ccf6 | 2015-09-02 19:40:36 | [diff] [blame] | 14115 | int64_t GetTotalSentBytes() const override { |
| 14116 | ADD_FAILURE(); |
| 14117 | return 0; |
| 14118 | } |
| 14119 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14120 | bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14121 | ADD_FAILURE(); |
| 14122 | return false; |
| 14123 | } |
| 14124 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14125 | void GetSSLInfo(SSLInfo* ssl_info) override { ADD_FAILURE(); } |
| 14126 | |
| 14127 | void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14128 | ADD_FAILURE(); |
| 14129 | } |
| 14130 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14131 | bool GetRemoteEndpoint(IPEndPoint* endpoint) override { return false; } |
| 14132 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14133 | void Drain(HttpNetworkSession* session) override { ADD_FAILURE(); } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14134 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14135 | void SetPriority(RequestPriority priority) override { priority_ = priority; } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14136 | |
yhirano | a7e05bb | 2014-11-06 05:40:39 | [diff] [blame] | 14137 | UploadProgress GetUploadProgress() const override { return UploadProgress(); } |
| 14138 | |
| 14139 | HttpStream* RenewStreamForAuth() override { return NULL; } |
| 14140 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14141 | private: |
| 14142 | RequestPriority priority_; |
| 14143 | |
| 14144 | DISALLOW_COPY_AND_ASSIGN(FakeStream); |
| 14145 | }; |
| 14146 | |
| 14147 | // Fake HttpStreamRequest that simply records calls to SetPriority() |
| 14148 | // and vends FakeStreams with its current priority. |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14149 | class FakeStreamRequest : public HttpStreamRequest, |
| 14150 | public base::SupportsWeakPtr<FakeStreamRequest> { |
| 14151 | public: |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14152 | FakeStreamRequest(RequestPriority priority, |
| 14153 | HttpStreamRequest::Delegate* delegate) |
| 14154 | : priority_(priority), |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14155 | delegate_(delegate), |
| 14156 | websocket_stream_create_helper_(NULL) {} |
| 14157 | |
| 14158 | FakeStreamRequest(RequestPriority priority, |
| 14159 | HttpStreamRequest::Delegate* delegate, |
| 14160 | WebSocketHandshakeStreamBase::CreateHelper* create_helper) |
| 14161 | : priority_(priority), |
| 14162 | delegate_(delegate), |
| 14163 | websocket_stream_create_helper_(create_helper) {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14164 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14165 | ~FakeStreamRequest() override {} |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14166 | |
| 14167 | RequestPriority priority() const { return priority_; } |
| 14168 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14169 | const WebSocketHandshakeStreamBase::CreateHelper* |
| 14170 | websocket_stream_create_helper() const { |
| 14171 | return websocket_stream_create_helper_; |
| 14172 | } |
| 14173 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14174 | // Create a new FakeStream and pass it to the request's |
| 14175 | // delegate. Returns a weak pointer to the FakeStream. |
| 14176 | base::WeakPtr<FakeStream> FinishStreamRequest() { |
| 14177 | FakeStream* fake_stream = new FakeStream(priority_); |
| 14178 | // Do this before calling OnStreamReady() as OnStreamReady() may |
| 14179 | // immediately delete |fake_stream|. |
| 14180 | base::WeakPtr<FakeStream> weak_stream = fake_stream->AsWeakPtr(); |
| 14181 | delegate_->OnStreamReady(SSLConfig(), ProxyInfo(), fake_stream); |
| 14182 | return weak_stream; |
| 14183 | } |
| 14184 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14185 | int RestartTunnelWithProxyAuth(const AuthCredentials& credentials) override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14186 | ADD_FAILURE(); |
| 14187 | return ERR_UNEXPECTED; |
| 14188 | } |
| 14189 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14190 | LoadState GetLoadState() const override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14191 | ADD_FAILURE(); |
| 14192 | return LoadState(); |
| 14193 | } |
| 14194 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14195 | void SetPriority(RequestPriority priority) override { priority_ = priority; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14196 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14197 | bool was_npn_negotiated() const override { return false; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14198 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14199 | NextProto protocol_negotiated() const override { return kProtoUnknown; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14200 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14201 | bool using_spdy() const override { return false; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14202 | |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 14203 | const ConnectionAttempts& connection_attempts() const override { |
| 14204 | static ConnectionAttempts no_attempts; |
| 14205 | return no_attempts; |
| 14206 | } |
| 14207 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14208 | private: |
| 14209 | RequestPriority priority_; |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14210 | HttpStreamRequest::Delegate* const delegate_; |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14211 | WebSocketHandshakeStreamBase::CreateHelper* websocket_stream_create_helper_; |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14212 | |
| 14213 | DISALLOW_COPY_AND_ASSIGN(FakeStreamRequest); |
| 14214 | }; |
| 14215 | |
| 14216 | // Fake HttpStreamFactory that vends FakeStreamRequests. |
| 14217 | class FakeStreamFactory : public HttpStreamFactory { |
| 14218 | public: |
| 14219 | FakeStreamFactory() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14220 | ~FakeStreamFactory() override {} |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14221 | |
| 14222 | // Returns a WeakPtr<> to the last HttpStreamRequest returned by |
| 14223 | // RequestStream() (which may be NULL if it was destroyed already). |
| 14224 | base::WeakPtr<FakeStreamRequest> last_stream_request() { |
| 14225 | return last_stream_request_; |
| 14226 | } |
| 14227 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14228 | HttpStreamRequest* RequestStream(const HttpRequestInfo& info, |
| 14229 | RequestPriority priority, |
| 14230 | const SSLConfig& server_ssl_config, |
| 14231 | const SSLConfig& proxy_ssl_config, |
| 14232 | HttpStreamRequest::Delegate* delegate, |
| 14233 | const BoundNetLog& net_log) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14234 | FakeStreamRequest* fake_request = new FakeStreamRequest(priority, delegate); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14235 | last_stream_request_ = fake_request->AsWeakPtr(); |
| 14236 | return fake_request; |
| 14237 | } |
| 14238 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14239 | HttpStreamRequest* RequestWebSocketHandshakeStream( |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14240 | const HttpRequestInfo& info, |
| 14241 | RequestPriority priority, |
| 14242 | const SSLConfig& server_ssl_config, |
| 14243 | const SSLConfig& proxy_ssl_config, |
| 14244 | HttpStreamRequest::Delegate* delegate, |
[email protected] | 467086b | 2013-11-12 08:19:46 | [diff] [blame] | 14245 | WebSocketHandshakeStreamBase::CreateHelper* create_helper, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 14246 | const BoundNetLog& net_log) override { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14247 | FakeStreamRequest* fake_request = |
| 14248 | new FakeStreamRequest(priority, delegate, create_helper); |
| 14249 | last_stream_request_ = fake_request->AsWeakPtr(); |
| 14250 | return fake_request; |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14251 | } |
| 14252 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14253 | void PreconnectStreams(int num_streams, |
| 14254 | const HttpRequestInfo& info, |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14255 | const SSLConfig& server_ssl_config, |
| 14256 | const SSLConfig& proxy_ssl_config) override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14257 | ADD_FAILURE(); |
| 14258 | } |
| 14259 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14260 | const HostMappingRules* GetHostMappingRules() const override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14261 | ADD_FAILURE(); |
| 14262 | return NULL; |
| 14263 | } |
| 14264 | |
| 14265 | private: |
| 14266 | base::WeakPtr<FakeStreamRequest> last_stream_request_; |
| 14267 | |
| 14268 | DISALLOW_COPY_AND_ASSIGN(FakeStreamFactory); |
| 14269 | }; |
| 14270 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14271 | // TODO(ricea): Maybe unify this with the one in |
| 14272 | // url_request_http_job_unittest.cc ? |
| 14273 | class FakeWebSocketBasicHandshakeStream : public WebSocketHandshakeStreamBase { |
| 14274 | public: |
| 14275 | FakeWebSocketBasicHandshakeStream(scoped_ptr<ClientSocketHandle> connection, |
| 14276 | bool using_proxy) |
| 14277 | : state_(connection.release(), using_proxy) {} |
| 14278 | |
| 14279 | // Fake implementation of HttpStreamBase methods. |
| 14280 | // This ends up being quite "real" because this object has to really send data |
| 14281 | // on the mock socket. It might be easier to use the real implementation, but |
| 14282 | // the fact that the WebSocket code is not compiled on iOS makes that |
| 14283 | // difficult. |
| 14284 | int InitializeStream(const HttpRequestInfo* request_info, |
| 14285 | RequestPriority priority, |
| 14286 | const BoundNetLog& net_log, |
| 14287 | const CompletionCallback& callback) override { |
| 14288 | state_.Initialize(request_info, priority, net_log, callback); |
| 14289 | return OK; |
| 14290 | } |
| 14291 | |
| 14292 | int SendRequest(const HttpRequestHeaders& request_headers, |
| 14293 | HttpResponseInfo* response, |
| 14294 | const CompletionCallback& callback) override { |
| 14295 | return parser()->SendRequest(state_.GenerateRequestLine(), request_headers, |
| 14296 | response, callback); |
| 14297 | } |
| 14298 | |
| 14299 | int ReadResponseHeaders(const CompletionCallback& callback) override { |
| 14300 | return parser()->ReadResponseHeaders(callback); |
| 14301 | } |
| 14302 | |
| 14303 | int ReadResponseBody(IOBuffer* buf, |
| 14304 | int buf_len, |
| 14305 | const CompletionCallback& callback) override { |
| 14306 | NOTREACHED(); |
| 14307 | return ERR_IO_PENDING; |
| 14308 | } |
| 14309 | |
| 14310 | void Close(bool not_reusable) override { |
| 14311 | if (parser()) |
| 14312 | parser()->Close(true); |
| 14313 | } |
| 14314 | |
| 14315 | bool IsResponseBodyComplete() const override { |
| 14316 | NOTREACHED(); |
| 14317 | return false; |
| 14318 | } |
| 14319 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14320 | bool IsConnectionReused() const override { |
| 14321 | NOTREACHED(); |
| 14322 | return false; |
| 14323 | } |
| 14324 | void SetConnectionReused() override { NOTREACHED(); } |
| 14325 | |
mmenke | bd84c39 | 2015-09-02 14:12:34 | [diff] [blame] | 14326 | bool CanReuseConnection() const override { return false; } |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14327 | |
sclittle | 4de1bab9 | 2015-09-22 21:28:24 | [diff] [blame] | 14328 | int64_t GetTotalReceivedBytes() const override { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14329 | NOTREACHED(); |
| 14330 | return 0; |
| 14331 | } |
| 14332 | |
sclittle | be1ccf6 | 2015-09-02 19:40:36 | [diff] [blame] | 14333 | int64_t GetTotalSentBytes() const override { |
| 14334 | NOTREACHED(); |
| 14335 | return 0; |
| 14336 | } |
| 14337 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14338 | bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override { |
| 14339 | NOTREACHED(); |
| 14340 | return false; |
| 14341 | } |
| 14342 | |
Adam Rice | cb76ac6 | 2015-02-20 05:33:25 | [diff] [blame] | 14343 | void GetSSLInfo(SSLInfo* ssl_info) override {} |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14344 | |
| 14345 | void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override { |
| 14346 | NOTREACHED(); |
| 14347 | } |
| 14348 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14349 | bool GetRemoteEndpoint(IPEndPoint* endpoint) override { return false; } |
| 14350 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14351 | void Drain(HttpNetworkSession* session) override { NOTREACHED(); } |
| 14352 | |
| 14353 | void SetPriority(RequestPriority priority) override { NOTREACHED(); } |
| 14354 | |
| 14355 | UploadProgress GetUploadProgress() const override { |
| 14356 | NOTREACHED(); |
| 14357 | return UploadProgress(); |
| 14358 | } |
| 14359 | |
| 14360 | HttpStream* RenewStreamForAuth() override { |
| 14361 | NOTREACHED(); |
| 14362 | return nullptr; |
| 14363 | } |
| 14364 | |
| 14365 | // Fake implementation of WebSocketHandshakeStreamBase method(s) |
| 14366 | scoped_ptr<WebSocketStream> Upgrade() override { |
| 14367 | NOTREACHED(); |
| 14368 | return scoped_ptr<WebSocketStream>(); |
| 14369 | } |
| 14370 | |
| 14371 | private: |
| 14372 | HttpStreamParser* parser() const { return state_.parser(); } |
| 14373 | HttpBasicState state_; |
| 14374 | |
| 14375 | DISALLOW_COPY_AND_ASSIGN(FakeWebSocketBasicHandshakeStream); |
| 14376 | }; |
| 14377 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14378 | // TODO(yhirano): Split this class out into a net/websockets file, if it is |
| 14379 | // worth doing. |
| 14380 | class FakeWebSocketStreamCreateHelper : |
| 14381 | public WebSocketHandshakeStreamBase::CreateHelper { |
| 14382 | public: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14383 | WebSocketHandshakeStreamBase* CreateBasicStream( |
[email protected] | 7e841a5 | 2013-11-22 09:04:21 | [diff] [blame] | 14384 | scoped_ptr<ClientSocketHandle> connection, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 14385 | bool using_proxy) override { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 14386 | return new FakeWebSocketBasicHandshakeStream(connection.Pass(), |
| 14387 | using_proxy); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14388 | } |
| 14389 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14390 | WebSocketHandshakeStreamBase* CreateSpdyStream( |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14391 | const base::WeakPtr<SpdySession>& session, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 14392 | bool use_relative_url) override { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14393 | NOTREACHED(); |
| 14394 | return NULL; |
| 14395 | }; |
| 14396 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14397 | ~FakeWebSocketStreamCreateHelper() override {} |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14398 | |
| 14399 | virtual scoped_ptr<WebSocketStream> Upgrade() { |
| 14400 | NOTREACHED(); |
| 14401 | return scoped_ptr<WebSocketStream>(); |
| 14402 | } |
| 14403 | }; |
| 14404 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14405 | } // namespace |
| 14406 | |
| 14407 | // Make sure that HttpNetworkTransaction passes on its priority to its |
| 14408 | // stream request on start. |
| 14409 | TEST_P(HttpNetworkTransactionTest, SetStreamRequestPriorityOnStart) { |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14410 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14411 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14412 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14413 | peer.SetHttpStreamFactory(scoped_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14414 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14415 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14416 | |
| 14417 | ASSERT_TRUE(fake_factory->last_stream_request() == NULL); |
| 14418 | |
| 14419 | HttpRequestInfo request; |
| 14420 | TestCompletionCallback callback; |
| 14421 | EXPECT_EQ(ERR_IO_PENDING, |
| 14422 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 14423 | |
| 14424 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 14425 | fake_factory->last_stream_request(); |
| 14426 | ASSERT_TRUE(fake_request != NULL); |
| 14427 | EXPECT_EQ(LOW, fake_request->priority()); |
| 14428 | } |
| 14429 | |
| 14430 | // Make sure that HttpNetworkTransaction passes on its priority |
| 14431 | // updates to its stream request. |
| 14432 | TEST_P(HttpNetworkTransactionTest, SetStreamRequestPriority) { |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14433 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14434 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14435 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14436 | peer.SetHttpStreamFactory(scoped_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14437 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14438 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 14439 | |
| 14440 | HttpRequestInfo request; |
| 14441 | TestCompletionCallback callback; |
| 14442 | EXPECT_EQ(ERR_IO_PENDING, |
| 14443 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 14444 | |
| 14445 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 14446 | fake_factory->last_stream_request(); |
| 14447 | ASSERT_TRUE(fake_request != NULL); |
| 14448 | EXPECT_EQ(LOW, fake_request->priority()); |
| 14449 | |
| 14450 | trans.SetPriority(LOWEST); |
| 14451 | ASSERT_TRUE(fake_request != NULL); |
| 14452 | EXPECT_EQ(LOWEST, fake_request->priority()); |
| 14453 | } |
| 14454 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14455 | // Make sure that HttpNetworkTransaction passes on its priority |
| 14456 | // updates to its stream. |
| 14457 | TEST_P(HttpNetworkTransactionTest, SetStreamPriority) { |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14458 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14459 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14460 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14461 | peer.SetHttpStreamFactory(scoped_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14462 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14463 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 14464 | |
| 14465 | HttpRequestInfo request; |
| 14466 | TestCompletionCallback callback; |
| 14467 | EXPECT_EQ(ERR_IO_PENDING, |
| 14468 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 14469 | |
| 14470 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 14471 | fake_factory->last_stream_request(); |
| 14472 | ASSERT_TRUE(fake_request != NULL); |
| 14473 | base::WeakPtr<FakeStream> fake_stream = fake_request->FinishStreamRequest(); |
| 14474 | ASSERT_TRUE(fake_stream != NULL); |
| 14475 | EXPECT_EQ(LOW, fake_stream->priority()); |
| 14476 | |
| 14477 | trans.SetPriority(LOWEST); |
| 14478 | EXPECT_EQ(LOWEST, fake_stream->priority()); |
| 14479 | } |
| 14480 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14481 | TEST_P(HttpNetworkTransactionTest, CreateWebSocketHandshakeStream) { |
| 14482 | // The same logic needs to be tested for both ws: and wss: schemes, but this |
| 14483 | // test is already parameterised on NextProto, so it uses a loop to verify |
| 14484 | // that the different schemes work. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14485 | std::string test_cases[] = {"ws://www.example.org/", |
| 14486 | "wss://www.example.org/"}; |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14487 | for (size_t i = 0; i < arraysize(test_cases); ++i) { |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14488 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14489 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14490 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
| 14491 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
[email protected] | 0191b51c | 2013-11-18 10:55:23 | [diff] [blame] | 14492 | peer.SetHttpStreamFactoryForWebSocket( |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14493 | scoped_ptr<HttpStreamFactory>(fake_factory)); |
| 14494 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14495 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 14496 | trans.SetWebSocketHandshakeStreamCreateHelper( |
| 14497 | &websocket_stream_create_helper); |
| 14498 | |
| 14499 | HttpRequestInfo request; |
| 14500 | TestCompletionCallback callback; |
| 14501 | request.method = "GET"; |
| 14502 | request.url = GURL(test_cases[i]); |
| 14503 | |
| 14504 | EXPECT_EQ(ERR_IO_PENDING, |
| 14505 | trans.Start(&request, callback.callback(), BoundNetLog())); |
| 14506 | |
| 14507 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 14508 | fake_factory->last_stream_request(); |
| 14509 | ASSERT_TRUE(fake_request != NULL); |
| 14510 | EXPECT_EQ(&websocket_stream_create_helper, |
| 14511 | fake_request->websocket_stream_create_helper()); |
| 14512 | } |
| 14513 | } |
| 14514 | |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14515 | // Tests that when a used socket is returned to the SSL socket pool, it's closed |
| 14516 | // if the transport socket pool is stalled on the global socket limit. |
| 14517 | TEST_P(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest) { |
| 14518 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 14519 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 14520 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 14521 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 14522 | |
| 14523 | // Set up SSL request. |
| 14524 | |
| 14525 | HttpRequestInfo ssl_request; |
| 14526 | ssl_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14527 | ssl_request.url = GURL("https://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14528 | |
| 14529 | MockWrite ssl_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14530 | MockWrite( |
| 14531 | "GET / HTTP/1.1\r\n" |
| 14532 | "Host: www.example.org\r\n" |
| 14533 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14534 | }; |
| 14535 | MockRead ssl_reads[] = { |
| 14536 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14537 | MockRead("Content-Length: 11\r\n\r\n"), |
| 14538 | MockRead("hello world"), |
| 14539 | MockRead(SYNCHRONOUS, OK), |
| 14540 | }; |
| 14541 | StaticSocketDataProvider ssl_data(ssl_reads, arraysize(ssl_reads), |
| 14542 | ssl_writes, arraysize(ssl_writes)); |
| 14543 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 14544 | |
| 14545 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 14546 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 14547 | |
| 14548 | // Set up HTTP request. |
| 14549 | |
| 14550 | HttpRequestInfo http_request; |
| 14551 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14552 | http_request.url = GURL("http://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14553 | |
| 14554 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14555 | MockWrite( |
| 14556 | "GET / HTTP/1.1\r\n" |
| 14557 | "Host: www.example.org\r\n" |
| 14558 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14559 | }; |
| 14560 | MockRead http_reads[] = { |
| 14561 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14562 | MockRead("Content-Length: 7\r\n\r\n"), |
| 14563 | MockRead("falafel"), |
| 14564 | MockRead(SYNCHRONOUS, OK), |
| 14565 | }; |
| 14566 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 14567 | http_writes, arraysize(http_writes)); |
| 14568 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 14569 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14570 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14571 | |
| 14572 | // Start the SSL request. |
| 14573 | TestCompletionCallback ssl_callback; |
| 14574 | scoped_ptr<HttpTransaction> ssl_trans( |
| 14575 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 14576 | ASSERT_EQ(ERR_IO_PENDING, |
| 14577 | ssl_trans->Start(&ssl_request, ssl_callback.callback(), |
| 14578 | BoundNetLog())); |
| 14579 | |
| 14580 | // Start the HTTP request. Pool should stall. |
| 14581 | TestCompletionCallback http_callback; |
| 14582 | scoped_ptr<HttpTransaction> http_trans( |
| 14583 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 14584 | ASSERT_EQ(ERR_IO_PENDING, |
| 14585 | http_trans->Start(&http_request, http_callback.callback(), |
| 14586 | BoundNetLog())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14587 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14588 | |
| 14589 | // Wait for response from SSL request. |
| 14590 | ASSERT_EQ(OK, ssl_callback.WaitForResult()); |
| 14591 | std::string response_data; |
| 14592 | ASSERT_EQ(OK, ReadTransaction(ssl_trans.get(), &response_data)); |
| 14593 | EXPECT_EQ("hello world", response_data); |
| 14594 | |
| 14595 | // The SSL socket should automatically be closed, so the HTTP request can |
| 14596 | // start. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14597 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 14598 | ASSERT_FALSE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14599 | |
| 14600 | // The HTTP request can now complete. |
| 14601 | ASSERT_EQ(OK, http_callback.WaitForResult()); |
| 14602 | ASSERT_EQ(OK, ReadTransaction(http_trans.get(), &response_data)); |
| 14603 | EXPECT_EQ("falafel", response_data); |
| 14604 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14605 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14606 | } |
| 14607 | |
| 14608 | // Tests that when a SSL connection is established but there's no corresponding |
| 14609 | // request that needs it, the new socket is closed if the transport socket pool |
| 14610 | // is stalled on the global socket limit. |
| 14611 | TEST_P(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest2) { |
| 14612 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 14613 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 14614 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 14615 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 14616 | |
| 14617 | // Set up an ssl request. |
| 14618 | |
| 14619 | HttpRequestInfo ssl_request; |
| 14620 | ssl_request.method = "GET"; |
| 14621 | ssl_request.url = GURL("https://www.foopy.com/"); |
| 14622 | |
| 14623 | // No data will be sent on the SSL socket. |
| 14624 | StaticSocketDataProvider ssl_data; |
| 14625 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 14626 | |
| 14627 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 14628 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 14629 | |
| 14630 | // Set up HTTP request. |
| 14631 | |
| 14632 | HttpRequestInfo http_request; |
| 14633 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14634 | http_request.url = GURL("http://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14635 | |
| 14636 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14637 | MockWrite( |
| 14638 | "GET / HTTP/1.1\r\n" |
| 14639 | "Host: www.example.org\r\n" |
| 14640 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14641 | }; |
| 14642 | MockRead http_reads[] = { |
| 14643 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14644 | MockRead("Content-Length: 7\r\n\r\n"), |
| 14645 | MockRead("falafel"), |
| 14646 | MockRead(SYNCHRONOUS, OK), |
| 14647 | }; |
| 14648 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 14649 | http_writes, arraysize(http_writes)); |
| 14650 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 14651 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14652 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14653 | |
| 14654 | // Preconnect an SSL socket. A preconnect is needed because connect jobs are |
| 14655 | // cancelled when a normal transaction is cancelled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14656 | HttpStreamFactory* http_stream_factory = session->http_stream_factory(); |
| 14657 | SSLConfig ssl_config; |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14658 | session->ssl_config_service()->GetSSLConfig(&ssl_config); |
mmenke | d1205bd397 | 2015-07-15 22:26:35 | [diff] [blame] | 14659 | http_stream_factory->PreconnectStreams(1, ssl_request, ssl_config, |
| 14660 | ssl_config); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14661 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14662 | |
| 14663 | // Start the HTTP request. Pool should stall. |
| 14664 | TestCompletionCallback http_callback; |
| 14665 | scoped_ptr<HttpTransaction> http_trans( |
| 14666 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 14667 | ASSERT_EQ(ERR_IO_PENDING, |
| 14668 | http_trans->Start(&http_request, http_callback.callback(), |
| 14669 | BoundNetLog())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14670 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14671 | |
| 14672 | // The SSL connection will automatically be closed once the connection is |
| 14673 | // established, to let the HTTP request start. |
| 14674 | ASSERT_EQ(OK, http_callback.WaitForResult()); |
| 14675 | std::string response_data; |
| 14676 | ASSERT_EQ(OK, ReadTransaction(http_trans.get(), &response_data)); |
| 14677 | EXPECT_EQ("falafel", response_data); |
| 14678 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14679 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 14680 | } |
| 14681 | |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14682 | TEST_P(HttpNetworkTransactionTest, PostReadsErrorResponseAfterReset) { |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 14683 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 14684 | element_readers.push_back( |
| 14685 | make_scoped_ptr(new UploadBytesElementReader("foo", 3))); |
| 14686 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14687 | |
| 14688 | HttpRequestInfo request; |
| 14689 | request.method = "POST"; |
| 14690 | request.url = GURL("http://www.foo.com/"); |
| 14691 | request.upload_data_stream = &upload_data_stream; |
| 14692 | request.load_flags = 0; |
| 14693 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14694 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14695 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14696 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14697 | // Send headers successfully, but get an error while sending the body. |
| 14698 | MockWrite data_writes[] = { |
| 14699 | MockWrite("POST / HTTP/1.1\r\n" |
| 14700 | "Host: www.foo.com\r\n" |
| 14701 | "Connection: keep-alive\r\n" |
| 14702 | "Content-Length: 3\r\n\r\n"), |
| 14703 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14704 | }; |
| 14705 | |
| 14706 | MockRead data_reads[] = { |
| 14707 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 14708 | MockRead("hello world"), |
| 14709 | MockRead(SYNCHRONOUS, OK), |
| 14710 | }; |
| 14711 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14712 | arraysize(data_writes)); |
| 14713 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14714 | |
| 14715 | TestCompletionCallback callback; |
| 14716 | |
| 14717 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14718 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14719 | |
| 14720 | rv = callback.WaitForResult(); |
| 14721 | EXPECT_EQ(OK, rv); |
| 14722 | |
| 14723 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 14724 | ASSERT_TRUE(response != NULL); |
| 14725 | |
| 14726 | EXPECT_TRUE(response->headers.get() != NULL); |
| 14727 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 14728 | |
| 14729 | std::string response_data; |
| 14730 | rv = ReadTransaction(trans.get(), &response_data); |
| 14731 | EXPECT_EQ(OK, rv); |
| 14732 | EXPECT_EQ("hello world", response_data); |
| 14733 | } |
| 14734 | |
| 14735 | // This test makes sure the retry logic doesn't trigger when reading an error |
| 14736 | // response from a server that rejected a POST with a CONNECTION_RESET. |
| 14737 | TEST_P(HttpNetworkTransactionTest, |
| 14738 | PostReadsErrorResponseAfterResetOnReusedSocket) { |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14739 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14740 | MockWrite data_writes[] = { |
| 14741 | MockWrite("GET / HTTP/1.1\r\n" |
| 14742 | "Host: www.foo.com\r\n" |
| 14743 | "Connection: keep-alive\r\n\r\n"), |
| 14744 | MockWrite("POST / HTTP/1.1\r\n" |
| 14745 | "Host: www.foo.com\r\n" |
| 14746 | "Connection: keep-alive\r\n" |
| 14747 | "Content-Length: 3\r\n\r\n"), |
| 14748 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14749 | }; |
| 14750 | |
| 14751 | MockRead data_reads[] = { |
| 14752 | MockRead("HTTP/1.1 200 Peachy\r\n" |
| 14753 | "Content-Length: 14\r\n\r\n"), |
| 14754 | MockRead("first response"), |
| 14755 | MockRead("HTTP/1.1 400 Not OK\r\n" |
| 14756 | "Content-Length: 15\r\n\r\n"), |
| 14757 | MockRead("second response"), |
| 14758 | MockRead(SYNCHRONOUS, OK), |
| 14759 | }; |
| 14760 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14761 | arraysize(data_writes)); |
| 14762 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14763 | |
| 14764 | TestCompletionCallback callback; |
| 14765 | HttpRequestInfo request1; |
| 14766 | request1.method = "GET"; |
| 14767 | request1.url = GURL("http://www.foo.com/"); |
| 14768 | request1.load_flags = 0; |
| 14769 | |
| 14770 | scoped_ptr<HttpTransaction> trans1( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14771 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14772 | int rv = trans1->Start(&request1, callback.callback(), BoundNetLog()); |
| 14773 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14774 | |
| 14775 | rv = callback.WaitForResult(); |
| 14776 | EXPECT_EQ(OK, rv); |
| 14777 | |
| 14778 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 14779 | ASSERT_TRUE(response1 != NULL); |
| 14780 | |
| 14781 | EXPECT_TRUE(response1->headers.get() != NULL); |
| 14782 | EXPECT_EQ("HTTP/1.1 200 Peachy", response1->headers->GetStatusLine()); |
| 14783 | |
| 14784 | std::string response_data1; |
| 14785 | rv = ReadTransaction(trans1.get(), &response_data1); |
| 14786 | EXPECT_EQ(OK, rv); |
| 14787 | EXPECT_EQ("first response", response_data1); |
| 14788 | // Delete the transaction to release the socket back into the socket pool. |
| 14789 | trans1.reset(); |
| 14790 | |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 14791 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 14792 | element_readers.push_back( |
| 14793 | make_scoped_ptr(new UploadBytesElementReader("foo", 3))); |
| 14794 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14795 | |
| 14796 | HttpRequestInfo request2; |
| 14797 | request2.method = "POST"; |
| 14798 | request2.url = GURL("http://www.foo.com/"); |
| 14799 | request2.upload_data_stream = &upload_data_stream; |
| 14800 | request2.load_flags = 0; |
| 14801 | |
| 14802 | scoped_ptr<HttpTransaction> trans2( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14803 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14804 | rv = trans2->Start(&request2, callback.callback(), BoundNetLog()); |
| 14805 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14806 | |
| 14807 | rv = callback.WaitForResult(); |
| 14808 | EXPECT_EQ(OK, rv); |
| 14809 | |
| 14810 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 14811 | ASSERT_TRUE(response2 != NULL); |
| 14812 | |
| 14813 | EXPECT_TRUE(response2->headers.get() != NULL); |
| 14814 | EXPECT_EQ("HTTP/1.1 400 Not OK", response2->headers->GetStatusLine()); |
| 14815 | |
| 14816 | std::string response_data2; |
| 14817 | rv = ReadTransaction(trans2.get(), &response_data2); |
| 14818 | EXPECT_EQ(OK, rv); |
| 14819 | EXPECT_EQ("second response", response_data2); |
| 14820 | } |
| 14821 | |
| 14822 | TEST_P(HttpNetworkTransactionTest, |
| 14823 | PostReadsErrorResponseAfterResetPartialBodySent) { |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 14824 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 14825 | element_readers.push_back( |
| 14826 | make_scoped_ptr(new UploadBytesElementReader("foo", 3))); |
| 14827 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14828 | |
| 14829 | HttpRequestInfo request; |
| 14830 | request.method = "POST"; |
| 14831 | request.url = GURL("http://www.foo.com/"); |
| 14832 | request.upload_data_stream = &upload_data_stream; |
| 14833 | request.load_flags = 0; |
| 14834 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14835 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14836 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14837 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14838 | // Send headers successfully, but get an error while sending the body. |
| 14839 | MockWrite data_writes[] = { |
| 14840 | MockWrite("POST / HTTP/1.1\r\n" |
| 14841 | "Host: www.foo.com\r\n" |
| 14842 | "Connection: keep-alive\r\n" |
| 14843 | "Content-Length: 3\r\n\r\n" |
| 14844 | "fo"), |
| 14845 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14846 | }; |
| 14847 | |
| 14848 | MockRead data_reads[] = { |
| 14849 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 14850 | MockRead("hello world"), |
| 14851 | MockRead(SYNCHRONOUS, OK), |
| 14852 | }; |
| 14853 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14854 | arraysize(data_writes)); |
| 14855 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14856 | |
| 14857 | TestCompletionCallback callback; |
| 14858 | |
| 14859 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14860 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14861 | |
| 14862 | rv = callback.WaitForResult(); |
| 14863 | EXPECT_EQ(OK, rv); |
| 14864 | |
| 14865 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 14866 | ASSERT_TRUE(response != NULL); |
| 14867 | |
| 14868 | EXPECT_TRUE(response->headers.get() != NULL); |
| 14869 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 14870 | |
| 14871 | std::string response_data; |
| 14872 | rv = ReadTransaction(trans.get(), &response_data); |
| 14873 | EXPECT_EQ(OK, rv); |
| 14874 | EXPECT_EQ("hello world", response_data); |
| 14875 | } |
| 14876 | |
| 14877 | // This tests the more common case than the previous test, where headers and |
| 14878 | // body are not merged into a single request. |
| 14879 | TEST_P(HttpNetworkTransactionTest, ChunkedPostReadsErrorResponseAfterReset) { |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 14880 | ChunkedUploadDataStream upload_data_stream(0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14881 | |
| 14882 | HttpRequestInfo request; |
| 14883 | request.method = "POST"; |
| 14884 | request.url = GURL("http://www.foo.com/"); |
| 14885 | request.upload_data_stream = &upload_data_stream; |
| 14886 | request.load_flags = 0; |
| 14887 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14888 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14889 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14890 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14891 | // Send headers successfully, but get an error while sending the body. |
| 14892 | MockWrite data_writes[] = { |
| 14893 | MockWrite("POST / HTTP/1.1\r\n" |
| 14894 | "Host: www.foo.com\r\n" |
| 14895 | "Connection: keep-alive\r\n" |
| 14896 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 14897 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14898 | }; |
| 14899 | |
| 14900 | MockRead data_reads[] = { |
| 14901 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 14902 | MockRead("hello world"), |
| 14903 | MockRead(SYNCHRONOUS, OK), |
| 14904 | }; |
| 14905 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14906 | arraysize(data_writes)); |
| 14907 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14908 | |
| 14909 | TestCompletionCallback callback; |
| 14910 | |
| 14911 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14912 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14913 | // Make sure the headers are sent before adding a chunk. This ensures that |
| 14914 | // they can't be merged with the body in a single send. Not currently |
| 14915 | // necessary since a chunked body is never merged with headers, but this makes |
| 14916 | // the test more future proof. |
| 14917 | base::RunLoop().RunUntilIdle(); |
| 14918 | |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 14919 | upload_data_stream.AppendData("last chunk", 10, true); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14920 | |
| 14921 | rv = callback.WaitForResult(); |
| 14922 | EXPECT_EQ(OK, rv); |
| 14923 | |
| 14924 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 14925 | ASSERT_TRUE(response != NULL); |
| 14926 | |
| 14927 | EXPECT_TRUE(response->headers.get() != NULL); |
| 14928 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 14929 | |
| 14930 | std::string response_data; |
| 14931 | rv = ReadTransaction(trans.get(), &response_data); |
| 14932 | EXPECT_EQ(OK, rv); |
| 14933 | EXPECT_EQ("hello world", response_data); |
| 14934 | } |
| 14935 | |
| 14936 | TEST_P(HttpNetworkTransactionTest, PostReadsErrorResponseAfterResetAnd100) { |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 14937 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 14938 | element_readers.push_back( |
| 14939 | make_scoped_ptr(new UploadBytesElementReader("foo", 3))); |
| 14940 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14941 | |
| 14942 | HttpRequestInfo request; |
| 14943 | request.method = "POST"; |
| 14944 | request.url = GURL("http://www.foo.com/"); |
| 14945 | request.upload_data_stream = &upload_data_stream; |
| 14946 | request.load_flags = 0; |
| 14947 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14948 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14949 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14950 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14951 | |
| 14952 | MockWrite data_writes[] = { |
| 14953 | MockWrite("POST / HTTP/1.1\r\n" |
| 14954 | "Host: www.foo.com\r\n" |
| 14955 | "Connection: keep-alive\r\n" |
| 14956 | "Content-Length: 3\r\n\r\n"), |
| 14957 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14958 | }; |
| 14959 | |
| 14960 | MockRead data_reads[] = { |
| 14961 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 14962 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 14963 | MockRead("hello world"), |
| 14964 | MockRead(SYNCHRONOUS, OK), |
| 14965 | }; |
| 14966 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 14967 | arraysize(data_writes)); |
| 14968 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14969 | |
| 14970 | TestCompletionCallback callback; |
| 14971 | |
| 14972 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 14973 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 14974 | |
| 14975 | rv = callback.WaitForResult(); |
| 14976 | EXPECT_EQ(OK, rv); |
| 14977 | |
| 14978 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 14979 | ASSERT_TRUE(response != NULL); |
| 14980 | |
| 14981 | EXPECT_TRUE(response->headers.get() != NULL); |
| 14982 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 14983 | |
| 14984 | std::string response_data; |
| 14985 | rv = ReadTransaction(trans.get(), &response_data); |
| 14986 | EXPECT_EQ(OK, rv); |
| 14987 | EXPECT_EQ("hello world", response_data); |
| 14988 | } |
| 14989 | |
| 14990 | TEST_P(HttpNetworkTransactionTest, PostIgnoresNonErrorResponseAfterReset) { |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 14991 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 14992 | element_readers.push_back( |
| 14993 | make_scoped_ptr(new UploadBytesElementReader("foo", 3))); |
| 14994 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 14995 | |
| 14996 | HttpRequestInfo request; |
| 14997 | request.method = "POST"; |
| 14998 | request.url = GURL("http://www.foo.com/"); |
| 14999 | request.upload_data_stream = &upload_data_stream; |
| 15000 | request.load_flags = 0; |
| 15001 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15002 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15003 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15004 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15005 | // Send headers successfully, but get an error while sending the body. |
| 15006 | MockWrite data_writes[] = { |
| 15007 | MockWrite("POST / HTTP/1.1\r\n" |
| 15008 | "Host: www.foo.com\r\n" |
| 15009 | "Connection: keep-alive\r\n" |
| 15010 | "Content-Length: 3\r\n\r\n"), |
| 15011 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15012 | }; |
| 15013 | |
| 15014 | MockRead data_reads[] = { |
| 15015 | MockRead("HTTP/1.0 200 Just Dandy\r\n\r\n"), |
| 15016 | MockRead("hello world"), |
| 15017 | MockRead(SYNCHRONOUS, OK), |
| 15018 | }; |
| 15019 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15020 | arraysize(data_writes)); |
| 15021 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15022 | |
| 15023 | TestCompletionCallback callback; |
| 15024 | |
| 15025 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 15026 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 15027 | |
| 15028 | rv = callback.WaitForResult(); |
| 15029 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15030 | } |
| 15031 | |
| 15032 | TEST_P(HttpNetworkTransactionTest, |
| 15033 | PostIgnoresNonErrorResponseAfterResetAnd100) { |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15034 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 15035 | element_readers.push_back( |
| 15036 | make_scoped_ptr(new UploadBytesElementReader("foo", 3))); |
| 15037 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15038 | |
| 15039 | HttpRequestInfo request; |
| 15040 | request.method = "POST"; |
| 15041 | request.url = GURL("http://www.foo.com/"); |
| 15042 | request.upload_data_stream = &upload_data_stream; |
| 15043 | request.load_flags = 0; |
| 15044 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15045 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15046 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15047 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15048 | // Send headers successfully, but get an error while sending the body. |
| 15049 | MockWrite data_writes[] = { |
| 15050 | MockWrite("POST / HTTP/1.1\r\n" |
| 15051 | "Host: www.foo.com\r\n" |
| 15052 | "Connection: keep-alive\r\n" |
| 15053 | "Content-Length: 3\r\n\r\n"), |
| 15054 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15055 | }; |
| 15056 | |
| 15057 | MockRead data_reads[] = { |
| 15058 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 15059 | MockRead("HTTP/1.0 302 Redirect\r\n"), |
| 15060 | MockRead("Location: http://somewhere-else.com/\r\n"), |
| 15061 | MockRead("Content-Length: 0\r\n\r\n"), |
| 15062 | MockRead(SYNCHRONOUS, OK), |
| 15063 | }; |
| 15064 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15065 | arraysize(data_writes)); |
| 15066 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15067 | |
| 15068 | TestCompletionCallback callback; |
| 15069 | |
| 15070 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 15071 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 15072 | |
| 15073 | rv = callback.WaitForResult(); |
| 15074 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15075 | } |
| 15076 | |
| 15077 | TEST_P(HttpNetworkTransactionTest, PostIgnoresHttp09ResponseAfterReset) { |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15078 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 15079 | element_readers.push_back( |
| 15080 | make_scoped_ptr(new UploadBytesElementReader("foo", 3))); |
| 15081 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15082 | |
| 15083 | HttpRequestInfo request; |
| 15084 | request.method = "POST"; |
| 15085 | request.url = GURL("http://www.foo.com/"); |
| 15086 | request.upload_data_stream = &upload_data_stream; |
| 15087 | request.load_flags = 0; |
| 15088 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15089 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15090 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15091 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15092 | // Send headers successfully, but get an error while sending the body. |
| 15093 | MockWrite data_writes[] = { |
| 15094 | MockWrite("POST / HTTP/1.1\r\n" |
| 15095 | "Host: www.foo.com\r\n" |
| 15096 | "Connection: keep-alive\r\n" |
| 15097 | "Content-Length: 3\r\n\r\n"), |
| 15098 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15099 | }; |
| 15100 | |
| 15101 | MockRead data_reads[] = { |
| 15102 | MockRead("HTTP 0.9 rocks!"), |
| 15103 | MockRead(SYNCHRONOUS, OK), |
| 15104 | }; |
| 15105 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15106 | arraysize(data_writes)); |
| 15107 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15108 | |
| 15109 | TestCompletionCallback callback; |
| 15110 | |
| 15111 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 15112 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 15113 | |
| 15114 | rv = callback.WaitForResult(); |
| 15115 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15116 | } |
| 15117 | |
| 15118 | TEST_P(HttpNetworkTransactionTest, PostIgnoresPartial400HeadersAfterReset) { |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15119 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 15120 | element_readers.push_back( |
| 15121 | make_scoped_ptr(new UploadBytesElementReader("foo", 3))); |
| 15122 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15123 | |
| 15124 | HttpRequestInfo request; |
| 15125 | request.method = "POST"; |
| 15126 | request.url = GURL("http://www.foo.com/"); |
| 15127 | request.upload_data_stream = &upload_data_stream; |
| 15128 | request.load_flags = 0; |
| 15129 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15130 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15131 | scoped_ptr<HttpTransaction> trans( |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15132 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15133 | // Send headers successfully, but get an error while sending the body. |
| 15134 | MockWrite data_writes[] = { |
| 15135 | MockWrite("POST / HTTP/1.1\r\n" |
| 15136 | "Host: www.foo.com\r\n" |
| 15137 | "Connection: keep-alive\r\n" |
| 15138 | "Content-Length: 3\r\n\r\n"), |
| 15139 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15140 | }; |
| 15141 | |
| 15142 | MockRead data_reads[] = { |
| 15143 | MockRead("HTTP/1.0 400 Not a Full Response\r\n"), |
| 15144 | MockRead(SYNCHRONOUS, OK), |
| 15145 | }; |
| 15146 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15147 | arraysize(data_writes)); |
| 15148 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15149 | |
| 15150 | TestCompletionCallback callback; |
| 15151 | |
| 15152 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 15153 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 15154 | |
| 15155 | rv = callback.WaitForResult(); |
| 15156 | EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15157 | } |
| 15158 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15159 | // Verify that proxy headers are not sent to the destination server when |
| 15160 | // establishing a tunnel for a secure WebSocket connection. |
| 15161 | TEST_P(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWssTunnel) { |
| 15162 | HttpRequestInfo request; |
| 15163 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15164 | request.url = GURL("wss://www.example.org/"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15165 | AddWebSocketHeaders(&request.extra_headers); |
| 15166 | |
| 15167 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 15168 | session_deps_.proxy_service = |
| 15169 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15170 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15171 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15172 | |
| 15173 | // Since a proxy is configured, try to establish a tunnel. |
| 15174 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15175 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 15176 | "Host: www.example.org:443\r\n" |
| 15177 | "Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15178 | |
| 15179 | // After calling trans->RestartWithAuth(), this is the request we should |
| 15180 | // be issuing -- the final header line contains the credentials. |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15181 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 15182 | "Host: www.example.org:443\r\n" |
| 15183 | "Proxy-Connection: keep-alive\r\n" |
| 15184 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15185 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15186 | MockWrite("GET / HTTP/1.1\r\n" |
| 15187 | "Host: www.example.org\r\n" |
| 15188 | "Connection: Upgrade\r\n" |
| 15189 | "Upgrade: websocket\r\n" |
| 15190 | "Origin: http://www.example.org\r\n" |
| 15191 | "Sec-WebSocket-Version: 13\r\n" |
| 15192 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15193 | }; |
| 15194 | |
| 15195 | // The proxy responds to the connect with a 407, using a persistent |
| 15196 | // connection. |
| 15197 | MockRead data_reads[] = { |
| 15198 | // No credentials. |
| 15199 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 15200 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 15201 | MockRead("Content-Length: 0\r\n"), |
| 15202 | MockRead("Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15203 | |
| 15204 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 15205 | |
| 15206 | MockRead("HTTP/1.1 101 Switching Protocols\r\n"), |
| 15207 | MockRead("Upgrade: websocket\r\n"), |
| 15208 | MockRead("Connection: Upgrade\r\n"), |
| 15209 | MockRead("Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n"), |
| 15210 | }; |
| 15211 | |
| 15212 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15213 | arraysize(data_writes)); |
| 15214 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15215 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 15216 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 15217 | |
| 15218 | scoped_ptr<HttpTransaction> trans( |
| 15219 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 15220 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
| 15221 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 15222 | &websocket_stream_create_helper); |
| 15223 | |
| 15224 | { |
| 15225 | TestCompletionCallback callback; |
| 15226 | |
| 15227 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 15228 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 15229 | |
| 15230 | rv = callback.WaitForResult(); |
| 15231 | EXPECT_EQ(OK, rv); |
| 15232 | } |
| 15233 | |
| 15234 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 15235 | ASSERT_TRUE(response); |
| 15236 | ASSERT_TRUE(response->headers.get()); |
| 15237 | EXPECT_EQ(407, response->headers->response_code()); |
| 15238 | |
| 15239 | { |
| 15240 | TestCompletionCallback callback; |
| 15241 | |
| 15242 | int rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 15243 | callback.callback()); |
| 15244 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 15245 | |
| 15246 | rv = callback.WaitForResult(); |
| 15247 | EXPECT_EQ(OK, rv); |
| 15248 | } |
| 15249 | |
| 15250 | response = trans->GetResponseInfo(); |
| 15251 | ASSERT_TRUE(response); |
| 15252 | ASSERT_TRUE(response->headers.get()); |
| 15253 | |
| 15254 | EXPECT_EQ(101, response->headers->response_code()); |
| 15255 | |
| 15256 | trans.reset(); |
| 15257 | session->CloseAllConnections(); |
| 15258 | } |
| 15259 | |
| 15260 | // Verify that proxy headers are not sent to the destination server when |
| 15261 | // establishing a tunnel for an insecure WebSocket connection. |
| 15262 | // This requires the authentication info to be injected into the auth cache |
| 15263 | // due to crbug.com/395064 |
| 15264 | // TODO(ricea): Change to use a 407 response once issue 395064 is fixed. |
| 15265 | TEST_P(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWsTunnel) { |
| 15266 | HttpRequestInfo request; |
| 15267 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15268 | request.url = GURL("ws://www.example.org/"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15269 | AddWebSocketHeaders(&request.extra_headers); |
| 15270 | |
| 15271 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 15272 | session_deps_.proxy_service = |
| 15273 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15274 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15275 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15276 | |
| 15277 | MockWrite data_writes[] = { |
| 15278 | // Try to establish a tunnel for the WebSocket connection, with |
| 15279 | // credentials. Because WebSockets have a separate set of socket pools, |
| 15280 | // they cannot and will not use the same TCP/IP connection as the |
| 15281 | // preflight HTTP request. |
| 15282 | MockWrite( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15283 | "CONNECT www.example.org:80 HTTP/1.1\r\n" |
| 15284 | "Host: www.example.org:80\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15285 | "Proxy-Connection: keep-alive\r\n" |
| 15286 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 15287 | |
| 15288 | MockWrite( |
| 15289 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15290 | "Host: www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15291 | "Connection: Upgrade\r\n" |
| 15292 | "Upgrade: websocket\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15293 | "Origin: http://www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15294 | "Sec-WebSocket-Version: 13\r\n" |
| 15295 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n\r\n"), |
| 15296 | }; |
| 15297 | |
| 15298 | MockRead data_reads[] = { |
| 15299 | // HTTP CONNECT with credentials. |
| 15300 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 15301 | |
| 15302 | // WebSocket connection established inside tunnel. |
| 15303 | MockRead("HTTP/1.1 101 Switching Protocols\r\n"), |
| 15304 | MockRead("Upgrade: websocket\r\n"), |
| 15305 | MockRead("Connection: Upgrade\r\n"), |
| 15306 | MockRead("Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n"), |
| 15307 | }; |
| 15308 | |
| 15309 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15310 | arraysize(data_writes)); |
| 15311 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15312 | |
| 15313 | session->http_auth_cache()->Add( |
| 15314 | GURL("http://myproxy:70/"), "MyRealm1", HttpAuth::AUTH_SCHEME_BASIC, |
| 15315 | "Basic realm=MyRealm1", AuthCredentials(kFoo, kBar), "/"); |
| 15316 | |
| 15317 | scoped_ptr<HttpTransaction> trans( |
| 15318 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 15319 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
| 15320 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 15321 | &websocket_stream_create_helper); |
| 15322 | |
| 15323 | TestCompletionCallback callback; |
| 15324 | |
| 15325 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 15326 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 15327 | |
| 15328 | rv = callback.WaitForResult(); |
| 15329 | EXPECT_EQ(OK, rv); |
| 15330 | |
| 15331 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 15332 | ASSERT_TRUE(response); |
| 15333 | ASSERT_TRUE(response->headers.get()); |
| 15334 | |
| 15335 | EXPECT_EQ(101, response->headers->response_code()); |
| 15336 | |
| 15337 | trans.reset(); |
| 15338 | session->CloseAllConnections(); |
| 15339 | } |
| 15340 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15341 | TEST_P(HttpNetworkTransactionTest, TotalNetworkBytesPost) { |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15342 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 15343 | element_readers.push_back( |
| 15344 | make_scoped_ptr(new UploadBytesElementReader("foo", 3))); |
| 15345 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15346 | |
| 15347 | HttpRequestInfo request; |
| 15348 | request.method = "POST"; |
| 15349 | request.url = GURL("http://www.foo.com/"); |
| 15350 | request.upload_data_stream = &upload_data_stream; |
| 15351 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15352 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15353 | scoped_ptr<HttpTransaction> trans( |
| 15354 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 15355 | MockWrite data_writes[] = { |
| 15356 | MockWrite("POST / HTTP/1.1\r\n" |
| 15357 | "Host: www.foo.com\r\n" |
| 15358 | "Connection: keep-alive\r\n" |
| 15359 | "Content-Length: 3\r\n\r\n"), |
| 15360 | MockWrite("foo"), |
| 15361 | }; |
| 15362 | |
| 15363 | MockRead data_reads[] = { |
| 15364 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 15365 | MockRead(SYNCHRONOUS, OK), |
| 15366 | }; |
| 15367 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15368 | arraysize(data_writes)); |
| 15369 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15370 | |
| 15371 | TestCompletionCallback callback; |
| 15372 | |
| 15373 | EXPECT_EQ(ERR_IO_PENDING, |
| 15374 | trans->Start(&request, callback.callback(), BoundNetLog())); |
| 15375 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 15376 | |
| 15377 | std::string response_data; |
| 15378 | EXPECT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 15379 | |
| 15380 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
| 15381 | trans->GetTotalSentBytes()); |
| 15382 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
| 15383 | trans->GetTotalReceivedBytes()); |
| 15384 | } |
| 15385 | |
| 15386 | TEST_P(HttpNetworkTransactionTest, TotalNetworkBytesPost100Continue) { |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15387 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 15388 | element_readers.push_back( |
| 15389 | make_scoped_ptr(new UploadBytesElementReader("foo", 3))); |
| 15390 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15391 | |
| 15392 | HttpRequestInfo request; |
| 15393 | request.method = "POST"; |
| 15394 | request.url = GURL("http://www.foo.com/"); |
| 15395 | request.upload_data_stream = &upload_data_stream; |
| 15396 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15397 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15398 | scoped_ptr<HttpTransaction> trans( |
| 15399 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 15400 | MockWrite data_writes[] = { |
| 15401 | MockWrite("POST / HTTP/1.1\r\n" |
| 15402 | "Host: www.foo.com\r\n" |
| 15403 | "Connection: keep-alive\r\n" |
| 15404 | "Content-Length: 3\r\n\r\n"), |
| 15405 | MockWrite("foo"), |
| 15406 | }; |
| 15407 | |
| 15408 | MockRead data_reads[] = { |
| 15409 | MockRead("HTTP/1.1 100 Continue\r\n\r\n"), |
| 15410 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 15411 | MockRead(SYNCHRONOUS, OK), |
| 15412 | }; |
| 15413 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15414 | arraysize(data_writes)); |
| 15415 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15416 | |
| 15417 | TestCompletionCallback callback; |
| 15418 | |
| 15419 | EXPECT_EQ(ERR_IO_PENDING, |
| 15420 | trans->Start(&request, callback.callback(), BoundNetLog())); |
| 15421 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 15422 | |
| 15423 | std::string response_data; |
| 15424 | EXPECT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 15425 | |
| 15426 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
| 15427 | trans->GetTotalSentBytes()); |
| 15428 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
| 15429 | trans->GetTotalReceivedBytes()); |
| 15430 | } |
| 15431 | |
| 15432 | TEST_P(HttpNetworkTransactionTest, TotalNetworkBytesChunkedPost) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15433 | ChunkedUploadDataStream upload_data_stream(0); |
| 15434 | |
| 15435 | HttpRequestInfo request; |
| 15436 | request.method = "POST"; |
| 15437 | request.url = GURL("http://www.foo.com/"); |
| 15438 | request.upload_data_stream = &upload_data_stream; |
| 15439 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15440 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 15441 | scoped_ptr<HttpTransaction> trans( |
| 15442 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 15443 | // Send headers successfully, but get an error while sending the body. |
| 15444 | MockWrite data_writes[] = { |
| 15445 | MockWrite("POST / HTTP/1.1\r\n" |
| 15446 | "Host: www.foo.com\r\n" |
| 15447 | "Connection: keep-alive\r\n" |
| 15448 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 15449 | MockWrite("1\r\nf\r\n"), MockWrite("2\r\noo\r\n"), MockWrite("0\r\n\r\n"), |
| 15450 | }; |
| 15451 | |
| 15452 | MockRead data_reads[] = { |
| 15453 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 15454 | MockRead(SYNCHRONOUS, OK), |
| 15455 | }; |
| 15456 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15457 | arraysize(data_writes)); |
| 15458 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15459 | |
| 15460 | TestCompletionCallback callback; |
| 15461 | |
| 15462 | EXPECT_EQ(ERR_IO_PENDING, |
| 15463 | trans->Start(&request, callback.callback(), BoundNetLog())); |
| 15464 | |
| 15465 | base::RunLoop().RunUntilIdle(); |
| 15466 | upload_data_stream.AppendData("f", 1, false); |
| 15467 | |
| 15468 | base::RunLoop().RunUntilIdle(); |
| 15469 | upload_data_stream.AppendData("oo", 2, true); |
| 15470 | |
| 15471 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 15472 | |
| 15473 | std::string response_data; |
| 15474 | EXPECT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 15475 | |
| 15476 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
| 15477 | trans->GetTotalSentBytes()); |
| 15478 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
| 15479 | trans->GetTotalReceivedBytes()); |
| 15480 | } |
| 15481 | |
bnc | f458840 | 2015-11-24 13:33:18 | [diff] [blame] | 15482 | TEST_P(HttpNetworkTransactionTest, EnableNPN) { |
| 15483 | session_deps_.next_protos = NextProtosDefaults(); |
| 15484 | session_deps_.enable_npn = true; |
| 15485 | |
| 15486 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 15487 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 15488 | |
| 15489 | EXPECT_THAT(trans.server_ssl_config_.alpn_protos, |
| 15490 | testing::ElementsAre(kProtoHTTP2, kProtoSPDY31, kProtoHTTP11)); |
| 15491 | EXPECT_THAT(trans.server_ssl_config_.npn_protos, |
| 15492 | testing::ElementsAre(kProtoHTTP2, kProtoSPDY31, kProtoHTTP11)); |
| 15493 | } |
| 15494 | |
| 15495 | TEST_P(HttpNetworkTransactionTest, DisableNPN) { |
| 15496 | session_deps_.next_protos = NextProtosDefaults(); |
| 15497 | session_deps_.enable_npn = false; |
| 15498 | |
| 15499 | scoped_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 15500 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 15501 | |
| 15502 | EXPECT_THAT(trans.server_ssl_config_.alpn_protos, |
| 15503 | testing::ElementsAre(kProtoHTTP2, kProtoSPDY31, kProtoHTTP11)); |
| 15504 | EXPECT_TRUE(trans.server_ssl_config_.npn_protos.empty()); |
| 15505 | } |
| 15506 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 15507 | } // namespace net |