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