[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 5 | #include <vector> |
| 6 | |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 7 | #include "base/basictypes.h" |
| 8 | #include "base/compiler_specific.h" |
| 9 | #include "base/memory/scoped_ptr.h" |
[email protected] | 98b20ce | 2013-05-10 05:55:26 | [diff] [blame] | 10 | #include "base/stl_util.h" |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 11 | #include "net/base/test_completion_callback.h" |
bnc | 50883590 | 2015-05-12 20:10:29 | [diff] [blame] | 12 | #include "net/base/test_data_directory.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 13 | #include "net/cert/mock_cert_verifier.h" |
[email protected] | f2cb3cf | 2013-03-21 01:40:53 | [diff] [blame] | 14 | #include "net/dns/mock_host_resolver.h" |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 15 | #include "net/http/http_auth_handler_factory.h" |
| 16 | #include "net/http/http_network_session.h" |
| 17 | #include "net/http/http_network_transaction.h" |
| 18 | #include "net/http/http_server_properties_impl.h" |
| 19 | #include "net/http/http_stream.h" |
| 20 | #include "net/http/http_stream_factory.h" |
[email protected] | c41737d | 2014-05-14 07:47:19 | [diff] [blame] | 21 | #include "net/http/http_transaction_test_util.h" |
[email protected] | b1c988b | 2013-06-13 06:48:11 | [diff] [blame] | 22 | #include "net/http/transport_security_state.h" |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 23 | #include "net/log/test_net_log.h" |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 24 | #include "net/log/test_net_log_entry.h" |
| 25 | #include "net/log/test_net_log_util.h" |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 26 | #include "net/proxy/proxy_config_service_fixed.h" |
| 27 | #include "net/proxy/proxy_resolver.h" |
| 28 | #include "net/proxy/proxy_service.h" |
bnc | 50883590 | 2015-05-12 20:10:29 | [diff] [blame] | 29 | #include "net/quic/crypto/proof_verifier_chromium.h" |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 30 | #include "net/quic/crypto/quic_decrypter.h" |
| 31 | #include "net/quic/crypto/quic_encrypter.h" |
| 32 | #include "net/quic/quic_framer.h" |
[email protected] | 24e5bc5 | 2013-09-18 15:36:58 | [diff] [blame] | 33 | #include "net/quic/quic_http_utils.h" |
[email protected] | ed3fc15d | 2013-03-08 18:37:44 | [diff] [blame] | 34 | #include "net/quic/test_tools/crypto_test_utils.h" |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 35 | #include "net/quic/test_tools/mock_clock.h" |
[email protected] | e8ff2684 | 2013-03-22 21:02:05 | [diff] [blame] | 36 | #include "net/quic/test_tools/mock_crypto_client_stream_factory.h" |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 37 | #include "net/quic/test_tools/mock_random.h" |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 38 | #include "net/quic/test_tools/quic_test_packet_maker.h" |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 39 | #include "net/quic/test_tools/quic_test_utils.h" |
| 40 | #include "net/socket/client_socket_factory.h" |
| 41 | #include "net/socket/mock_client_socket_pool_manager.h" |
| 42 | #include "net/socket/socket_test_util.h" |
| 43 | #include "net/socket/ssl_client_socket.h" |
| 44 | #include "net/spdy/spdy_frame_builder.h" |
| 45 | #include "net/spdy/spdy_framer.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 46 | #include "net/ssl/ssl_config_service_defaults.h" |
bnc | 50883590 | 2015-05-12 20:10:29 | [diff] [blame] | 47 | #include "net/test/cert_test_util.h" |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 48 | #include "testing/gtest/include/gtest/gtest.h" |
| 49 | #include "testing/platform_test.h" |
| 50 | |
bnc | 50883590 | 2015-05-12 20:10:29 | [diff] [blame] | 51 | namespace net { |
| 52 | namespace test { |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 53 | |
| 54 | namespace { |
| 55 | |
| 56 | // This is the expected return from a current server advertising QUIC. |
| 57 | static const char kQuicAlternateProtocolHttpHeader[] = |
[email protected] | 4ff6537 | 2013-06-21 05:45:46 | [diff] [blame] | 58 | "Alternate-Protocol: 80:quic\r\n\r\n"; |
[email protected] | 287d941 | 2014-07-08 23:01:00 | [diff] [blame] | 59 | static const char kQuicAlternateProtocol50pctHttpHeader[] = |
| 60 | "Alternate-Protocol: 80:quic,p=.5\r\n\r\n"; |
bnc | 62a44f02 | 2015-04-02 15:59:41 | [diff] [blame] | 61 | static const char kQuicAlternateProtocolDifferentPortHttpHeader[] = |
| 62 | "Alternate-Protocol: 137:quic\r\n\r\n"; |
[email protected] | 6d1b4ed | 2013-07-10 03:57:54 | [diff] [blame] | 63 | static const char kQuicAlternateProtocolHttpsHeader[] = |
| 64 | "Alternate-Protocol: 443:quic\r\n\r\n"; |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 65 | |
bnc | b07c0553 | 2015-05-14 19:07:20 | [diff] [blame] | 66 | const char kDefaultServerHostName[] = "www.google.com"; |
| 67 | |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 68 | } // namespace |
| 69 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 70 | // Helper class to encapsulate MockReads and MockWrites for QUIC. |
| 71 | // Simplify ownership issues and the interaction with the MockSocketFactory. |
| 72 | class MockQuicData { |
| 73 | public: |
rch | a5399e0 | 2015-04-21 19:32:04 | [diff] [blame] | 74 | MockQuicData() : sequence_number_(0) {} |
| 75 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 76 | ~MockQuicData() { |
| 77 | STLDeleteElements(&packets_); |
| 78 | } |
| 79 | |
rch | a5399e0 | 2015-04-21 19:32:04 | [diff] [blame] | 80 | void AddSynchronousRead(scoped_ptr<QuicEncryptedPacket> packet) { |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 81 | reads_.push_back(MockRead(SYNCHRONOUS, packet->data(), packet->length(), |
| 82 | sequence_number_++)); |
| 83 | packets_.push_back(packet.release()); |
| 84 | } |
| 85 | |
rch | a5399e0 | 2015-04-21 19:32:04 | [diff] [blame] | 86 | void AddRead(scoped_ptr<QuicEncryptedPacket> packet) { |
| 87 | reads_.push_back( |
| 88 | MockRead(ASYNC, packet->data(), packet->length(), sequence_number_++)); |
| 89 | packets_.push_back(packet.release()); |
| 90 | } |
| 91 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 92 | void AddRead(IoMode mode, int rv) { |
rch | a5399e0 | 2015-04-21 19:32:04 | [diff] [blame] | 93 | reads_.push_back(MockRead(mode, rv, sequence_number_++)); |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | void AddWrite(scoped_ptr<QuicEncryptedPacket> packet) { |
| 97 | writes_.push_back(MockWrite(SYNCHRONOUS, packet->data(), packet->length(), |
| 98 | sequence_number_++)); |
| 99 | packets_.push_back(packet.release()); |
| 100 | } |
| 101 | |
rch | a5399e0 | 2015-04-21 19:32:04 | [diff] [blame] | 102 | void AddSocketDataToFactory(MockClientSocketFactory* factory) { |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 103 | MockRead* reads = reads_.empty() ? nullptr : &reads_[0]; |
| 104 | MockWrite* writes = writes_.empty() ? nullptr : &writes_[0]; |
rch | a5399e0 | 2015-04-21 19:32:04 | [diff] [blame] | 105 | socket_data_.reset( |
| 106 | new SequencedSocketData(reads, reads_.size(), writes, writes_.size())); |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 107 | factory->AddSocketDataProvider(socket_data_.get()); |
| 108 | } |
| 109 | |
| 110 | private: |
| 111 | std::vector<QuicEncryptedPacket*> packets_; |
| 112 | std::vector<MockWrite> writes_; |
| 113 | std::vector<MockRead> reads_; |
| 114 | size_t sequence_number_; |
| 115 | scoped_ptr<SocketDataProvider> socket_data_; |
| 116 | }; |
| 117 | |
tbansal | 7cec381 | 2015-02-05 21:25:12 | [diff] [blame] | 118 | class ProxyHeadersHandler { |
| 119 | public: |
| 120 | ProxyHeadersHandler() : was_called_(false) {} |
| 121 | |
| 122 | bool was_called() { return was_called_; } |
| 123 | |
| 124 | void OnBeforeProxyHeadersSent(const ProxyInfo& proxy_info, |
| 125 | HttpRequestHeaders* request_headers) { |
| 126 | was_called_ = true; |
| 127 | } |
| 128 | |
| 129 | private: |
| 130 | bool was_called_; |
| 131 | }; |
| 132 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 133 | class QuicNetworkTransactionTest |
| 134 | : public PlatformTest, |
[email protected] | 5d03bbd | 2014-03-07 16:19:16 | [diff] [blame] | 135 | public ::testing::WithParamInterface<QuicVersion> { |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 136 | protected: |
[email protected] | 1c04f952 | 2013-02-21 20:32:43 | [diff] [blame] | 137 | QuicNetworkTransactionTest() |
rtenneti | 4b06ae7 | 2014-08-26 03:43:43 | [diff] [blame] | 138 | : clock_(new MockClock), |
bnc | b07c0553 | 2015-05-14 19:07:20 | [diff] [blame] | 139 | maker_(GetParam(), 0, clock_, kDefaultServerHostName), |
[email protected] | 1c04f952 | 2013-02-21 20:32:43 | [diff] [blame] | 140 | ssl_config_service_(new SSLConfigServiceDefaults), |
| 141 | proxy_service_(ProxyService::CreateDirect()), |
| 142 | auth_handler_factory_( |
[email protected] | dda75ab | 2013-06-22 22:43:30 | [diff] [blame] | 143 | HttpAuthHandlerFactory::CreateDefault(&host_resolver_)), |
[email protected] | 457d695 | 2013-12-13 09:24:58 | [diff] [blame] | 144 | random_generator_(0), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 145 | hanging_data_(nullptr, 0, nullptr, 0) { |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 146 | request_.method = "GET"; |
bnc | b07c0553 | 2015-05-14 19:07:20 | [diff] [blame] | 147 | std::string url("http://"); |
| 148 | url.append(kDefaultServerHostName); |
| 149 | request_.url = GURL(url); |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 150 | request_.load_flags = 0; |
[email protected] | 98a9d125 | 2014-04-04 00:43:59 | [diff] [blame] | 151 | clock_->AdvanceTime(QuicTime::Delta::FromMilliseconds(20)); |
[email protected] | 1c04f952 | 2013-02-21 20:32:43 | [diff] [blame] | 152 | } |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 153 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 154 | void SetUp() override { |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 155 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 156 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 157 | } |
| 158 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 159 | void TearDown() override { |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 160 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
| 161 | // Empty the current queue. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 162 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 163 | PlatformTest::TearDown(); |
| 164 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 165 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 166 | } |
| 167 | |
[email protected] | 3316d42 | 2013-05-03 21:45:30 | [diff] [blame] | 168 | scoped_ptr<QuicEncryptedPacket> ConstructConnectionClosePacket( |
| 169 | QuicPacketSequenceNumber num) { |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 170 | return maker_.MakeConnectionClosePacket(num); |
[email protected] | 3316d42 | 2013-05-03 21:45:30 | [diff] [blame] | 171 | } |
| 172 | |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 173 | scoped_ptr<QuicEncryptedPacket> ConstructAckPacket( |
| 174 | QuicPacketSequenceNumber largest_received, |
| 175 | QuicPacketSequenceNumber least_unacked) { |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 176 | return maker_.MakeAckPacket(2, largest_received, least_unacked, true); |
| 177 | } |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 178 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 179 | SpdyHeaderBlock GetRequestHeaders(const std::string& method, |
| 180 | const std::string& scheme, |
| 181 | const std::string& path) { |
| 182 | return maker_.GetRequestHeaders(method, scheme, path); |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 183 | } |
| 184 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 185 | SpdyHeaderBlock GetResponseHeaders(const std::string& status) { |
| 186 | return maker_.GetResponseHeaders(status); |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 187 | } |
| 188 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 189 | scoped_ptr<QuicEncryptedPacket> ConstructDataPacket( |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 190 | QuicPacketSequenceNumber sequence_number, |
[email protected] | 98b20ce | 2013-05-10 05:55:26 | [diff] [blame] | 191 | QuicStreamId stream_id, |
[email protected] | e8ff2684 | 2013-03-22 21:02:05 | [diff] [blame] | 192 | bool should_include_version, |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 193 | bool fin, |
| 194 | QuicStreamOffset offset, |
| 195 | base::StringPiece data) { |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 196 | return maker_.MakeDataPacket( |
| 197 | sequence_number, stream_id, should_include_version, fin, offset, data); |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 198 | } |
| 199 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 200 | scoped_ptr<QuicEncryptedPacket> ConstructRequestHeadersPacket( |
| 201 | QuicPacketSequenceNumber sequence_number, |
| 202 | QuicStreamId stream_id, |
| 203 | bool should_include_version, |
| 204 | bool fin, |
| 205 | const SpdyHeaderBlock& headers) { |
rtenneti | f4bdb54 | 2015-01-21 14:33:05 | [diff] [blame] | 206 | QuicPriority priority = |
| 207 | ConvertRequestPriorityToQuicPriority(DEFAULT_PRIORITY); |
| 208 | return maker_.MakeRequestHeadersPacket(sequence_number, stream_id, |
| 209 | should_include_version, fin, |
| 210 | priority, headers); |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 211 | } |
| 212 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 213 | scoped_ptr<QuicEncryptedPacket> ConstructResponseHeadersPacket( |
| 214 | QuicPacketSequenceNumber sequence_number, |
| 215 | QuicStreamId stream_id, |
| 216 | bool should_include_version, |
| 217 | bool fin, |
| 218 | const SpdyHeaderBlock& headers) { |
| 219 | return maker_.MakeResponseHeadersPacket( |
| 220 | sequence_number, stream_id, should_include_version, fin, headers); |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | void CreateSession() { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 224 | CreateSessionWithFactory(&socket_factory_, false); |
[email protected] | dda75ab | 2013-06-22 22:43:30 | [diff] [blame] | 225 | } |
| 226 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 227 | void CreateSessionWithNextProtos() { |
| 228 | CreateSessionWithFactory(&socket_factory_, true); |
| 229 | } |
| 230 | |
| 231 | // If |use_next_protos| is true, enables SPDY and QUIC. |
| 232 | void CreateSessionWithFactory(ClientSocketFactory* socket_factory, |
| 233 | bool use_next_protos) { |
[email protected] | 4dca587c | 2013-03-07 16:54:47 | [diff] [blame] | 234 | params_.enable_quic = true; |
| 235 | params_.quic_clock = clock_; |
| 236 | params_.quic_random = &random_generator_; |
[email protected] | dda75ab | 2013-06-22 22:43:30 | [diff] [blame] | 237 | params_.client_socket_factory = socket_factory; |
[email protected] | e8ff2684 | 2013-03-22 21:02:05 | [diff] [blame] | 238 | params_.quic_crypto_client_stream_factory = &crypto_client_stream_factory_; |
[email protected] | 1c04f952 | 2013-02-21 20:32:43 | [diff] [blame] | 239 | params_.host_resolver = &host_resolver_; |
| 240 | params_.cert_verifier = &cert_verifier_; |
[email protected] | b1c988b | 2013-06-13 06:48:11 | [diff] [blame] | 241 | params_.transport_security_state = &transport_security_state_; |
[email protected] | 1c04f952 | 2013-02-21 20:32:43 | [diff] [blame] | 242 | params_.proxy_service = proxy_service_.get(); |
| 243 | params_.ssl_config_service = ssl_config_service_.get(); |
| 244 | params_.http_auth_handler_factory = auth_handler_factory_.get(); |
bnc | 6be245c1 | 2015-05-15 11:24:07 | [diff] [blame] | 245 | params_.http_server_properties = http_server_properties_.GetWeakPtr(); |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 246 | params_.quic_supported_versions = SupportedVersions(GetParam()); |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 247 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 248 | if (use_next_protos) { |
| 249 | params_.use_alternate_protocols = true; |
bnc | 3bb2c23 | 2014-11-07 20:26:39 | [diff] [blame] | 250 | params_.next_protos = NextProtosWithSpdyAndQuic(true, true); |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 251 | } |
| 252 | |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 253 | session_ = new HttpNetworkSession(params_); |
[email protected] | 11c0587 | 2013-08-20 02:04:12 | [diff] [blame] | 254 | session_->quic_stream_factory()->set_require_confirmation(false); |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 255 | } |
| 256 | |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 257 | void CheckWasQuicResponse(const scoped_ptr<HttpNetworkTransaction>& trans) { |
| 258 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 259 | ASSERT_TRUE(response != nullptr); |
| 260 | ASSERT_TRUE(response->headers.get() != nullptr); |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 261 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 262 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 263 | EXPECT_TRUE(response->was_npn_negotiated); |
| 264 | EXPECT_EQ(HttpResponseInfo::CONNECTION_INFO_QUIC1_SPDY3, |
| 265 | response->connection_info); |
| 266 | } |
| 267 | |
bnc | 62a44f02 | 2015-04-02 15:59:41 | [diff] [blame] | 268 | void CheckResponsePort(const scoped_ptr<HttpNetworkTransaction>& trans, |
| 269 | uint16 port) { |
| 270 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 271 | ASSERT_TRUE(response != nullptr); |
| 272 | EXPECT_EQ(port, response->socket_address.port()); |
| 273 | } |
| 274 | |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 275 | void CheckWasHttpResponse(const scoped_ptr<HttpNetworkTransaction>& trans) { |
| 276 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 277 | ASSERT_TRUE(response != nullptr); |
| 278 | ASSERT_TRUE(response->headers.get() != nullptr); |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 279 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 280 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 281 | EXPECT_FALSE(response->was_npn_negotiated); |
| 282 | EXPECT_EQ(HttpResponseInfo::CONNECTION_INFO_HTTP1, |
| 283 | response->connection_info); |
| 284 | } |
| 285 | |
bnc | ffc2fdf | 2015-05-14 18:29:49 | [diff] [blame] | 286 | void CheckResponseData(const scoped_ptr<HttpNetworkTransaction>& trans, |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 287 | const std::string& expected) { |
| 288 | std::string response_data; |
bnc | ffc2fdf | 2015-05-14 18:29:49 | [diff] [blame] | 289 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 290 | EXPECT_EQ(expected, response_data); |
| 291 | } |
| 292 | |
bnc | ffc2fdf | 2015-05-14 18:29:49 | [diff] [blame] | 293 | void RunTransaction(const scoped_ptr<HttpNetworkTransaction>& trans) { |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 294 | TestCompletionCallback callback; |
| 295 | int rv = trans->Start(&request_, callback.callback(), net_log_.bound()); |
| 296 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 297 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 298 | } |
| 299 | |
| 300 | void SendRequestAndExpectHttpResponse(const std::string& expected) { |
| 301 | scoped_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 302 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get())); |
bnc | ffc2fdf | 2015-05-14 18:29:49 | [diff] [blame] | 303 | RunTransaction(trans); |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 304 | CheckWasHttpResponse(trans); |
bnc | ffc2fdf | 2015-05-14 18:29:49 | [diff] [blame] | 305 | CheckResponseData(trans, expected); |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | void SendRequestAndExpectQuicResponse(const std::string& expected) { |
bnc | 62a44f02 | 2015-04-02 15:59:41 | [diff] [blame] | 309 | SendRequestAndExpectQuicResponseMaybeFromProxy(expected, false, 80); |
tbansal | 7cec381 | 2015-02-05 21:25:12 | [diff] [blame] | 310 | } |
| 311 | |
bnc | 62a44f02 | 2015-04-02 15:59:41 | [diff] [blame] | 312 | void SendRequestAndExpectQuicResponseOnPort(const std::string& expected, |
| 313 | uint16 port) { |
| 314 | SendRequestAndExpectQuicResponseMaybeFromProxy(expected, false, port); |
| 315 | } |
| 316 | |
| 317 | void SendRequestAndExpectQuicResponseFromProxyOnPort( |
| 318 | const std::string& expected, |
| 319 | uint16 port) { |
| 320 | SendRequestAndExpectQuicResponseMaybeFromProxy(expected, true, port); |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | void AddQuicAlternateProtocolMapping( |
| 324 | MockCryptoClientStream::HandshakeMode handshake_mode) { |
| 325 | crypto_client_stream_factory_.set_handshake_mode(handshake_mode); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 326 | HostPortPair host_port_pair = HostPortPair::FromURL(request_.url); |
| 327 | AlternativeService alternative_service(QUIC, host_port_pair.host(), 80); |
bnc | 6be245c1 | 2015-05-15 11:24:07 | [diff] [blame] | 328 | http_server_properties_.SetAlternativeService(host_port_pair, |
| 329 | alternative_service, 1.0); |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | void ExpectBrokenAlternateProtocolMapping() { |
bnc | 8445b300 | 2015-03-13 01:57:09 | [diff] [blame] | 333 | const HostPortPair origin = HostPortPair::FromURL(request_.url); |
bnc | 181b39a | 2015-03-17 21:36:47 | [diff] [blame] | 334 | const AlternativeService alternative_service = |
bnc | 6be245c1 | 2015-05-15 11:24:07 | [diff] [blame] | 335 | http_server_properties_.GetAlternativeService(origin); |
bnc | 181b39a | 2015-03-17 21:36:47 | [diff] [blame] | 336 | EXPECT_NE(UNINITIALIZED_ALTERNATE_PROTOCOL, alternative_service.protocol); |
bnc | 6be245c1 | 2015-05-15 11:24:07 | [diff] [blame] | 337 | EXPECT_TRUE(http_server_properties_.IsAlternativeServiceBroken( |
bnc | 8445b300 | 2015-03-13 01:57:09 | [diff] [blame] | 338 | alternative_service)); |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 339 | } |
| 340 | |
[email protected] | 4d590c9c | 2014-05-02 05:14:33 | [diff] [blame] | 341 | void ExpectQuicAlternateProtocolMapping() { |
bnc | 181b39a | 2015-03-17 21:36:47 | [diff] [blame] | 342 | const AlternativeService alternative_service = |
bnc | 6be245c1 | 2015-05-15 11:24:07 | [diff] [blame] | 343 | http_server_properties_.GetAlternativeService( |
[email protected] | 4d590c9c | 2014-05-02 05:14:33 | [diff] [blame] | 344 | HostPortPair::FromURL(request_.url)); |
bnc | 181b39a | 2015-03-17 21:36:47 | [diff] [blame] | 345 | EXPECT_EQ(QUIC, alternative_service.protocol); |
[email protected] | 4d590c9c | 2014-05-02 05:14:33 | [diff] [blame] | 346 | } |
| 347 | |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 348 | void AddHangingNonAlternateProtocolSocketData() { |
[email protected] | dda75ab | 2013-06-22 22:43:30 | [diff] [blame] | 349 | MockConnect hanging_connect(SYNCHRONOUS, ERR_IO_PENDING); |
| 350 | hanging_data_.set_connect_data(hanging_connect); |
| 351 | socket_factory_.AddSocketDataProvider(&hanging_data_); |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 352 | } |
| 353 | |
rtenneti | 4b06ae7 | 2014-08-26 03:43:43 | [diff] [blame] | 354 | MockClock* clock_; // Owned by QuicStreamFactory after CreateSession. |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 355 | QuicTestPacketMaker maker_; |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 356 | scoped_refptr<HttpNetworkSession> session_; |
| 357 | MockClientSocketFactory socket_factory_; |
[email protected] | e8ff2684 | 2013-03-22 21:02:05 | [diff] [blame] | 358 | MockCryptoClientStreamFactory crypto_client_stream_factory_; |
[email protected] | 1c04f952 | 2013-02-21 20:32:43 | [diff] [blame] | 359 | MockHostResolver host_resolver_; |
| 360 | MockCertVerifier cert_verifier_; |
[email protected] | b1c988b | 2013-06-13 06:48:11 | [diff] [blame] | 361 | TransportSecurityState transport_security_state_; |
[email protected] | 1c04f952 | 2013-02-21 20:32:43 | [diff] [blame] | 362 | scoped_refptr<SSLConfigServiceDefaults> ssl_config_service_; |
| 363 | scoped_ptr<ProxyService> proxy_service_; |
| 364 | scoped_ptr<HttpAuthHandlerFactory> auth_handler_factory_; |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 365 | MockRandom random_generator_; |
bnc | 6be245c1 | 2015-05-15 11:24:07 | [diff] [blame] | 366 | HttpServerPropertiesImpl http_server_properties_; |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 367 | HttpNetworkSession::Params params_; |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 368 | HttpRequestInfo request_; |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 369 | BoundTestNetLog net_log_; |
[email protected] | dda75ab | 2013-06-22 22:43:30 | [diff] [blame] | 370 | StaticSocketDataProvider hanging_data_; |
tbansal | 7cec381 | 2015-02-05 21:25:12 | [diff] [blame] | 371 | |
| 372 | private: |
| 373 | void SendRequestAndExpectQuicResponseMaybeFromProxy( |
| 374 | const std::string& expected, |
bnc | 62a44f02 | 2015-04-02 15:59:41 | [diff] [blame] | 375 | bool used_proxy, |
| 376 | uint16 port) { |
tbansal | 7cec381 | 2015-02-05 21:25:12 | [diff] [blame] | 377 | scoped_ptr<HttpNetworkTransaction> trans( |
| 378 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get())); |
| 379 | ProxyHeadersHandler proxy_headers_handler; |
| 380 | trans->SetBeforeProxyHeadersSentCallback( |
| 381 | base::Bind(&ProxyHeadersHandler::OnBeforeProxyHeadersSent, |
| 382 | base::Unretained(&proxy_headers_handler))); |
bnc | ffc2fdf | 2015-05-14 18:29:49 | [diff] [blame] | 383 | RunTransaction(trans); |
tbansal | 7cec381 | 2015-02-05 21:25:12 | [diff] [blame] | 384 | CheckWasQuicResponse(trans); |
bnc | 62a44f02 | 2015-04-02 15:59:41 | [diff] [blame] | 385 | CheckResponsePort(trans, port); |
bnc | ffc2fdf | 2015-05-14 18:29:49 | [diff] [blame] | 386 | CheckResponseData(trans, expected); |
tbansal | 7cec381 | 2015-02-05 21:25:12 | [diff] [blame] | 387 | EXPECT_EQ(used_proxy, proxy_headers_handler.was_called()); |
| 388 | } |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 389 | }; |
| 390 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 391 | INSTANTIATE_TEST_CASE_P(Version, QuicNetworkTransactionTest, |
| 392 | ::testing::ValuesIn(QuicSupportedVersions())); |
| 393 | |
| 394 | TEST_P(QuicNetworkTransactionTest, ForceQuic) { |
[email protected] | 49e8533 | 2013-06-04 04:18:03 | [diff] [blame] | 395 | params_.origin_to_force_quic_on = |
| 396 | HostPortPair::FromString("www.google.com:80"); |
[email protected] | 4dca587c | 2013-03-07 16:54:47 | [diff] [blame] | 397 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 398 | MockQuicData mock_quic_data; |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 399 | mock_quic_data.AddWrite( |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 400 | ConstructRequestHeadersPacket(1, kClientDataStreamId1, true, true, |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 401 | GetRequestHeaders("GET", "http", "/"))); |
| 402 | mock_quic_data.AddRead( |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 403 | ConstructResponseHeadersPacket(1, kClientDataStreamId1, false, false, |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 404 | GetResponseHeaders("200 OK"))); |
| 405 | mock_quic_data.AddRead( |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 406 | ConstructDataPacket(2, kClientDataStreamId1, false, true, 0, "hello!")); |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 407 | mock_quic_data.AddWrite(ConstructAckPacket(2, 1)); |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 408 | mock_quic_data.AddRead(SYNCHRONOUS, 0); // EOF |
[email protected] | 4dca587c | 2013-03-07 16:54:47 | [diff] [blame] | 409 | |
rch | a5399e0 | 2015-04-21 19:32:04 | [diff] [blame] | 410 | mock_quic_data.AddSocketDataToFactory(&socket_factory_); |
[email protected] | 4dca587c | 2013-03-07 16:54:47 | [diff] [blame] | 411 | |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 412 | // The non-alternate protocol job needs to hang in order to guarantee that |
| 413 | // the alternate-protocol job will "win". |
| 414 | AddHangingNonAlternateProtocolSocketData(); |
[email protected] | 4dca587c | 2013-03-07 16:54:47 | [diff] [blame] | 415 | |
| 416 | CreateSession(); |
[email protected] | 4dca587c | 2013-03-07 16:54:47 | [diff] [blame] | 417 | |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 418 | SendRequestAndExpectQuicResponse("hello!"); |
[email protected] | 4dca587c | 2013-03-07 16:54:47 | [diff] [blame] | 419 | |
[email protected] | 98b20ce | 2013-05-10 05:55:26 | [diff] [blame] | 420 | // Check that the NetLog was filled reasonably. |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 421 | TestNetLogEntry::List entries; |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 422 | net_log_.GetEntries(&entries); |
[email protected] | 98b20ce | 2013-05-10 05:55:26 | [diff] [blame] | 423 | EXPECT_LT(0u, entries.size()); |
| 424 | |
| 425 | // Check that we logged a QUIC_SESSION_PACKET_RECEIVED. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 426 | int pos = ExpectLogContainsSomewhere( |
| 427 | entries, 0, NetLog::TYPE_QUIC_SESSION_PACKET_RECEIVED, |
| 428 | NetLog::PHASE_NONE); |
[email protected] | 98b20ce | 2013-05-10 05:55:26 | [diff] [blame] | 429 | EXPECT_LT(0, pos); |
| 430 | |
| 431 | // ... and also a TYPE_QUIC_SESSION_PACKET_HEADER_RECEIVED. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 432 | pos = ExpectLogContainsSomewhere( |
| 433 | entries, 0, NetLog::TYPE_QUIC_SESSION_PACKET_HEADER_RECEIVED, |
| 434 | NetLog::PHASE_NONE); |
[email protected] | 98b20ce | 2013-05-10 05:55:26 | [diff] [blame] | 435 | EXPECT_LT(0, pos); |
| 436 | |
| 437 | std::string packet_sequence_number; |
| 438 | ASSERT_TRUE(entries[pos].GetStringValue( |
| 439 | "packet_sequence_number", &packet_sequence_number)); |
| 440 | EXPECT_EQ("1", packet_sequence_number); |
| 441 | |
| 442 | // ... and also a QUIC_SESSION_STREAM_FRAME_RECEIVED. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 443 | pos = ExpectLogContainsSomewhere( |
| 444 | entries, 0, NetLog::TYPE_QUIC_SESSION_STREAM_FRAME_RECEIVED, |
| 445 | NetLog::PHASE_NONE); |
[email protected] | 98b20ce | 2013-05-10 05:55:26 | [diff] [blame] | 446 | EXPECT_LT(0, pos); |
| 447 | |
| 448 | int log_stream_id; |
| 449 | ASSERT_TRUE(entries[pos].GetIntegerValue("stream_id", &log_stream_id)); |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 450 | EXPECT_EQ(3, log_stream_id); |
[email protected] | 4dca587c | 2013-03-07 16:54:47 | [diff] [blame] | 451 | } |
| 452 | |
[email protected] | cf3e3cd6 | 2014-02-05 16:16:16 | [diff] [blame] | 453 | TEST_P(QuicNetworkTransactionTest, QuicProxy) { |
tbansal | ed0aecc | 2015-02-20 03:44:18 | [diff] [blame] | 454 | params_.enable_quic_for_proxies = true; |
[email protected] | cf3e3cd6 | 2014-02-05 16:16:16 | [diff] [blame] | 455 | proxy_service_.reset( |
| 456 | ProxyService::CreateFixedFromPacResult("QUIC myproxy:70")); |
| 457 | |
[email protected] | cf3e3cd6 | 2014-02-05 16:16:16 | [diff] [blame] | 458 | MockQuicData mock_quic_data; |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 459 | mock_quic_data.AddWrite( |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 460 | ConstructRequestHeadersPacket(1, kClientDataStreamId1, true, true, |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 461 | GetRequestHeaders("GET", "http", "/"))); |
| 462 | mock_quic_data.AddRead( |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 463 | ConstructResponseHeadersPacket(1, kClientDataStreamId1, false, false, |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 464 | GetResponseHeaders("200 OK"))); |
| 465 | mock_quic_data.AddRead( |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 466 | ConstructDataPacket(2, kClientDataStreamId1, false, true, 0, "hello!")); |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 467 | mock_quic_data.AddWrite(ConstructAckPacket(2, 1)); |
[email protected] | cf3e3cd6 | 2014-02-05 16:16:16 | [diff] [blame] | 468 | mock_quic_data.AddRead(SYNCHRONOUS, 0); // EOF |
| 469 | |
rch | a5399e0 | 2015-04-21 19:32:04 | [diff] [blame] | 470 | mock_quic_data.AddSocketDataToFactory(&socket_factory_); |
[email protected] | cf3e3cd6 | 2014-02-05 16:16:16 | [diff] [blame] | 471 | |
| 472 | // There is no need to set up an alternate protocol job, because |
| 473 | // no attempt will be made to speak to the proxy over TCP. |
| 474 | |
| 475 | CreateSession(); |
| 476 | |
bnc | 62a44f02 | 2015-04-02 15:59:41 | [diff] [blame] | 477 | SendRequestAndExpectQuicResponseFromProxyOnPort("hello!", 70); |
[email protected] | cf3e3cd6 | 2014-02-05 16:16:16 | [diff] [blame] | 478 | } |
| 479 | |
bnc | 313ba9c | 2015-06-11 15:42:31 | [diff] [blame^] | 480 | // Regression test for https://crbug.com/492458. Test that for an HTTP |
| 481 | // connection through a QUIC proxy, the certificate exhibited by the proxy is |
| 482 | // checked against the proxy hostname, not the origin hostname. |
| 483 | TEST_P(QuicNetworkTransactionTest, QuicProxyWithCert) { |
| 484 | const std::string origin_host = "news.example.com"; |
| 485 | const std::string proxy_host = "www.example.org"; |
| 486 | |
| 487 | params_.enable_quic_for_proxies = true; |
| 488 | proxy_service_.reset( |
| 489 | ProxyService::CreateFixedFromPacResult("QUIC " + proxy_host + ":70")); |
| 490 | |
| 491 | maker_.set_hostname(origin_host); |
| 492 | MockQuicData mock_quic_data; |
| 493 | mock_quic_data.AddWrite( |
| 494 | ConstructRequestHeadersPacket(1, kClientDataStreamId1, true, true, |
| 495 | GetRequestHeaders("GET", "http", "/"))); |
| 496 | mock_quic_data.AddRead(ConstructResponseHeadersPacket( |
| 497 | 1, kClientDataStreamId1, false, false, GetResponseHeaders("200 OK"))); |
| 498 | mock_quic_data.AddRead( |
| 499 | ConstructDataPacket(2, kClientDataStreamId1, false, true, 0, "hello!")); |
| 500 | mock_quic_data.AddWrite(ConstructAckPacket(2, 1)); |
| 501 | mock_quic_data.AddRead(SYNCHRONOUS, 0); |
| 502 | mock_quic_data.AddSocketDataToFactory(&socket_factory_); |
| 503 | |
| 504 | scoped_refptr<X509Certificate> cert( |
| 505 | ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem")); |
| 506 | ASSERT_TRUE(cert.get()); |
| 507 | // This certificate is valid for the proxy, but not for the origin. |
| 508 | bool common_name_fallback_used; |
| 509 | EXPECT_TRUE(cert->VerifyNameMatch(proxy_host, &common_name_fallback_used)); |
| 510 | EXPECT_FALSE(cert->VerifyNameMatch(origin_host, &common_name_fallback_used)); |
| 511 | ProofVerifyDetailsChromium verify_details; |
| 512 | verify_details.cert_verify_result.verified_cert = cert; |
| 513 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 514 | |
| 515 | request_.url = GURL("http://" + origin_host); |
| 516 | AddHangingNonAlternateProtocolSocketData(); |
| 517 | CreateSessionWithNextProtos(); |
| 518 | AddQuicAlternateProtocolMapping(MockCryptoClientStream::CONFIRM_HANDSHAKE); |
| 519 | SendRequestAndExpectQuicResponseFromProxyOnPort("hello!", 70); |
| 520 | } |
| 521 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 522 | TEST_P(QuicNetworkTransactionTest, ForceQuicWithErrorConnecting) { |
[email protected] | 49e8533 | 2013-06-04 04:18:03 | [diff] [blame] | 523 | params_.origin_to_force_quic_on = |
| 524 | HostPortPair::FromString("www.google.com:80"); |
[email protected] | cebe328 | 2013-05-22 23:49:30 | [diff] [blame] | 525 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 526 | MockQuicData mock_quic_data; |
| 527 | mock_quic_data.AddRead(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
| 528 | |
rch | a5399e0 | 2015-04-21 19:32:04 | [diff] [blame] | 529 | mock_quic_data.AddSocketDataToFactory(&socket_factory_); |
[email protected] | cebe328 | 2013-05-22 23:49:30 | [diff] [blame] | 530 | |
| 531 | CreateSession(); |
| 532 | |
| 533 | scoped_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 534 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get())); |
[email protected] | cebe328 | 2013-05-22 23:49:30 | [diff] [blame] | 535 | TestCompletionCallback callback; |
| 536 | int rv = trans->Start(&request_, callback.callback(), net_log_.bound()); |
| 537 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 538 | EXPECT_EQ(ERR_CONNECTION_CLOSED, callback.WaitForResult()); |
[email protected] | cebe328 | 2013-05-22 23:49:30 | [diff] [blame] | 539 | } |
| 540 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 541 | TEST_P(QuicNetworkTransactionTest, DoNotForceQuicForHttps) { |
[email protected] | 4dca587c | 2013-03-07 16:54:47 | [diff] [blame] | 542 | // Attempt to "force" quic on 443, which will not be honored. |
[email protected] | 49e8533 | 2013-06-04 04:18:03 | [diff] [blame] | 543 | params_.origin_to_force_quic_on = |
| 544 | HostPortPair::FromString("www.google.com:443"); |
[email protected] | 4dca587c | 2013-03-07 16:54:47 | [diff] [blame] | 545 | |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 546 | MockRead http_reads[] = { |
[email protected] | 4dca587c | 2013-03-07 16:54:47 | [diff] [blame] | 547 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 548 | MockRead("hello world"), |
| 549 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 550 | MockRead(ASYNC, OK) |
| 551 | }; |
| 552 | |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 553 | StaticSocketDataProvider data(http_reads, arraysize(http_reads), nullptr, 0); |
[email protected] | 4dca587c | 2013-03-07 16:54:47 | [diff] [blame] | 554 | socket_factory_.AddSocketDataProvider(&data); |
| 555 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 556 | socket_factory_.AddSSLSocketDataProvider(&ssl); |
| 557 | |
[email protected] | 4dca587c | 2013-03-07 16:54:47 | [diff] [blame] | 558 | CreateSession(); |
[email protected] | 4dca587c | 2013-03-07 16:54:47 | [diff] [blame] | 559 | |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 560 | SendRequestAndExpectHttpResponse("hello world"); |
[email protected] | 4dca587c | 2013-03-07 16:54:47 | [diff] [blame] | 561 | } |
| 562 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 563 | TEST_P(QuicNetworkTransactionTest, UseAlternateProtocolForQuic) { |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 564 | MockRead http_reads[] = { |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 565 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 566 | MockRead(kQuicAlternateProtocolHttpHeader), |
| 567 | MockRead("hello world"), |
| 568 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 569 | MockRead(ASYNC, OK) |
| 570 | }; |
| 571 | |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 572 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 573 | nullptr, 0); |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 574 | socket_factory_.AddSocketDataProvider(&http_data); |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 575 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 576 | MockQuicData mock_quic_data; |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 577 | mock_quic_data.AddWrite( |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 578 | ConstructRequestHeadersPacket(1, kClientDataStreamId1, true, true, |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 579 | GetRequestHeaders("GET", "http", "/"))); |
| 580 | mock_quic_data.AddRead( |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 581 | ConstructResponseHeadersPacket(1, kClientDataStreamId1, false, false, |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 582 | GetResponseHeaders("200 OK"))); |
| 583 | mock_quic_data.AddRead( |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 584 | ConstructDataPacket(2, kClientDataStreamId1, false, true, 0, "hello!")); |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 585 | mock_quic_data.AddWrite(ConstructAckPacket(2, 1)); |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 586 | mock_quic_data.AddRead(SYNCHRONOUS, 0); // EOF |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 587 | |
rch | a5399e0 | 2015-04-21 19:32:04 | [diff] [blame] | 588 | mock_quic_data.AddSocketDataToFactory(&socket_factory_); |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 589 | |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 590 | // The non-alternate protocol job needs to hang in order to guarantee that |
| 591 | // the alternate-protocol job will "win". |
| 592 | AddHangingNonAlternateProtocolSocketData(); |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 593 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 594 | CreateSessionWithNextProtos(); |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 595 | |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 596 | SendRequestAndExpectHttpResponse("hello world"); |
| 597 | SendRequestAndExpectQuicResponse("hello!"); |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 598 | } |
| 599 | |
bnc | 62a44f02 | 2015-04-02 15:59:41 | [diff] [blame] | 600 | TEST_P(QuicNetworkTransactionTest, AlternateProtocolDifferentPort) { |
| 601 | MockRead http_reads[] = { |
| 602 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 603 | MockRead(kQuicAlternateProtocolDifferentPortHttpHeader), |
| 604 | MockRead("hello world"), |
| 605 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 606 | MockRead(ASYNC, OK)}; |
| 607 | |
| 608 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), nullptr, |
| 609 | 0); |
| 610 | socket_factory_.AddSocketDataProvider(&http_data); |
| 611 | |
| 612 | MockQuicData mock_quic_data; |
| 613 | mock_quic_data.AddWrite( |
| 614 | ConstructRequestHeadersPacket(1, kClientDataStreamId1, true, true, |
| 615 | GetRequestHeaders("GET", "http", "/"))); |
| 616 | mock_quic_data.AddRead(ConstructResponseHeadersPacket( |
| 617 | 1, kClientDataStreamId1, false, false, GetResponseHeaders("200 OK"))); |
| 618 | mock_quic_data.AddRead( |
| 619 | ConstructDataPacket(2, kClientDataStreamId1, false, true, 0, "hello!")); |
| 620 | mock_quic_data.AddWrite(ConstructAckPacket(2, 1)); |
| 621 | mock_quic_data.AddRead(SYNCHRONOUS, 0); // EOF |
| 622 | |
rch | a5399e0 | 2015-04-21 19:32:04 | [diff] [blame] | 623 | mock_quic_data.AddSocketDataToFactory(&socket_factory_); |
bnc | 62a44f02 | 2015-04-02 15:59:41 | [diff] [blame] | 624 | |
| 625 | // The non-alternate protocol job needs to hang in order to guarantee that |
| 626 | // the alternate-protocol job will "win". |
| 627 | AddHangingNonAlternateProtocolSocketData(); |
| 628 | |
| 629 | CreateSessionWithNextProtos(); |
| 630 | |
| 631 | SendRequestAndExpectHttpResponse("hello world"); |
| 632 | SendRequestAndExpectQuicResponseOnPort("hello!", 137); |
| 633 | } |
| 634 | |
bnc | ae8db840 | 2015-03-26 20:13:50 | [diff] [blame] | 635 | TEST_P(QuicNetworkTransactionTest, ConfirmAlternativeService) { |
| 636 | MockRead http_reads[] = { |
| 637 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 638 | MockRead(kQuicAlternateProtocolHttpHeader), |
| 639 | MockRead("hello world"), |
| 640 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 641 | MockRead(ASYNC, OK)}; |
| 642 | |
| 643 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), nullptr, |
| 644 | 0); |
| 645 | socket_factory_.AddSocketDataProvider(&http_data); |
| 646 | |
| 647 | MockQuicData mock_quic_data; |
| 648 | mock_quic_data.AddWrite( |
| 649 | ConstructRequestHeadersPacket(1, kClientDataStreamId1, true, true, |
| 650 | GetRequestHeaders("GET", "http", "/"))); |
| 651 | mock_quic_data.AddRead(ConstructResponseHeadersPacket( |
| 652 | 1, kClientDataStreamId1, false, false, GetResponseHeaders("200 OK"))); |
| 653 | mock_quic_data.AddRead( |
| 654 | ConstructDataPacket(2, kClientDataStreamId1, false, true, 0, "hello!")); |
| 655 | mock_quic_data.AddWrite(ConstructAckPacket(2, 1)); |
| 656 | mock_quic_data.AddRead(SYNCHRONOUS, 0); // EOF |
| 657 | |
rch | a5399e0 | 2015-04-21 19:32:04 | [diff] [blame] | 658 | mock_quic_data.AddSocketDataToFactory(&socket_factory_); |
bnc | ae8db840 | 2015-03-26 20:13:50 | [diff] [blame] | 659 | |
| 660 | // The non-alternate protocol job needs to hang in order to guarantee that |
| 661 | // the alternate-protocol job will "win". |
| 662 | AddHangingNonAlternateProtocolSocketData(); |
| 663 | |
| 664 | CreateSessionWithNextProtos(); |
| 665 | |
| 666 | AlternativeService alternative_service(QUIC, |
| 667 | HostPortPair::FromURL(request_.url)); |
bnc | 6be245c1 | 2015-05-15 11:24:07 | [diff] [blame] | 668 | http_server_properties_.MarkAlternativeServiceRecentlyBroken( |
bnc | ae8db840 | 2015-03-26 20:13:50 | [diff] [blame] | 669 | alternative_service); |
bnc | 6be245c1 | 2015-05-15 11:24:07 | [diff] [blame] | 670 | EXPECT_TRUE(http_server_properties_.WasAlternativeServiceRecentlyBroken( |
| 671 | alternative_service)); |
bnc | ae8db840 | 2015-03-26 20:13:50 | [diff] [blame] | 672 | |
| 673 | SendRequestAndExpectHttpResponse("hello world"); |
| 674 | SendRequestAndExpectQuicResponse("hello!"); |
| 675 | |
bnc | 6be245c1 | 2015-05-15 11:24:07 | [diff] [blame] | 676 | EXPECT_FALSE(http_server_properties_.WasAlternativeServiceRecentlyBroken( |
| 677 | alternative_service)); |
bnc | ae8db840 | 2015-03-26 20:13:50 | [diff] [blame] | 678 | } |
| 679 | |
[email protected] | 287d941 | 2014-07-08 23:01:00 | [diff] [blame] | 680 | TEST_P(QuicNetworkTransactionTest, UseAlternateProtocolProbabilityForQuic) { |
| 681 | MockRead http_reads[] = { |
| 682 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 683 | MockRead(kQuicAlternateProtocol50pctHttpHeader), |
| 684 | MockRead("hello world"), |
| 685 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 686 | MockRead(ASYNC, OK) |
| 687 | }; |
| 688 | |
| 689 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 690 | nullptr, 0); |
[email protected] | 287d941 | 2014-07-08 23:01:00 | [diff] [blame] | 691 | socket_factory_.AddSocketDataProvider(&http_data); |
| 692 | |
| 693 | MockQuicData mock_quic_data; |
| 694 | mock_quic_data.AddWrite( |
| 695 | ConstructRequestHeadersPacket(1, kClientDataStreamId1, true, true, |
| 696 | GetRequestHeaders("GET", "http", "/"))); |
| 697 | mock_quic_data.AddRead( |
| 698 | ConstructResponseHeadersPacket(1, kClientDataStreamId1, false, false, |
| 699 | GetResponseHeaders("200 OK"))); |
| 700 | mock_quic_data.AddRead( |
| 701 | ConstructDataPacket(2, kClientDataStreamId1, false, true, 0, "hello!")); |
| 702 | mock_quic_data.AddWrite(ConstructAckPacket(2, 1)); |
| 703 | mock_quic_data.AddRead(SYNCHRONOUS, 0); // EOF |
| 704 | |
rch | a5399e0 | 2015-04-21 19:32:04 | [diff] [blame] | 705 | mock_quic_data.AddSocketDataToFactory(&socket_factory_); |
[email protected] | 287d941 | 2014-07-08 23:01:00 | [diff] [blame] | 706 | |
| 707 | // The non-alternate protocol job needs to hang in order to guarantee that |
| 708 | // the alternate-protocol job will "win". |
| 709 | AddHangingNonAlternateProtocolSocketData(); |
| 710 | |
bnc | 62891a5 | 2015-04-27 14:14:12 | [diff] [blame] | 711 | params_.alternative_service_probability_threshold = .25; |
[email protected] | 287d941 | 2014-07-08 23:01:00 | [diff] [blame] | 712 | CreateSessionWithNextProtos(); |
| 713 | |
| 714 | SendRequestAndExpectHttpResponse("hello world"); |
| 715 | SendRequestAndExpectQuicResponse("hello!"); |
| 716 | } |
| 717 | |
| 718 | TEST_P(QuicNetworkTransactionTest, DontUseAlternateProtocolProbabilityForQuic) { |
| 719 | MockRead http_reads[] = { |
| 720 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 721 | MockRead(kQuicAlternateProtocol50pctHttpHeader), |
| 722 | MockRead("hello world"), |
| 723 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 724 | MockRead(ASYNC, OK) |
| 725 | }; |
| 726 | |
| 727 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 728 | nullptr, 0); |
[email protected] | 287d941 | 2014-07-08 23:01:00 | [diff] [blame] | 729 | socket_factory_.AddSocketDataProvider(&http_data); |
| 730 | socket_factory_.AddSocketDataProvider(&http_data); |
| 731 | |
bnc | 62891a5 | 2015-04-27 14:14:12 | [diff] [blame] | 732 | params_.alternative_service_probability_threshold = .75; |
[email protected] | 287d941 | 2014-07-08 23:01:00 | [diff] [blame] | 733 | CreateSessionWithNextProtos(); |
| 734 | |
| 735 | SendRequestAndExpectHttpResponse("hello world"); |
| 736 | SendRequestAndExpectHttpResponse("hello world"); |
| 737 | } |
| 738 | |
rch | 405ed7a | 2015-05-12 01:10:16 | [diff] [blame] | 739 | TEST_P(QuicNetworkTransactionTest, DontUseAlternateProtocolForInsecureQuic) { |
| 740 | MockRead http_reads[] = {MockRead("HTTP/1.1 200 OK\r\n"), |
| 741 | MockRead("Content-length: 11\r\n"), |
| 742 | MockRead("Alternate-Protocol: 443:quic\r\n\r\n"), |
| 743 | MockRead("hello world"), |
| 744 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 745 | MockRead("Content-length: 11\r\n"), |
| 746 | MockRead("Alternate-Protocol: 443:quic\r\n\r\n"), |
| 747 | MockRead("hello world"), |
| 748 | MockRead(ASYNC, OK)}; |
| 749 | |
| 750 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), nullptr, |
| 751 | 0); |
| 752 | socket_factory_.AddSocketDataProvider(&http_data); |
| 753 | socket_factory_.AddSocketDataProvider(&http_data); |
| 754 | |
| 755 | params_.disable_insecure_quic = true; |
| 756 | CreateSessionWithNextProtos(); |
| 757 | |
| 758 | SendRequestAndExpectHttpResponse("hello world"); |
| 759 | SendRequestAndExpectHttpResponse("hello world"); |
| 760 | } |
| 761 | |
[email protected] | 287d941 | 2014-07-08 23:01:00 | [diff] [blame] | 762 | TEST_P(QuicNetworkTransactionTest, |
| 763 | DontUseAlternateProtocolWithBadProbabilityForQuic) { |
| 764 | MockRead http_reads[] = { |
| 765 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 766 | MockRead("Alternate-Protocol: 443:quic,p=2\r\n\r\n"), |
| 767 | MockRead("hello world"), |
| 768 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 769 | MockRead(ASYNC, OK) |
| 770 | }; |
| 771 | |
| 772 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 773 | nullptr, 0); |
[email protected] | 287d941 | 2014-07-08 23:01:00 | [diff] [blame] | 774 | socket_factory_.AddSocketDataProvider(&http_data); |
| 775 | socket_factory_.AddSocketDataProvider(&http_data); |
| 776 | |
bnc | 62891a5 | 2015-04-27 14:14:12 | [diff] [blame] | 777 | params_.alternative_service_probability_threshold = .75; |
[email protected] | 287d941 | 2014-07-08 23:01:00 | [diff] [blame] | 778 | CreateSessionWithNextProtos(); |
| 779 | |
| 780 | SendRequestAndExpectHttpResponse("hello world"); |
| 781 | SendRequestAndExpectHttpResponse("hello world"); |
| 782 | } |
| 783 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 784 | TEST_P(QuicNetworkTransactionTest, UseAlternateProtocolForQuicForHttps) { |
[email protected] | 6d1b4ed | 2013-07-10 03:57:54 | [diff] [blame] | 785 | params_.origin_to_force_quic_on = |
| 786 | HostPortPair::FromString("www.google.com:443"); |
[email protected] | 6d1b4ed | 2013-07-10 03:57:54 | [diff] [blame] | 787 | |
| 788 | MockRead http_reads[] = { |
| 789 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 790 | MockRead(kQuicAlternateProtocolHttpsHeader), |
| 791 | MockRead("hello world"), |
| 792 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 793 | MockRead(ASYNC, OK) |
| 794 | }; |
| 795 | |
| 796 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 797 | nullptr, 0); |
[email protected] | 6d1b4ed | 2013-07-10 03:57:54 | [diff] [blame] | 798 | socket_factory_.AddSocketDataProvider(&http_data); |
| 799 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 800 | MockQuicData mock_quic_data; |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 801 | mock_quic_data.AddWrite( |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 802 | ConstructRequestHeadersPacket(1, kClientDataStreamId1, true, true, |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 803 | GetRequestHeaders("GET", "http", "/"))); |
| 804 | mock_quic_data.AddRead( |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 805 | ConstructResponseHeadersPacket(1, kClientDataStreamId1, false, false, |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 806 | GetResponseHeaders("200 OK"))); |
| 807 | mock_quic_data.AddRead( |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 808 | ConstructDataPacket(2, kClientDataStreamId1, false, true, 0, "hello!")); |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 809 | mock_quic_data.AddWrite(ConstructAckPacket(2, 1)); |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 810 | mock_quic_data.AddRead(SYNCHRONOUS, 0); // EOF |
[email protected] | 6d1b4ed | 2013-07-10 03:57:54 | [diff] [blame] | 811 | |
rch | a5399e0 | 2015-04-21 19:32:04 | [diff] [blame] | 812 | mock_quic_data.AddSocketDataToFactory(&socket_factory_); |
[email protected] | 6d1b4ed | 2013-07-10 03:57:54 | [diff] [blame] | 813 | |
| 814 | // The non-alternate protocol job needs to hang in order to guarantee that |
| 815 | // the alternate-protocol job will "win". |
| 816 | AddHangingNonAlternateProtocolSocketData(); |
| 817 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 818 | CreateSessionWithNextProtos(); |
[email protected] | 6d1b4ed | 2013-07-10 03:57:54 | [diff] [blame] | 819 | |
| 820 | // TODO(rtenneti): Test QUIC over HTTPS, GetSSLInfo(). |
| 821 | SendRequestAndExpectHttpResponse("hello world"); |
| 822 | } |
| 823 | |
bnc | cb7ff3c | 2015-05-21 20:51:55 | [diff] [blame] | 824 | class QuicAltSvcCertificateVerificationTest |
| 825 | : public QuicNetworkTransactionTest { |
| 826 | public: |
| 827 | void Run(bool valid) { |
| 828 | HostPortPair origin(valid ? "mail.example.org" : "invalid.example.org", |
| 829 | 443); |
| 830 | HostPortPair alternative("www.example.org", 443); |
| 831 | std::string url("https://"); |
| 832 | url.append(origin.host()); |
| 833 | url.append(":443"); |
| 834 | request_.url = GURL(url); |
| 835 | |
| 836 | maker_.set_hostname(origin.host()); |
| 837 | MockQuicData mock_quic_data; |
| 838 | mock_quic_data.AddWrite( |
| 839 | ConstructRequestHeadersPacket(1, kClientDataStreamId1, true, true, |
| 840 | GetRequestHeaders("GET", "https", "/"))); |
| 841 | mock_quic_data.AddRead(ConstructResponseHeadersPacket( |
| 842 | 1, kClientDataStreamId1, false, false, GetResponseHeaders("200 OK"))); |
| 843 | mock_quic_data.AddRead( |
| 844 | ConstructDataPacket(2, kClientDataStreamId1, false, true, 0, "hello!")); |
| 845 | mock_quic_data.AddWrite(ConstructAckPacket(2, 1)); |
| 846 | mock_quic_data.AddRead(SYNCHRONOUS, 0); |
| 847 | mock_quic_data.AddSocketDataToFactory(&socket_factory_); |
| 848 | |
| 849 | scoped_refptr<X509Certificate> cert( |
| 850 | ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem")); |
| 851 | ASSERT_TRUE(cert.get()); |
| 852 | bool common_name_fallback_used; |
| 853 | EXPECT_EQ(valid, |
| 854 | cert->VerifyNameMatch(origin.host(), &common_name_fallback_used)); |
| 855 | EXPECT_TRUE( |
| 856 | cert->VerifyNameMatch(alternative.host(), &common_name_fallback_used)); |
| 857 | ProofVerifyDetailsChromium verify_details; |
| 858 | verify_details.cert_verify_result.verified_cert = cert; |
| 859 | verify_details.cert_verify_result.is_issued_by_known_root = true; |
| 860 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 861 | crypto_client_stream_factory_.set_handshake_mode( |
| 862 | MockCryptoClientStream::CONFIRM_HANDSHAKE); |
| 863 | |
| 864 | // Connection to |origin| fails, so that success of |request| depends on |
| 865 | // connection to |alternate| only. |
| 866 | MockConnect refused_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 867 | StaticSocketDataProvider refused_data; |
| 868 | refused_data.set_connect_data(refused_connect); |
| 869 | socket_factory_.AddSocketDataProvider(&refused_data); |
| 870 | |
| 871 | CreateSessionWithNextProtos(); |
| 872 | AlternativeService alternative_service(QUIC, alternative); |
| 873 | session_->http_server_properties()->SetAlternativeService( |
| 874 | origin, alternative_service, 1.0); |
| 875 | scoped_ptr<HttpNetworkTransaction> trans( |
| 876 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get())); |
| 877 | TestCompletionCallback callback; |
| 878 | int rv = trans->Start(&request_, callback.callback(), net_log_.bound()); |
| 879 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 880 | rv = callback.WaitForResult(); |
| 881 | if (valid) { |
| 882 | EXPECT_EQ(OK, rv); |
| 883 | CheckWasQuicResponse(trans); |
| 884 | CheckResponsePort(trans, 443); |
| 885 | CheckResponseData(trans, "hello!"); |
| 886 | } else { |
| 887 | EXPECT_EQ(ERR_CONNECTION_REFUSED, rv); |
| 888 | } |
| 889 | } |
| 890 | }; |
| 891 | |
| 892 | INSTANTIATE_TEST_CASE_P(Version, |
| 893 | QuicAltSvcCertificateVerificationTest, |
| 894 | ::testing::ValuesIn(QuicSupportedVersions())); |
| 895 | |
| 896 | TEST_P(QuicAltSvcCertificateVerificationTest, |
| 897 | RequestSucceedsWithValidCertificate) { |
| 898 | Run(true); |
| 899 | } |
| 900 | |
| 901 | TEST_P(QuicAltSvcCertificateVerificationTest, |
| 902 | RequestFailsWithInvalidCertificate) { |
| 903 | Run(false); |
| 904 | } |
| 905 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 906 | TEST_P(QuicNetworkTransactionTest, HungAlternateProtocol) { |
[email protected] | dda75ab | 2013-06-22 22:43:30 | [diff] [blame] | 907 | crypto_client_stream_factory_.set_handshake_mode( |
| 908 | MockCryptoClientStream::COLD_START); |
| 909 | |
| 910 | MockWrite http_writes[] = { |
| 911 | MockWrite(SYNCHRONOUS, 0, "GET / HTTP/1.1\r\n"), |
| 912 | MockWrite(SYNCHRONOUS, 1, "Host: www.google.com\r\n"), |
| 913 | MockWrite(SYNCHRONOUS, 2, "Connection: keep-alive\r\n\r\n") |
| 914 | }; |
| 915 | |
| 916 | MockRead http_reads[] = { |
| 917 | MockRead(SYNCHRONOUS, 3, "HTTP/1.1 200 OK\r\n"), |
| 918 | MockRead(SYNCHRONOUS, 4, kQuicAlternateProtocolHttpHeader), |
| 919 | MockRead(SYNCHRONOUS, 5, "hello world"), |
| 920 | MockRead(SYNCHRONOUS, OK, 6) |
| 921 | }; |
| 922 | |
| 923 | DeterministicMockClientSocketFactory socket_factory; |
| 924 | |
| 925 | DeterministicSocketData http_data(http_reads, arraysize(http_reads), |
| 926 | http_writes, arraysize(http_writes)); |
| 927 | socket_factory.AddSocketDataProvider(&http_data); |
| 928 | |
| 929 | // The QUIC transaction will not be allowed to complete. |
| 930 | MockWrite quic_writes[] = { |
| 931 | MockWrite(ASYNC, ERR_IO_PENDING, 0) |
| 932 | }; |
| 933 | MockRead quic_reads[] = { |
| 934 | MockRead(ASYNC, ERR_IO_PENDING, 1), |
| 935 | }; |
| 936 | DeterministicSocketData quic_data(quic_reads, arraysize(quic_reads), |
| 937 | quic_writes, arraysize(quic_writes)); |
| 938 | socket_factory.AddSocketDataProvider(&quic_data); |
| 939 | |
| 940 | // The HTTP transaction will complete. |
| 941 | DeterministicSocketData http_data2(http_reads, arraysize(http_reads), |
| 942 | http_writes, arraysize(http_writes)); |
| 943 | socket_factory.AddSocketDataProvider(&http_data2); |
| 944 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 945 | CreateSessionWithFactory(&socket_factory, true); |
[email protected] | dda75ab | 2013-06-22 22:43:30 | [diff] [blame] | 946 | |
| 947 | // Run the first request. |
| 948 | http_data.StopAfter(arraysize(http_reads) + arraysize(http_writes)); |
| 949 | SendRequestAndExpectHttpResponse("hello world"); |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 950 | ASSERT_TRUE(http_data.AllReadDataConsumed()); |
| 951 | ASSERT_TRUE(http_data.AllWriteDataConsumed()); |
[email protected] | dda75ab | 2013-06-22 22:43:30 | [diff] [blame] | 952 | |
| 953 | // Now run the second request in which the QUIC socket hangs, |
| 954 | // and verify the the transaction continues over HTTP. |
| 955 | http_data2.StopAfter(arraysize(http_reads) + arraysize(http_writes)); |
| 956 | SendRequestAndExpectHttpResponse("hello world"); |
| 957 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 958 | ASSERT_TRUE(http_data2.AllReadDataConsumed()); |
| 959 | ASSERT_TRUE(http_data2.AllWriteDataConsumed()); |
| 960 | ASSERT_TRUE(!quic_data.AllReadDataConsumed()); |
| 961 | ASSERT_TRUE(!quic_data.AllWriteDataConsumed()); |
[email protected] | dda75ab | 2013-06-22 22:43:30 | [diff] [blame] | 962 | } |
| 963 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 964 | TEST_P(QuicNetworkTransactionTest, ZeroRTTWithHttpRace) { |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 965 | MockQuicData mock_quic_data; |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 966 | mock_quic_data.AddWrite( |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 967 | ConstructRequestHeadersPacket(1, kClientDataStreamId1, true, true, |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 968 | GetRequestHeaders("GET", "http", "/"))); |
| 969 | mock_quic_data.AddRead( |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 970 | ConstructResponseHeadersPacket(1, kClientDataStreamId1, false, false, |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 971 | GetResponseHeaders("200 OK"))); |
| 972 | mock_quic_data.AddRead( |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 973 | ConstructDataPacket(2, kClientDataStreamId1, false, true, 0, "hello!")); |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 974 | mock_quic_data.AddWrite(ConstructAckPacket(2, 1)); |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 975 | mock_quic_data.AddRead(SYNCHRONOUS, 0); // EOF |
[email protected] | 8ba8121 | 2013-05-03 13:11:48 | [diff] [blame] | 976 | |
rch | a5399e0 | 2015-04-21 19:32:04 | [diff] [blame] | 977 | mock_quic_data.AddSocketDataToFactory(&socket_factory_); |
[email protected] | 8ba8121 | 2013-05-03 13:11:48 | [diff] [blame] | 978 | |
[email protected] | 3a120a6b | 2013-06-25 01:08:27 | [diff] [blame] | 979 | // The non-alternate protocol job needs to hang in order to guarantee that |
| 980 | // the alternate-protocol job will "win". |
[email protected] | dda75ab | 2013-06-22 22:43:30 | [diff] [blame] | 981 | AddHangingNonAlternateProtocolSocketData(); |
| 982 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 983 | CreateSessionWithNextProtos(); |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 984 | AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT); |
| 985 | SendRequestAndExpectQuicResponse("hello!"); |
[email protected] | 8ba8121 | 2013-05-03 13:11:48 | [diff] [blame] | 986 | } |
| 987 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 988 | TEST_P(QuicNetworkTransactionTest, ZeroRTTWithNoHttpRace) { |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 989 | MockQuicData mock_quic_data; |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 990 | mock_quic_data.AddWrite( |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 991 | ConstructRequestHeadersPacket(1, kClientDataStreamId1, true, true, |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 992 | GetRequestHeaders("GET", "http", "/"))); |
| 993 | mock_quic_data.AddRead( |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 994 | ConstructResponseHeadersPacket(1, kClientDataStreamId1, false, false, |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 995 | GetResponseHeaders("200 OK"))); |
| 996 | mock_quic_data.AddRead( |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 997 | ConstructDataPacket(2, kClientDataStreamId1, false, true, 0, "hello!")); |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 998 | mock_quic_data.AddWrite(ConstructAckPacket(2, 1)); |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 999 | mock_quic_data.AddRead(SYNCHRONOUS, 0); // EOF |
rch | a5399e0 | 2015-04-21 19:32:04 | [diff] [blame] | 1000 | mock_quic_data.AddSocketDataToFactory(&socket_factory_); |
[email protected] | 3a120a6b | 2013-06-25 01:08:27 | [diff] [blame] | 1001 | |
| 1002 | // In order for a new QUIC session to be established via alternate-protocol |
| 1003 | // without racing an HTTP connection, we need the host resolution to happen |
| 1004 | // synchronously. |
| 1005 | host_resolver_.set_synchronous_mode(true); |
| 1006 | host_resolver_.rules()->AddIPLiteralRule("www.google.com", "192.168.0.1", ""); |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 1007 | HostResolver::RequestInfo info(HostPortPair("www.google.com", 80)); |
[email protected] | 3a120a6b | 2013-06-25 01:08:27 | [diff] [blame] | 1008 | AddressList address; |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 1009 | host_resolver_.Resolve(info, |
| 1010 | DEFAULT_PRIORITY, |
| 1011 | &address, |
| 1012 | CompletionCallback(), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 1013 | nullptr, |
[email protected] | 3a120a6b | 2013-06-25 01:08:27 | [diff] [blame] | 1014 | net_log_.bound()); |
| 1015 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 1016 | CreateSessionWithNextProtos(); |
[email protected] | 3a120a6b | 2013-06-25 01:08:27 | [diff] [blame] | 1017 | AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT); |
| 1018 | SendRequestAndExpectQuicResponse("hello!"); |
| 1019 | } |
| 1020 | |
[email protected] | 0fc924b | 2014-03-31 04:34:15 | [diff] [blame] | 1021 | TEST_P(QuicNetworkTransactionTest, ZeroRTTWithProxy) { |
| 1022 | proxy_service_.reset( |
| 1023 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
[email protected] | 0fc924b | 2014-03-31 04:34:15 | [diff] [blame] | 1024 | |
| 1025 | // Since we are using a proxy, the QUIC job will not succeed. |
| 1026 | MockWrite http_writes[] = { |
| 1027 | MockWrite(SYNCHRONOUS, 0, "GET http://www.google.com/ HTTP/1.1\r\n"), |
| 1028 | MockWrite(SYNCHRONOUS, 1, "Host: www.google.com\r\n"), |
| 1029 | MockWrite(SYNCHRONOUS, 2, "Proxy-Connection: keep-alive\r\n\r\n") |
| 1030 | }; |
| 1031 | |
| 1032 | MockRead http_reads[] = { |
| 1033 | MockRead(SYNCHRONOUS, 3, "HTTP/1.1 200 OK\r\n"), |
| 1034 | MockRead(SYNCHRONOUS, 4, kQuicAlternateProtocolHttpHeader), |
| 1035 | MockRead(SYNCHRONOUS, 5, "hello world"), |
| 1036 | MockRead(SYNCHRONOUS, OK, 6) |
| 1037 | }; |
| 1038 | |
| 1039 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 1040 | http_writes, arraysize(http_writes)); |
| 1041 | socket_factory_.AddSocketDataProvider(&http_data); |
| 1042 | |
| 1043 | // In order for a new QUIC session to be established via alternate-protocol |
| 1044 | // without racing an HTTP connection, we need the host resolution to happen |
| 1045 | // synchronously. |
| 1046 | host_resolver_.set_synchronous_mode(true); |
| 1047 | host_resolver_.rules()->AddIPLiteralRule("www.google.com", "192.168.0.1", ""); |
| 1048 | HostResolver::RequestInfo info(HostPortPair("www.google.com", 80)); |
| 1049 | AddressList address; |
| 1050 | host_resolver_.Resolve(info, |
| 1051 | DEFAULT_PRIORITY, |
| 1052 | &address, |
| 1053 | CompletionCallback(), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 1054 | nullptr, |
[email protected] | 0fc924b | 2014-03-31 04:34:15 | [diff] [blame] | 1055 | net_log_.bound()); |
| 1056 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 1057 | CreateSessionWithNextProtos(); |
[email protected] | 0fc924b | 2014-03-31 04:34:15 | [diff] [blame] | 1058 | AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT); |
| 1059 | SendRequestAndExpectHttpResponse("hello world"); |
| 1060 | } |
| 1061 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1062 | TEST_P(QuicNetworkTransactionTest, ZeroRTTWithConfirmationRequired) { |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1063 | MockQuicData mock_quic_data; |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 1064 | mock_quic_data.AddWrite( |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 1065 | ConstructRequestHeadersPacket(1, kClientDataStreamId1, true, true, |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 1066 | GetRequestHeaders("GET", "http", "/"))); |
| 1067 | mock_quic_data.AddRead( |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 1068 | ConstructResponseHeadersPacket(1, kClientDataStreamId1, false, false, |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 1069 | GetResponseHeaders("200 OK"))); |
| 1070 | mock_quic_data.AddRead( |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 1071 | ConstructDataPacket(2, kClientDataStreamId1, false, true, 0, "hello!")); |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 1072 | mock_quic_data.AddWrite(ConstructAckPacket(2, 1)); |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1073 | mock_quic_data.AddRead(SYNCHRONOUS, 0); // EOF |
rch | a5399e0 | 2015-04-21 19:32:04 | [diff] [blame] | 1074 | mock_quic_data.AddSocketDataToFactory(&socket_factory_); |
[email protected] | 11c0587 | 2013-08-20 02:04:12 | [diff] [blame] | 1075 | |
| 1076 | // The non-alternate protocol job needs to hang in order to guarantee that |
| 1077 | // the alternate-protocol job will "win". |
| 1078 | AddHangingNonAlternateProtocolSocketData(); |
| 1079 | |
| 1080 | // In order for a new QUIC session to be established via alternate-protocol |
| 1081 | // without racing an HTTP connection, we need the host resolution to happen |
| 1082 | // synchronously. Of course, even though QUIC *could* perform a 0-RTT |
| 1083 | // connection to the the server, in this test we require confirmation |
| 1084 | // before encrypting so the HTTP job will still start. |
| 1085 | host_resolver_.set_synchronous_mode(true); |
| 1086 | host_resolver_.rules()->AddIPLiteralRule("www.google.com", "192.168.0.1", ""); |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 1087 | HostResolver::RequestInfo info(HostPortPair("www.google.com", 80)); |
[email protected] | 11c0587 | 2013-08-20 02:04:12 | [diff] [blame] | 1088 | AddressList address; |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 1089 | host_resolver_.Resolve(info, DEFAULT_PRIORITY, &address, |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 1090 | CompletionCallback(), nullptr, net_log_.bound()); |
[email protected] | 11c0587 | 2013-08-20 02:04:12 | [diff] [blame] | 1091 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 1092 | CreateSessionWithNextProtos(); |
[email protected] | 11c0587 | 2013-08-20 02:04:12 | [diff] [blame] | 1093 | session_->quic_stream_factory()->set_require_confirmation(true); |
| 1094 | AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT); |
| 1095 | |
| 1096 | scoped_ptr<HttpNetworkTransaction> trans( |
| 1097 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get())); |
| 1098 | TestCompletionCallback callback; |
| 1099 | int rv = trans->Start(&request_, callback.callback(), net_log_.bound()); |
| 1100 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1101 | |
| 1102 | crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
| 1103 | QuicSession::HANDSHAKE_CONFIRMED); |
| 1104 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 1105 | } |
| 1106 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1107 | TEST_P(QuicNetworkTransactionTest, BrokenAlternateProtocol) { |
[email protected] | 3316d42 | 2013-05-03 21:45:30 | [diff] [blame] | 1108 | // Alternate-protocol job |
| 1109 | scoped_ptr<QuicEncryptedPacket> close(ConstructConnectionClosePacket(1)); |
| 1110 | MockRead quic_reads[] = { |
| 1111 | MockRead(ASYNC, close->data(), close->length()), |
| 1112 | MockRead(ASYNC, OK), // EOF |
| 1113 | }; |
| 1114 | StaticSocketDataProvider quic_data(quic_reads, arraysize(quic_reads), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 1115 | nullptr, 0); |
[email protected] | 3316d42 | 2013-05-03 21:45:30 | [diff] [blame] | 1116 | socket_factory_.AddSocketDataProvider(&quic_data); |
| 1117 | |
| 1118 | // Main job which will succeed even though the alternate job fails. |
| 1119 | MockRead http_reads[] = { |
| 1120 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 1121 | MockRead("hello from http"), |
| 1122 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 1123 | MockRead(ASYNC, OK) |
| 1124 | }; |
| 1125 | |
| 1126 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 1127 | nullptr, 0); |
[email protected] | 3316d42 | 2013-05-03 21:45:30 | [diff] [blame] | 1128 | socket_factory_.AddSocketDataProvider(&http_data); |
| 1129 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 1130 | CreateSessionWithNextProtos(); |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 1131 | AddQuicAlternateProtocolMapping(MockCryptoClientStream::COLD_START); |
| 1132 | SendRequestAndExpectHttpResponse("hello from http"); |
| 1133 | ExpectBrokenAlternateProtocolMapping(); |
[email protected] | 3316d42 | 2013-05-03 21:45:30 | [diff] [blame] | 1134 | } |
| 1135 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1136 | TEST_P(QuicNetworkTransactionTest, BrokenAlternateProtocolReadError) { |
[email protected] | d03a66d | 2013-05-06 12:55:59 | [diff] [blame] | 1137 | // Alternate-protocol job |
| 1138 | MockRead quic_reads[] = { |
| 1139 | MockRead(ASYNC, ERR_SOCKET_NOT_CONNECTED), |
| 1140 | }; |
| 1141 | StaticSocketDataProvider quic_data(quic_reads, arraysize(quic_reads), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 1142 | nullptr, 0); |
[email protected] | d03a66d | 2013-05-06 12:55:59 | [diff] [blame] | 1143 | socket_factory_.AddSocketDataProvider(&quic_data); |
| 1144 | |
| 1145 | // Main job which will succeed even though the alternate job fails. |
| 1146 | MockRead http_reads[] = { |
| 1147 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 1148 | MockRead("hello from http"), |
| 1149 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 1150 | MockRead(ASYNC, OK) |
| 1151 | }; |
| 1152 | |
| 1153 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 1154 | nullptr, 0); |
[email protected] | d03a66d | 2013-05-06 12:55:59 | [diff] [blame] | 1155 | socket_factory_.AddSocketDataProvider(&http_data); |
| 1156 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 1157 | CreateSessionWithNextProtos(); |
[email protected] | d03a66d | 2013-05-06 12:55:59 | [diff] [blame] | 1158 | |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 1159 | AddQuicAlternateProtocolMapping(MockCryptoClientStream::COLD_START); |
| 1160 | SendRequestAndExpectHttpResponse("hello from http"); |
| 1161 | ExpectBrokenAlternateProtocolMapping(); |
[email protected] | d03a66d | 2013-05-06 12:55:59 | [diff] [blame] | 1162 | } |
| 1163 | |
[email protected] | 00c159f | 2014-05-21 22:38:16 | [diff] [blame] | 1164 | TEST_P(QuicNetworkTransactionTest, NoBrokenAlternateProtocolIfTcpFails) { |
[email protected] | eb71ab6 | 2014-05-23 07:57:53 | [diff] [blame] | 1165 | // Alternate-protocol job will fail when the session attempts to read. |
[email protected] | 00c159f | 2014-05-21 22:38:16 | [diff] [blame] | 1166 | MockRead quic_reads[] = { |
| 1167 | MockRead(ASYNC, ERR_SOCKET_NOT_CONNECTED), |
| 1168 | }; |
| 1169 | StaticSocketDataProvider quic_data(quic_reads, arraysize(quic_reads), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 1170 | nullptr, 0); |
[email protected] | 00c159f | 2014-05-21 22:38:16 | [diff] [blame] | 1171 | socket_factory_.AddSocketDataProvider(&quic_data); |
| 1172 | |
[email protected] | eb71ab6 | 2014-05-23 07:57:53 | [diff] [blame] | 1173 | // Main job will also fail. |
[email protected] | 00c159f | 2014-05-21 22:38:16 | [diff] [blame] | 1174 | MockRead http_reads[] = { |
| 1175 | MockRead(ASYNC, ERR_SOCKET_NOT_CONNECTED), |
| 1176 | }; |
| 1177 | |
| 1178 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 1179 | nullptr, 0); |
[email protected] | 00c159f | 2014-05-21 22:38:16 | [diff] [blame] | 1180 | http_data.set_connect_data(MockConnect(ASYNC, ERR_SOCKET_NOT_CONNECTED)); |
| 1181 | socket_factory_.AddSocketDataProvider(&http_data); |
| 1182 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 1183 | CreateSessionWithNextProtos(); |
[email protected] | 00c159f | 2014-05-21 22:38:16 | [diff] [blame] | 1184 | |
| 1185 | AddQuicAlternateProtocolMapping(MockCryptoClientStream::COLD_START); |
| 1186 | scoped_ptr<HttpNetworkTransaction> trans( |
| 1187 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get())); |
| 1188 | TestCompletionCallback callback; |
| 1189 | int rv = trans->Start(&request_, callback.callback(), net_log_.bound()); |
| 1190 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1191 | EXPECT_EQ(ERR_SOCKET_NOT_CONNECTED, callback.WaitForResult()); |
| 1192 | ExpectQuicAlternateProtocolMapping(); |
| 1193 | } |
| 1194 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1195 | TEST_P(QuicNetworkTransactionTest, FailedZeroRttBrokenAlternateProtocol) { |
[email protected] | 77c6c16 | 2013-08-17 02:57:45 | [diff] [blame] | 1196 | // Alternate-protocol job |
| 1197 | MockRead quic_reads[] = { |
| 1198 | MockRead(ASYNC, ERR_SOCKET_NOT_CONNECTED), |
| 1199 | }; |
| 1200 | StaticSocketDataProvider quic_data(quic_reads, arraysize(quic_reads), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 1201 | nullptr, 0); |
[email protected] | 77c6c16 | 2013-08-17 02:57:45 | [diff] [blame] | 1202 | socket_factory_.AddSocketDataProvider(&quic_data); |
| 1203 | |
| 1204 | AddHangingNonAlternateProtocolSocketData(); |
| 1205 | |
[email protected] | c92c1b5 | 2014-05-31 04:16:06 | [diff] [blame] | 1206 | // Second Alternate-protocol job which will race with the TCP job. |
| 1207 | StaticSocketDataProvider quic_data2(quic_reads, arraysize(quic_reads), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 1208 | nullptr, 0); |
[email protected] | c92c1b5 | 2014-05-31 04:16:06 | [diff] [blame] | 1209 | socket_factory_.AddSocketDataProvider(&quic_data2); |
| 1210 | |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 1211 | // Final job that will proceed when the QUIC job fails. |
| 1212 | MockRead http_reads[] = { |
| 1213 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 1214 | MockRead("hello from http"), |
| 1215 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 1216 | MockRead(ASYNC, OK) |
| 1217 | }; |
| 1218 | |
| 1219 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 1220 | nullptr, 0); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 1221 | socket_factory_.AddSocketDataProvider(&http_data); |
| 1222 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 1223 | CreateSessionWithNextProtos(); |
[email protected] | 77c6c16 | 2013-08-17 02:57:45 | [diff] [blame] | 1224 | |
| 1225 | AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT); |
| 1226 | |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 1227 | SendRequestAndExpectHttpResponse("hello from http"); |
[email protected] | 77c6c16 | 2013-08-17 02:57:45 | [diff] [blame] | 1228 | |
| 1229 | ExpectBrokenAlternateProtocolMapping(); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 1230 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 1231 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 1232 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
[email protected] | 77c6c16 | 2013-08-17 02:57:45 | [diff] [blame] | 1233 | } |
| 1234 | |
[email protected] | 93b3177 | 2014-06-19 08:03:35 | [diff] [blame] | 1235 | TEST_P(QuicNetworkTransactionTest, DISABLED_HangingZeroRttFallback) { |
[email protected] | 6576844 | 2014-06-06 23:37:03 | [diff] [blame] | 1236 | // Alternate-protocol job |
| 1237 | MockRead quic_reads[] = { |
| 1238 | MockRead(ASYNC, ERR_IO_PENDING), |
| 1239 | }; |
| 1240 | StaticSocketDataProvider quic_data(quic_reads, arraysize(quic_reads), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 1241 | nullptr, 0); |
[email protected] | 6576844 | 2014-06-06 23:37:03 | [diff] [blame] | 1242 | socket_factory_.AddSocketDataProvider(&quic_data); |
| 1243 | |
| 1244 | // Main job that will proceed when the QUIC job fails. |
| 1245 | MockRead http_reads[] = { |
| 1246 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 1247 | MockRead("hello from http"), |
| 1248 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 1249 | MockRead(ASYNC, OK) |
| 1250 | }; |
| 1251 | |
| 1252 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 1253 | nullptr, 0); |
[email protected] | 6576844 | 2014-06-06 23:37:03 | [diff] [blame] | 1254 | socket_factory_.AddSocketDataProvider(&http_data); |
| 1255 | |
| 1256 | CreateSessionWithNextProtos(); |
| 1257 | |
| 1258 | AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT); |
| 1259 | |
| 1260 | SendRequestAndExpectHttpResponse("hello from http"); |
| 1261 | } |
| 1262 | |
[email protected] | eb71ab6 | 2014-05-23 07:57:53 | [diff] [blame] | 1263 | TEST_P(QuicNetworkTransactionTest, BrokenAlternateProtocolOnConnectFailure) { |
[email protected] | 4d590c9c | 2014-05-02 05:14:33 | [diff] [blame] | 1264 | // Alternate-protocol job will fail before creating a QUIC session. |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 1265 | StaticSocketDataProvider quic_data(nullptr, 0, nullptr, 0); |
[email protected] | 4d590c9c | 2014-05-02 05:14:33 | [diff] [blame] | 1266 | quic_data.set_connect_data(MockConnect(SYNCHRONOUS, |
| 1267 | ERR_INTERNET_DISCONNECTED)); |
| 1268 | socket_factory_.AddSocketDataProvider(&quic_data); |
| 1269 | |
| 1270 | // Main job which will succeed even though the alternate job fails. |
| 1271 | MockRead http_reads[] = { |
| 1272 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 1273 | MockRead("hello from http"), |
| 1274 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 1275 | MockRead(ASYNC, OK) |
| 1276 | }; |
| 1277 | |
| 1278 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 1279 | nullptr, 0); |
[email protected] | 4d590c9c | 2014-05-02 05:14:33 | [diff] [blame] | 1280 | socket_factory_.AddSocketDataProvider(&http_data); |
| 1281 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 1282 | CreateSessionWithNextProtos(); |
[email protected] | 4d590c9c | 2014-05-02 05:14:33 | [diff] [blame] | 1283 | AddQuicAlternateProtocolMapping(MockCryptoClientStream::COLD_START); |
| 1284 | SendRequestAndExpectHttpResponse("hello from http"); |
[email protected] | eb71ab6 | 2014-05-23 07:57:53 | [diff] [blame] | 1285 | |
| 1286 | ExpectBrokenAlternateProtocolMapping(); |
[email protected] | 4d590c9c | 2014-05-02 05:14:33 | [diff] [blame] | 1287 | } |
| 1288 | |
[email protected] | 4fee967 | 2014-01-08 14:47:15 | [diff] [blame] | 1289 | TEST_P(QuicNetworkTransactionTest, ConnectionCloseDuringConnect) { |
[email protected] | 4fee967 | 2014-01-08 14:47:15 | [diff] [blame] | 1290 | MockQuicData mock_quic_data; |
rch | a5399e0 | 2015-04-21 19:32:04 | [diff] [blame] | 1291 | mock_quic_data.AddSynchronousRead(ConstructConnectionClosePacket(1)); |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 1292 | mock_quic_data.AddWrite( |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 1293 | ConstructRequestHeadersPacket(1, kClientDataStreamId1, true, true, |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 1294 | GetRequestHeaders("GET", "http", "/"))); |
| 1295 | mock_quic_data.AddWrite(ConstructAckPacket(2, 1)); |
rch | a5399e0 | 2015-04-21 19:32:04 | [diff] [blame] | 1296 | mock_quic_data.AddSocketDataToFactory(&socket_factory_); |
[email protected] | 4fee967 | 2014-01-08 14:47:15 | [diff] [blame] | 1297 | |
| 1298 | // When the QUIC connection fails, we will try the request again over HTTP. |
| 1299 | MockRead http_reads[] = { |
| 1300 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1301 | MockRead(kQuicAlternateProtocolHttpHeader), |
| 1302 | MockRead("hello world"), |
| 1303 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 1304 | MockRead(ASYNC, OK) |
| 1305 | }; |
| 1306 | |
| 1307 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 1308 | nullptr, 0); |
[email protected] | 4fee967 | 2014-01-08 14:47:15 | [diff] [blame] | 1309 | socket_factory_.AddSocketDataProvider(&http_data); |
| 1310 | |
| 1311 | // In order for a new QUIC session to be established via alternate-protocol |
| 1312 | // without racing an HTTP connection, we need the host resolution to happen |
| 1313 | // synchronously. |
| 1314 | host_resolver_.set_synchronous_mode(true); |
| 1315 | host_resolver_.rules()->AddIPLiteralRule("www.google.com", "192.168.0.1", ""); |
| 1316 | HostResolver::RequestInfo info(HostPortPair("www.google.com", 80)); |
| 1317 | AddressList address; |
| 1318 | host_resolver_.Resolve(info, |
| 1319 | DEFAULT_PRIORITY, |
| 1320 | &address, |
| 1321 | CompletionCallback(), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 1322 | nullptr, |
[email protected] | 4fee967 | 2014-01-08 14:47:15 | [diff] [blame] | 1323 | net_log_.bound()); |
| 1324 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 1325 | CreateSessionWithNextProtos(); |
[email protected] | 4fee967 | 2014-01-08 14:47:15 | [diff] [blame] | 1326 | AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT); |
| 1327 | SendRequestAndExpectHttpResponse("hello world"); |
| 1328 | } |
| 1329 | |
bnc | 50883590 | 2015-05-12 20:10:29 | [diff] [blame] | 1330 | // Test that a secure request over an insecure QUIC connection fails with |
| 1331 | // the appropriate error code. Note that this never happens in production, |
| 1332 | // because the handshake (which this test mocks) would fail in this scenario. |
| 1333 | TEST_P(QuicNetworkTransactionTest, SecureResourceOverInsecureQuic) { |
bnc | b07c0553 | 2015-05-14 19:07:20 | [diff] [blame] | 1334 | maker_.set_hostname("www.example.org"); |
bnc | 50883590 | 2015-05-12 20:10:29 | [diff] [blame] | 1335 | MockQuicData mock_quic_data; |
| 1336 | mock_quic_data.AddWrite( |
| 1337 | ConstructRequestHeadersPacket(1, kClientDataStreamId1, true, true, |
| 1338 | GetRequestHeaders("GET", "https", "/"))); |
| 1339 | mock_quic_data.AddRead(ConstructResponseHeadersPacket( |
| 1340 | 1, kClientDataStreamId1, false, false, GetResponseHeaders("200 OK"))); |
| 1341 | mock_quic_data.AddRead( |
| 1342 | ConstructDataPacket(2, kClientDataStreamId1, false, true, 0, "hello!")); |
| 1343 | mock_quic_data.AddWrite(ConstructAckPacket(2, 1)); |
| 1344 | mock_quic_data.AddRead(SYNCHRONOUS, 0); |
| 1345 | mock_quic_data.AddSocketDataToFactory(&socket_factory_); |
| 1346 | |
bnc | b07c0553 | 2015-05-14 19:07:20 | [diff] [blame] | 1347 | request_.url = GURL("https://www.example.org:443"); |
bnc | 50883590 | 2015-05-12 20:10:29 | [diff] [blame] | 1348 | AddHangingNonAlternateProtocolSocketData(); |
| 1349 | CreateSessionWithNextProtos(); |
| 1350 | AddQuicAlternateProtocolMapping(MockCryptoClientStream::CONFIRM_HANDSHAKE); |
| 1351 | scoped_ptr<HttpNetworkTransaction> trans( |
| 1352 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get())); |
| 1353 | TestCompletionCallback callback; |
| 1354 | int rv = trans->Start(&request_, callback.callback(), net_log_.bound()); |
| 1355 | EXPECT_EQ(ERR_REQUEST_FOR_SECURE_RESOURCE_OVER_INSECURE_QUIC, |
| 1356 | callback.GetResult(rv)); |
| 1357 | } |
| 1358 | |
| 1359 | TEST_P(QuicNetworkTransactionTest, SecureResourceOverSecureQuic) { |
bnc | b07c0553 | 2015-05-14 19:07:20 | [diff] [blame] | 1360 | maker_.set_hostname("www.example.org"); |
bnc | 50883590 | 2015-05-12 20:10:29 | [diff] [blame] | 1361 | MockQuicData mock_quic_data; |
| 1362 | mock_quic_data.AddWrite( |
| 1363 | ConstructRequestHeadersPacket(1, kClientDataStreamId1, true, true, |
| 1364 | GetRequestHeaders("GET", "https", "/"))); |
| 1365 | mock_quic_data.AddRead(ConstructResponseHeadersPacket( |
| 1366 | 1, kClientDataStreamId1, false, false, GetResponseHeaders("200 OK"))); |
| 1367 | mock_quic_data.AddRead( |
| 1368 | ConstructDataPacket(2, kClientDataStreamId1, false, true, 0, "hello!")); |
| 1369 | mock_quic_data.AddWrite(ConstructAckPacket(2, 1)); |
| 1370 | mock_quic_data.AddRead(SYNCHRONOUS, 0); |
| 1371 | mock_quic_data.AddSocketDataToFactory(&socket_factory_); |
| 1372 | |
| 1373 | scoped_refptr<X509Certificate> cert( |
| 1374 | ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem")); |
| 1375 | ASSERT_TRUE(cert.get()); |
bnc | b07c0553 | 2015-05-14 19:07:20 | [diff] [blame] | 1376 | bool common_name_fallback_used; |
| 1377 | EXPECT_TRUE( |
| 1378 | cert->VerifyNameMatch("www.example.org", &common_name_fallback_used)); |
bnc | 50883590 | 2015-05-12 20:10:29 | [diff] [blame] | 1379 | ProofVerifyDetailsChromium verify_details; |
| 1380 | verify_details.cert_verify_result.verified_cert = cert; |
bnc | 20daf9a | 2015-05-15 17:11:01 | [diff] [blame] | 1381 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
bnc | 50883590 | 2015-05-12 20:10:29 | [diff] [blame] | 1382 | |
bnc | b07c0553 | 2015-05-14 19:07:20 | [diff] [blame] | 1383 | request_.url = GURL("https://www.example.org:443"); |
bnc | 50883590 | 2015-05-12 20:10:29 | [diff] [blame] | 1384 | AddHangingNonAlternateProtocolSocketData(); |
| 1385 | CreateSessionWithNextProtos(); |
| 1386 | AddQuicAlternateProtocolMapping(MockCryptoClientStream::CONFIRM_HANDSHAKE); |
| 1387 | SendRequestAndExpectQuicResponse("hello!"); |
| 1388 | } |
| 1389 | |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 1390 | } // namespace test |
| 1391 | } // namespace net |