[email protected] | e13201d8 | 2012-12-12 05:00:32 | [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 | |
| 5 | #include "net/quic/quic_stream_factory.h" |
| 6 | |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 7 | #include "base/run_loop.h" |
[email protected] | fc9be580 | 2013-06-11 10:56:51 | [diff] [blame] | 8 | #include "base/strings/string_util.h" |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 9 | #include "net/base/test_data_directory.h" |
[email protected] | 6d1b4ed | 2013-07-10 03:57:54 | [diff] [blame] | 10 | #include "net/cert/cert_verifier.h" |
[email protected] | f2cb3cf | 2013-03-21 01:40:53 | [diff] [blame] | 11 | #include "net/dns/mock_host_resolver.h" |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 12 | #include "net/http/http_response_headers.h" |
| 13 | #include "net/http/http_response_info.h" |
| 14 | #include "net/http/http_util.h" |
[email protected] | 080b7793 | 2014-08-04 01:22:46 | [diff] [blame] | 15 | #include "net/http/transport_security_state.h" |
[email protected] | c49ff18 | 2013-09-28 08:33:26 | [diff] [blame] | 16 | #include "net/quic/crypto/crypto_handshake.h" |
[email protected] | b694e48c | 2014-03-18 17:10:13 | [diff] [blame] | 17 | #include "net/quic/crypto/proof_verifier_chromium.h" |
[email protected] | 4df6984 | 2013-02-27 06:32:16 | [diff] [blame] | 18 | #include "net/quic/crypto/quic_decrypter.h" |
| 19 | #include "net/quic/crypto/quic_encrypter.h" |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 20 | #include "net/quic/quic_http_stream.h" |
[email protected] | 257f24f | 2014-04-01 09:15:37 | [diff] [blame] | 21 | #include "net/quic/quic_server_id.h" |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 22 | #include "net/quic/test_tools/mock_clock.h" |
[email protected] | e8ff2684 | 2013-03-22 21:02:05 | [diff] [blame] | 23 | #include "net/quic/test_tools/mock_crypto_client_stream_factory.h" |
[email protected] | 9558c5d3 | 2012-12-22 00:08:14 | [diff] [blame] | 24 | #include "net/quic/test_tools/mock_random.h" |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 25 | #include "net/quic/test_tools/quic_test_packet_maker.h" |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 26 | #include "net/quic/test_tools/quic_test_utils.h" |
| 27 | #include "net/socket/socket_test_util.h" |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame^] | 28 | #include "net/spdy/spdy_test_utils.h" |
[email protected] | 6b8a3c74 | 2014-07-25 00:25:35 | [diff] [blame] | 29 | #include "net/ssl/channel_id_service.h" |
| 30 | #include "net/ssl/default_channel_id_store.h" |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 31 | #include "net/test/cert_test_util.h" |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 32 | #include "testing/gtest/include/gtest/gtest.h" |
| 33 | |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 34 | using base::StringPiece; |
| 35 | using std::string; |
| 36 | using std::vector; |
| 37 | |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 38 | namespace net { |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 39 | namespace test { |
| 40 | |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 41 | namespace { |
| 42 | const char kDefaultServerHostName[] = "www.google.com"; |
| 43 | const int kDefaultServerPort = 443; |
| 44 | } // namespace anonymous |
| 45 | |
[email protected] | c49ff18 | 2013-09-28 08:33:26 | [diff] [blame] | 46 | class QuicStreamFactoryPeer { |
| 47 | public: |
[email protected] | 59c0bbd | 2014-03-22 04:08:12 | [diff] [blame] | 48 | static QuicCryptoClientConfig* GetCryptoConfig(QuicStreamFactory* factory) { |
| 49 | return &factory->crypto_config_; |
[email protected] | c49ff18 | 2013-09-28 08:33:26 | [diff] [blame] | 50 | } |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 51 | |
| 52 | static bool HasActiveSession(QuicStreamFactory* factory, |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 53 | const HostPortPair& host_port_pair, |
[email protected] | df157d9d | 2014-03-10 07:27:27 | [diff] [blame] | 54 | bool is_https) { |
[email protected] | 257f24f | 2014-04-01 09:15:37 | [diff] [blame] | 55 | QuicServerId server_id(host_port_pair, is_https, PRIVACY_MODE_DISABLED); |
| 56 | return factory->HasActiveSession(server_id); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | static QuicClientSession* GetActiveSession( |
| 60 | QuicStreamFactory* factory, |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 61 | const HostPortPair& host_port_pair, |
[email protected] | df157d9d | 2014-03-10 07:27:27 | [diff] [blame] | 62 | bool is_https) { |
[email protected] | 257f24f | 2014-04-01 09:15:37 | [diff] [blame] | 63 | QuicServerId server_id(host_port_pair, is_https, PRIVACY_MODE_DISABLED); |
| 64 | DCHECK(factory->HasActiveSession(server_id)); |
| 65 | return factory->active_sessions_[server_id]; |
[email protected] | df157d9d | 2014-03-10 07:27:27 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | static scoped_ptr<QuicHttpStream> CreateIfSessionExists( |
| 69 | QuicStreamFactory* factory, |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 70 | const HostPortPair& host_port_pair, |
[email protected] | df157d9d | 2014-03-10 07:27:27 | [diff] [blame] | 71 | bool is_https, |
| 72 | const BoundNetLog& net_log) { |
[email protected] | 257f24f | 2014-04-01 09:15:37 | [diff] [blame] | 73 | QuicServerId server_id(host_port_pair, is_https, PRIVACY_MODE_DISABLED); |
| 74 | return factory->CreateIfSessionExists(server_id, net_log); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | static bool IsLiveSession(QuicStreamFactory* factory, |
| 78 | QuicClientSession* session) { |
[email protected] | 4d590c9c | 2014-05-02 05:14:33 | [diff] [blame] | 79 | for (QuicStreamFactory::SessionIdMap::iterator it = |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 80 | factory->all_sessions_.begin(); |
| 81 | it != factory->all_sessions_.end(); ++it) { |
[email protected] | 4d590c9c | 2014-05-02 05:14:33 | [diff] [blame] | 82 | if (it->first == session) |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 83 | return true; |
| 84 | } |
| 85 | return false; |
| 86 | } |
[email protected] | c49ff18 | 2013-09-28 08:33:26 | [diff] [blame] | 87 | }; |
| 88 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 89 | class QuicStreamFactoryTest : public ::testing::TestWithParam<QuicVersion> { |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 90 | protected: |
| 91 | QuicStreamFactoryTest() |
[email protected] | 457d695 | 2013-12-13 09:24:58 | [diff] [blame] | 92 | : random_generator_(0), |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 93 | maker_(GetParam(), 0), |
[email protected] | 457d695 | 2013-12-13 09:24:58 | [diff] [blame] | 94 | clock_(new MockClock()), |
[email protected] | 59c0bbd | 2014-03-22 04:08:12 | [diff] [blame] | 95 | cert_verifier_(CertVerifier::CreateDefault()), |
[email protected] | 6b8a3c74 | 2014-07-25 00:25:35 | [diff] [blame] | 96 | channel_id_service_(new ChannelIDService( |
| 97 | new DefaultChannelIDStore(NULL), |
[email protected] | 0cceb92 | 2014-07-01 02:00:56 | [diff] [blame] | 98 | base::MessageLoopProxy::current())), |
[email protected] | 872edd9e | 2013-01-16 08:51:15 | [diff] [blame] | 99 | factory_(&host_resolver_, &socket_factory_, |
[email protected] | 0c4017ca | 2014-06-06 03:30:45 | [diff] [blame] | 100 | base::WeakPtr<HttpServerProperties>(), cert_verifier_.get(), |
[email protected] | 080b7793 | 2014-08-04 01:22:46 | [diff] [blame] | 101 | channel_id_service_.get(), &transport_security_state_, |
[email protected] | 0c4017ca | 2014-06-06 03:30:45 | [diff] [blame] | 102 | &crypto_client_stream_factory_, &random_generator_, clock_, |
| 103 | kDefaultMaxPacketSize, std::string(), |
[email protected] | 648f8114 | 2014-08-15 21:38:46 | [diff] [blame] | 104 | SupportedVersions(GetParam()), true, true, QuicTagVector()), |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 105 | host_port_pair_(kDefaultServerHostName, kDefaultServerPort), |
[email protected] | 9dd3ff0f | 2014-03-26 09:51:28 | [diff] [blame] | 106 | is_https_(false), |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 107 | privacy_mode_(PRIVACY_MODE_DISABLED) { |
[email protected] | 11c0587 | 2013-08-20 02:04:12 | [diff] [blame] | 108 | factory_.set_require_confirmation(false); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 109 | } |
| 110 | |
[email protected] | df157d9d | 2014-03-10 07:27:27 | [diff] [blame] | 111 | scoped_ptr<QuicHttpStream> CreateIfSessionExists( |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 112 | const HostPortPair& host_port_pair, |
[email protected] | df157d9d | 2014-03-10 07:27:27 | [diff] [blame] | 113 | const BoundNetLog& net_log) { |
| 114 | return QuicStreamFactoryPeer::CreateIfSessionExists( |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 115 | &factory_, host_port_pair, false, net_log_); |
[email protected] | df157d9d | 2014-03-10 07:27:27 | [diff] [blame] | 116 | } |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 117 | |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 118 | int GetSourcePortForNewSession(const HostPortPair& destination) { |
[email protected] | d8e2abf8 | 2014-03-06 10:30:10 | [diff] [blame] | 119 | return GetSourcePortForNewSessionInner(destination, false); |
| 120 | } |
| 121 | |
| 122 | int GetSourcePortForNewSessionAndGoAway( |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 123 | const HostPortPair& destination) { |
[email protected] | d8e2abf8 | 2014-03-06 10:30:10 | [diff] [blame] | 124 | return GetSourcePortForNewSessionInner(destination, true); |
| 125 | } |
| 126 | |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 127 | int GetSourcePortForNewSessionInner(const HostPortPair& destination, |
[email protected] | d8e2abf8 | 2014-03-06 10:30:10 | [diff] [blame] | 128 | bool goaway_received) { |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 129 | // Should only be called if there is no active session for this destination. |
[email protected] | df157d9d | 2014-03-10 07:27:27 | [diff] [blame] | 130 | EXPECT_EQ(NULL, CreateIfSessionExists(destination, net_log_).get()); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 131 | size_t socket_count = socket_factory_.udp_client_sockets().size(); |
| 132 | |
| 133 | MockRead reads[] = { |
| 134 | MockRead(ASYNC, OK, 0) // EOF |
| 135 | }; |
| 136 | DeterministicSocketData socket_data(reads, arraysize(reads), NULL, 0); |
| 137 | socket_data.StopAfter(1); |
| 138 | socket_factory_.AddSocketDataProvider(&socket_data); |
| 139 | |
| 140 | QuicStreamRequest request(&factory_); |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 141 | EXPECT_EQ(ERR_IO_PENDING, |
| 142 | request.Request(destination, |
| 143 | is_https_, |
[email protected] | 9dd3ff0f | 2014-03-26 09:51:28 | [diff] [blame] | 144 | privacy_mode_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 145 | "GET", |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 146 | net_log_, |
| 147 | callback_.callback())); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 148 | |
| 149 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 150 | scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
| 151 | EXPECT_TRUE(stream.get()); |
| 152 | stream.reset(); |
| 153 | |
| 154 | QuicClientSession* session = QuicStreamFactoryPeer::GetActiveSession( |
[email protected] | df157d9d | 2014-03-10 07:27:27 | [diff] [blame] | 155 | &factory_, destination, is_https_); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 156 | |
| 157 | if (socket_count + 1 != socket_factory_.udp_client_sockets().size()) { |
| 158 | EXPECT_TRUE(false); |
| 159 | return 0; |
| 160 | } |
| 161 | |
| 162 | IPEndPoint endpoint; |
| 163 | socket_factory_. |
| 164 | udp_client_sockets()[socket_count]->GetLocalAddress(&endpoint); |
| 165 | int port = endpoint.port(); |
[email protected] | d8e2abf8 | 2014-03-06 10:30:10 | [diff] [blame] | 166 | if (goaway_received) { |
| 167 | QuicGoAwayFrame goaway(QUIC_NO_ERROR, 1, ""); |
| 168 | session->OnGoAway(goaway); |
| 169 | } |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 170 | |
| 171 | factory_.OnSessionClosed(session); |
[email protected] | df157d9d | 2014-03-10 07:27:27 | [diff] [blame] | 172 | EXPECT_EQ(NULL, CreateIfSessionExists(destination, net_log_).get()); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 173 | EXPECT_TRUE(socket_data.at_read_eof()); |
| 174 | EXPECT_TRUE(socket_data.at_write_eof()); |
| 175 | return port; |
| 176 | } |
| 177 | |
[email protected] | 459a740 | 2014-02-10 12:58:52 | [diff] [blame] | 178 | scoped_ptr<QuicEncryptedPacket> ConstructRstPacket() { |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 179 | QuicStreamId stream_id = kClientDataStreamId1; |
[email protected] | 51cc134 | 2014-04-18 23:44:37 | [diff] [blame] | 180 | return maker_.MakeRstPacket( |
| 181 | 1, true, stream_id, |
| 182 | AdjustErrorForVersion(QUIC_RST_FLOW_CONTROL_ACCOUNTING, GetParam())); |
[email protected] | 459a740 | 2014-02-10 12:58:52 | [diff] [blame] | 183 | } |
| 184 | |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 185 | MockHostResolver host_resolver_; |
[email protected] | 0edce6a | 2013-05-08 18:02:40 | [diff] [blame] | 186 | DeterministicMockClientSocketFactory socket_factory_; |
[email protected] | e8ff2684 | 2013-03-22 21:02:05 | [diff] [blame] | 187 | MockCryptoClientStreamFactory crypto_client_stream_factory_; |
[email protected] | 9558c5d3 | 2012-12-22 00:08:14 | [diff] [blame] | 188 | MockRandom random_generator_; |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 189 | QuicTestPacketMaker maker_; |
[email protected] | 872edd9e | 2013-01-16 08:51:15 | [diff] [blame] | 190 | MockClock* clock_; // Owned by factory_. |
[email protected] | 59c0bbd | 2014-03-22 04:08:12 | [diff] [blame] | 191 | scoped_ptr<CertVerifier> cert_verifier_; |
[email protected] | 6b8a3c74 | 2014-07-25 00:25:35 | [diff] [blame] | 192 | scoped_ptr<ChannelIDService> channel_id_service_; |
[email protected] | 080b7793 | 2014-08-04 01:22:46 | [diff] [blame] | 193 | TransportSecurityState transport_security_state_; |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 194 | QuicStreamFactory factory_; |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 195 | HostPortPair host_port_pair_; |
[email protected] | 6d1b4ed | 2013-07-10 03:57:54 | [diff] [blame] | 196 | bool is_https_; |
[email protected] | 9dd3ff0f | 2014-03-26 09:51:28 | [diff] [blame] | 197 | PrivacyMode privacy_mode_; |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 198 | BoundNetLog net_log_; |
| 199 | TestCompletionCallback callback_; |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 200 | }; |
| 201 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 202 | INSTANTIATE_TEST_CASE_P(Version, QuicStreamFactoryTest, |
| 203 | ::testing::ValuesIn(QuicSupportedVersions())); |
| 204 | |
| 205 | TEST_P(QuicStreamFactoryTest, CreateIfSessionExists) { |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 206 | EXPECT_EQ(NULL, CreateIfSessionExists(host_port_pair_, net_log_).get()); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 207 | } |
| 208 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 209 | TEST_P(QuicStreamFactoryTest, Create) { |
[email protected] | 69dfd1b | 2013-06-04 22:20:12 | [diff] [blame] | 210 | MockRead reads[] = { |
[email protected] | 25c31dc | 2013-06-05 17:56:04 | [diff] [blame] | 211 | MockRead(ASYNC, OK, 0) // EOF |
[email protected] | 69dfd1b | 2013-06-04 22:20:12 | [diff] [blame] | 212 | }; |
[email protected] | 25c31dc | 2013-06-05 17:56:04 | [diff] [blame] | 213 | DeterministicSocketData socket_data(reads, arraysize(reads), NULL, 0); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 214 | socket_factory_.AddSocketDataProvider(&socket_data); |
[email protected] | 25c31dc | 2013-06-05 17:56:04 | [diff] [blame] | 215 | socket_data.StopAfter(1); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 216 | |
| 217 | QuicStreamRequest request(&factory_); |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 218 | EXPECT_EQ(ERR_IO_PENDING, |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 219 | request.Request(host_port_pair_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 220 | is_https_, |
[email protected] | 9dd3ff0f | 2014-03-26 09:51:28 | [diff] [blame] | 221 | privacy_mode_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 222 | "GET", |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 223 | net_log_, |
| 224 | callback_.callback())); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 225 | |
| 226 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 227 | scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
[email protected] | 0edce6a | 2013-05-08 18:02:40 | [diff] [blame] | 228 | EXPECT_TRUE(stream.get()); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 229 | |
| 230 | // Will reset stream 3. |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 231 | stream = CreateIfSessionExists(host_port_pair_, net_log_); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 232 | EXPECT_TRUE(stream.get()); |
| 233 | |
[email protected] | 6d1b4ed | 2013-07-10 03:57:54 | [diff] [blame] | 234 | // TODO(rtenneti): We should probably have a tests that HTTP and HTTPS result |
| 235 | // in streams on different sessions. |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 236 | QuicStreamRequest request2(&factory_); |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 237 | EXPECT_EQ(OK, |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 238 | request2.Request(host_port_pair_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 239 | is_https_, |
[email protected] | 9dd3ff0f | 2014-03-26 09:51:28 | [diff] [blame] | 240 | privacy_mode_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 241 | "GET", |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 242 | net_log_, |
| 243 | callback_.callback())); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 244 | stream = request2.ReleaseStream(); // Will reset stream 5. |
| 245 | stream.reset(); // Will reset stream 7. |
| 246 | |
| 247 | EXPECT_TRUE(socket_data.at_read_eof()); |
| 248 | EXPECT_TRUE(socket_data.at_write_eof()); |
| 249 | } |
| 250 | |
[email protected] | 8bd2b81 | 2014-03-26 04:01:17 | [diff] [blame] | 251 | TEST_P(QuicStreamFactoryTest, CreateZeroRtt) { |
| 252 | MockRead reads[] = { |
| 253 | MockRead(ASYNC, OK, 0) // EOF |
| 254 | }; |
| 255 | DeterministicSocketData socket_data(reads, arraysize(reads), NULL, 0); |
| 256 | socket_factory_.AddSocketDataProvider(&socket_data); |
| 257 | socket_data.StopAfter(1); |
| 258 | |
| 259 | crypto_client_stream_factory_.set_handshake_mode( |
| 260 | MockCryptoClientStream::ZERO_RTT); |
| 261 | host_resolver_.set_synchronous_mode(true); |
| 262 | host_resolver_.rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 263 | "192.168.0.1", ""); |
| 264 | |
| 265 | QuicStreamRequest request(&factory_); |
| 266 | EXPECT_EQ(OK, |
| 267 | request.Request(host_port_pair_, |
| 268 | is_https_, |
[email protected] | 9dd3ff0f | 2014-03-26 09:51:28 | [diff] [blame] | 269 | privacy_mode_, |
[email protected] | 8bd2b81 | 2014-03-26 04:01:17 | [diff] [blame] | 270 | "GET", |
| 271 | net_log_, |
| 272 | callback_.callback())); |
| 273 | |
| 274 | scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
| 275 | EXPECT_TRUE(stream.get()); |
| 276 | EXPECT_TRUE(socket_data.at_read_eof()); |
| 277 | EXPECT_TRUE(socket_data.at_write_eof()); |
| 278 | } |
| 279 | |
| 280 | TEST_P(QuicStreamFactoryTest, CreateZeroRttPost) { |
| 281 | MockRead reads[] = { |
| 282 | MockRead(ASYNC, OK, 0) // EOF |
| 283 | }; |
| 284 | DeterministicSocketData socket_data(reads, arraysize(reads), NULL, 0); |
| 285 | socket_factory_.AddSocketDataProvider(&socket_data); |
| 286 | socket_data.StopAfter(1); |
| 287 | |
| 288 | crypto_client_stream_factory_.set_handshake_mode( |
| 289 | MockCryptoClientStream::ZERO_RTT); |
| 290 | host_resolver_.set_synchronous_mode(true); |
| 291 | host_resolver_.rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 292 | "192.168.0.1", ""); |
| 293 | |
| 294 | QuicStreamRequest request(&factory_); |
| 295 | // Posts require handshake confirmation, so this will return asynchronously. |
| 296 | EXPECT_EQ(ERR_IO_PENDING, |
| 297 | request.Request(host_port_pair_, |
| 298 | is_https_, |
[email protected] | 9dd3ff0f | 2014-03-26 09:51:28 | [diff] [blame] | 299 | privacy_mode_, |
[email protected] | 8bd2b81 | 2014-03-26 04:01:17 | [diff] [blame] | 300 | "POST", |
| 301 | net_log_, |
| 302 | callback_.callback())); |
| 303 | |
| 304 | // Confirm the handshake and verify that the stream is created. |
| 305 | crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
| 306 | QuicSession::HANDSHAKE_CONFIRMED); |
| 307 | |
| 308 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 309 | scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
| 310 | EXPECT_TRUE(stream.get()); |
| 311 | EXPECT_TRUE(socket_data.at_read_eof()); |
| 312 | EXPECT_TRUE(socket_data.at_write_eof()); |
| 313 | } |
| 314 | |
[email protected] | df157d9d | 2014-03-10 07:27:27 | [diff] [blame] | 315 | TEST_P(QuicStreamFactoryTest, CreateHttpVsHttps) { |
| 316 | MockRead reads[] = { |
| 317 | MockRead(ASYNC, OK, 0) // EOF |
| 318 | }; |
| 319 | DeterministicSocketData socket_data1(reads, arraysize(reads), NULL, 0); |
| 320 | DeterministicSocketData socket_data2(reads, arraysize(reads), NULL, 0); |
| 321 | socket_factory_.AddSocketDataProvider(&socket_data1); |
| 322 | socket_factory_.AddSocketDataProvider(&socket_data2); |
| 323 | socket_data1.StopAfter(1); |
| 324 | socket_data2.StopAfter(1); |
| 325 | |
| 326 | QuicStreamRequest request(&factory_); |
| 327 | EXPECT_EQ(ERR_IO_PENDING, |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 328 | request.Request(host_port_pair_, |
[email protected] | df157d9d | 2014-03-10 07:27:27 | [diff] [blame] | 329 | is_https_, |
[email protected] | 9dd3ff0f | 2014-03-26 09:51:28 | [diff] [blame] | 330 | privacy_mode_, |
[email protected] | df157d9d | 2014-03-10 07:27:27 | [diff] [blame] | 331 | "GET", |
[email protected] | df157d9d | 2014-03-10 07:27:27 | [diff] [blame] | 332 | net_log_, |
| 333 | callback_.callback())); |
| 334 | |
| 335 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 336 | scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
| 337 | EXPECT_TRUE(stream.get()); |
| 338 | |
| 339 | QuicStreamRequest request2(&factory_); |
| 340 | EXPECT_EQ(ERR_IO_PENDING, |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 341 | request2.Request(host_port_pair_, |
[email protected] | df157d9d | 2014-03-10 07:27:27 | [diff] [blame] | 342 | !is_https_, |
[email protected] | 9dd3ff0f | 2014-03-26 09:51:28 | [diff] [blame] | 343 | privacy_mode_, |
[email protected] | df157d9d | 2014-03-10 07:27:27 | [diff] [blame] | 344 | "GET", |
[email protected] | df157d9d | 2014-03-10 07:27:27 | [diff] [blame] | 345 | net_log_, |
| 346 | callback_.callback())); |
| 347 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 348 | stream = request2.ReleaseStream(); |
| 349 | EXPECT_TRUE(stream.get()); |
| 350 | stream.reset(); |
| 351 | |
| 352 | EXPECT_NE(QuicStreamFactoryPeer::GetActiveSession( |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 353 | &factory_, host_port_pair_, is_https_), |
[email protected] | df157d9d | 2014-03-10 07:27:27 | [diff] [blame] | 354 | QuicStreamFactoryPeer::GetActiveSession( |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 355 | &factory_, host_port_pair_, !is_https_)); |
[email protected] | df157d9d | 2014-03-10 07:27:27 | [diff] [blame] | 356 | |
| 357 | EXPECT_TRUE(socket_data1.at_read_eof()); |
| 358 | EXPECT_TRUE(socket_data1.at_write_eof()); |
| 359 | EXPECT_TRUE(socket_data2.at_read_eof()); |
| 360 | EXPECT_TRUE(socket_data2.at_write_eof()); |
| 361 | } |
| 362 | |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame^] | 363 | TEST_P(QuicStreamFactoryTest, Pooling) { |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 364 | MockRead reads[] = { |
| 365 | MockRead(ASYNC, OK, 0) // EOF |
| 366 | }; |
| 367 | DeterministicSocketData socket_data(reads, arraysize(reads), NULL, 0); |
| 368 | socket_factory_.AddSocketDataProvider(&socket_data); |
| 369 | socket_data.StopAfter(1); |
| 370 | |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 371 | HostPortPair server2("mail.google.com", kDefaultServerPort); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 372 | host_resolver_.set_synchronous_mode(true); |
| 373 | host_resolver_.rules()->AddIPLiteralRule( |
| 374 | kDefaultServerHostName, "192.168.0.1", ""); |
| 375 | host_resolver_.rules()->AddIPLiteralRule( |
| 376 | "mail.google.com", "192.168.0.1", ""); |
| 377 | |
| 378 | QuicStreamRequest request(&factory_); |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 379 | EXPECT_EQ(OK, |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 380 | request.Request(host_port_pair_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 381 | is_https_, |
[email protected] | 9dd3ff0f | 2014-03-26 09:51:28 | [diff] [blame] | 382 | privacy_mode_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 383 | "GET", |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 384 | net_log_, |
| 385 | callback_.callback())); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 386 | scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
| 387 | EXPECT_TRUE(stream.get()); |
| 388 | |
| 389 | TestCompletionCallback callback; |
| 390 | QuicStreamRequest request2(&factory_); |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 391 | EXPECT_EQ(OK, |
| 392 | request2.Request(server2, |
| 393 | is_https_, |
[email protected] | 9dd3ff0f | 2014-03-26 09:51:28 | [diff] [blame] | 394 | privacy_mode_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 395 | "GET", |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 396 | net_log_, |
| 397 | callback.callback())); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 398 | scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream(); |
| 399 | EXPECT_TRUE(stream2.get()); |
| 400 | |
| 401 | EXPECT_EQ( |
[email protected] | df157d9d | 2014-03-10 07:27:27 | [diff] [blame] | 402 | QuicStreamFactoryPeer::GetActiveSession( |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 403 | &factory_, host_port_pair_, is_https_), |
[email protected] | df157d9d | 2014-03-10 07:27:27 | [diff] [blame] | 404 | QuicStreamFactoryPeer::GetActiveSession(&factory_, server2, is_https_)); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 405 | |
| 406 | EXPECT_TRUE(socket_data.at_read_eof()); |
| 407 | EXPECT_TRUE(socket_data.at_write_eof()); |
| 408 | } |
| 409 | |
| 410 | TEST_P(QuicStreamFactoryTest, NoPoolingAfterGoAway) { |
| 411 | MockRead reads[] = { |
| 412 | MockRead(ASYNC, OK, 0) // EOF |
| 413 | }; |
| 414 | DeterministicSocketData socket_data1(reads, arraysize(reads), NULL, 0); |
| 415 | DeterministicSocketData socket_data2(reads, arraysize(reads), NULL, 0); |
| 416 | socket_factory_.AddSocketDataProvider(&socket_data1); |
| 417 | socket_factory_.AddSocketDataProvider(&socket_data2); |
| 418 | socket_data1.StopAfter(1); |
| 419 | socket_data2.StopAfter(1); |
| 420 | |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 421 | HostPortPair server2("mail.google.com", kDefaultServerPort); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 422 | host_resolver_.set_synchronous_mode(true); |
| 423 | host_resolver_.rules()->AddIPLiteralRule( |
| 424 | kDefaultServerHostName, "192.168.0.1", ""); |
| 425 | host_resolver_.rules()->AddIPLiteralRule( |
| 426 | "mail.google.com", "192.168.0.1", ""); |
| 427 | |
| 428 | QuicStreamRequest request(&factory_); |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 429 | EXPECT_EQ(OK, |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 430 | request.Request(host_port_pair_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 431 | is_https_, |
[email protected] | 9dd3ff0f | 2014-03-26 09:51:28 | [diff] [blame] | 432 | privacy_mode_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 433 | "GET", |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 434 | net_log_, |
| 435 | callback_.callback())); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 436 | scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
| 437 | EXPECT_TRUE(stream.get()); |
| 438 | |
| 439 | TestCompletionCallback callback; |
| 440 | QuicStreamRequest request2(&factory_); |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 441 | EXPECT_EQ(OK, |
| 442 | request2.Request(server2, |
| 443 | is_https_, |
[email protected] | 9dd3ff0f | 2014-03-26 09:51:28 | [diff] [blame] | 444 | privacy_mode_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 445 | "GET", |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 446 | net_log_, |
| 447 | callback.callback())); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 448 | scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream(); |
| 449 | EXPECT_TRUE(stream2.get()); |
| 450 | |
[email protected] | df157d9d | 2014-03-10 07:27:27 | [diff] [blame] | 451 | factory_.OnSessionGoingAway(QuicStreamFactoryPeer::GetActiveSession( |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 452 | &factory_, host_port_pair_, is_https_)); |
[email protected] | df157d9d | 2014-03-10 07:27:27 | [diff] [blame] | 453 | EXPECT_FALSE(QuicStreamFactoryPeer::HasActiveSession( |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 454 | &factory_, host_port_pair_, is_https_)); |
[email protected] | df157d9d | 2014-03-10 07:27:27 | [diff] [blame] | 455 | EXPECT_FALSE(QuicStreamFactoryPeer::HasActiveSession( |
| 456 | &factory_, server2, is_https_)); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 457 | |
| 458 | TestCompletionCallback callback3; |
| 459 | QuicStreamRequest request3(&factory_); |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 460 | EXPECT_EQ(OK, |
| 461 | request3.Request(server2, |
| 462 | is_https_, |
[email protected] | 9dd3ff0f | 2014-03-26 09:51:28 | [diff] [blame] | 463 | privacy_mode_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 464 | "GET", |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 465 | net_log_, |
| 466 | callback3.callback())); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 467 | scoped_ptr<QuicHttpStream> stream3 = request3.ReleaseStream(); |
| 468 | EXPECT_TRUE(stream3.get()); |
| 469 | |
[email protected] | df157d9d | 2014-03-10 07:27:27 | [diff] [blame] | 470 | EXPECT_TRUE(QuicStreamFactoryPeer::HasActiveSession( |
| 471 | &factory_, server2, is_https_)); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 472 | |
| 473 | EXPECT_TRUE(socket_data1.at_read_eof()); |
| 474 | EXPECT_TRUE(socket_data1.at_write_eof()); |
| 475 | EXPECT_TRUE(socket_data2.at_read_eof()); |
| 476 | EXPECT_TRUE(socket_data2.at_write_eof()); |
| 477 | } |
| 478 | |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame^] | 479 | TEST_P(QuicStreamFactoryTest, HttpsPooling) { |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 480 | MockRead reads[] = { |
| 481 | MockRead(ASYNC, OK, 0) // EOF |
| 482 | }; |
| 483 | DeterministicSocketData socket_data(reads, arraysize(reads), NULL, 0); |
| 484 | socket_factory_.AddSocketDataProvider(&socket_data); |
| 485 | socket_data.StopAfter(1); |
| 486 | |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 487 | HostPortPair server1("www.example.org", 443); |
| 488 | HostPortPair server2("mail.example.org", 443); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 489 | |
| 490 | // Load a cert that is valid for: |
| 491 | // www.example.org (server1) |
| 492 | // mail.example.org (server2) |
| 493 | // www.example.com |
| 494 | base::FilePath certs_dir = GetTestCertsDirectory(); |
| 495 | scoped_refptr<X509Certificate> test_cert( |
| 496 | ImportCertFromFile(certs_dir, "spdy_pooling.pem")); |
| 497 | ASSERT_NE(static_cast<X509Certificate*>(NULL), test_cert); |
[email protected] | b694e48c | 2014-03-18 17:10:13 | [diff] [blame] | 498 | ProofVerifyDetailsChromium verify_details; |
| 499 | verify_details.cert_verify_result.verified_cert = test_cert; |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame^] | 500 | verify_details.cert_verify_result.is_issued_by_known_root = true; |
[email protected] | b694e48c | 2014-03-18 17:10:13 | [diff] [blame] | 501 | crypto_client_stream_factory_.set_proof_verify_details(&verify_details); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 502 | |
| 503 | host_resolver_.set_synchronous_mode(true); |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 504 | host_resolver_.rules()->AddIPLiteralRule(server1.host(), "192.168.0.1", ""); |
| 505 | host_resolver_.rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", ""); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 506 | |
| 507 | QuicStreamRequest request(&factory_); |
| 508 | is_https_ = true; |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 509 | EXPECT_EQ(OK, |
| 510 | request.Request(server1, |
| 511 | is_https_, |
[email protected] | 9dd3ff0f | 2014-03-26 09:51:28 | [diff] [blame] | 512 | privacy_mode_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 513 | "GET", |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 514 | net_log_, |
| 515 | callback_.callback())); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 516 | scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
| 517 | EXPECT_TRUE(stream.get()); |
| 518 | |
| 519 | TestCompletionCallback callback; |
| 520 | QuicStreamRequest request2(&factory_); |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 521 | EXPECT_EQ(OK, |
| 522 | request2.Request(server2, |
| 523 | is_https_, |
[email protected] | 9dd3ff0f | 2014-03-26 09:51:28 | [diff] [blame] | 524 | privacy_mode_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 525 | "GET", |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 526 | net_log_, |
| 527 | callback_.callback())); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 528 | scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream(); |
| 529 | EXPECT_TRUE(stream2.get()); |
| 530 | |
[email protected] | df157d9d | 2014-03-10 07:27:27 | [diff] [blame] | 531 | EXPECT_EQ(QuicStreamFactoryPeer::GetActiveSession( |
| 532 | &factory_, server1, is_https_), |
| 533 | QuicStreamFactoryPeer::GetActiveSession( |
| 534 | &factory_, server2, is_https_)); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 535 | |
| 536 | EXPECT_TRUE(socket_data.at_read_eof()); |
| 537 | EXPECT_TRUE(socket_data.at_write_eof()); |
| 538 | } |
| 539 | |
| 540 | TEST_P(QuicStreamFactoryTest, NoHttpsPoolingWithCertMismatch) { |
| 541 | MockRead reads[] = { |
| 542 | MockRead(ASYNC, OK, 0) // EOF |
| 543 | }; |
| 544 | DeterministicSocketData socket_data1(reads, arraysize(reads), NULL, 0); |
| 545 | DeterministicSocketData socket_data2(reads, arraysize(reads), NULL, 0); |
| 546 | socket_factory_.AddSocketDataProvider(&socket_data1); |
| 547 | socket_factory_.AddSocketDataProvider(&socket_data2); |
| 548 | socket_data1.StopAfter(1); |
| 549 | socket_data2.StopAfter(1); |
| 550 | |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 551 | HostPortPair server1("www.example.org", 443); |
| 552 | HostPortPair server2("mail.google.com", 443); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 553 | |
| 554 | // Load a cert that is valid for: |
| 555 | // www.example.org (server1) |
| 556 | // mail.example.org |
| 557 | // www.example.com |
| 558 | // But is not valid for mail.google.com (server2). |
| 559 | base::FilePath certs_dir = GetTestCertsDirectory(); |
| 560 | scoped_refptr<X509Certificate> test_cert( |
| 561 | ImportCertFromFile(certs_dir, "spdy_pooling.pem")); |
| 562 | ASSERT_NE(static_cast<X509Certificate*>(NULL), test_cert); |
[email protected] | b694e48c | 2014-03-18 17:10:13 | [diff] [blame] | 563 | ProofVerifyDetailsChromium verify_details; |
| 564 | verify_details.cert_verify_result.verified_cert = test_cert; |
| 565 | crypto_client_stream_factory_.set_proof_verify_details(&verify_details); |
| 566 | |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 567 | |
| 568 | host_resolver_.set_synchronous_mode(true); |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 569 | host_resolver_.rules()->AddIPLiteralRule(server1.host(), "192.168.0.1", ""); |
| 570 | host_resolver_.rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", ""); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 571 | |
| 572 | QuicStreamRequest request(&factory_); |
| 573 | is_https_ = true; |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 574 | EXPECT_EQ(OK, |
| 575 | request.Request(server1, |
| 576 | is_https_, |
[email protected] | 9dd3ff0f | 2014-03-26 09:51:28 | [diff] [blame] | 577 | privacy_mode_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 578 | "GET", |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 579 | net_log_, |
| 580 | callback_.callback())); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 581 | scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
| 582 | EXPECT_TRUE(stream.get()); |
| 583 | |
| 584 | TestCompletionCallback callback; |
| 585 | QuicStreamRequest request2(&factory_); |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 586 | EXPECT_EQ(OK, |
| 587 | request2.Request(server2, |
| 588 | is_https_, |
[email protected] | 9dd3ff0f | 2014-03-26 09:51:28 | [diff] [blame] | 589 | privacy_mode_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 590 | "GET", |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 591 | net_log_, |
| 592 | callback_.callback())); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 593 | scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream(); |
| 594 | EXPECT_TRUE(stream2.get()); |
| 595 | |
[email protected] | df157d9d | 2014-03-10 07:27:27 | [diff] [blame] | 596 | EXPECT_NE(QuicStreamFactoryPeer::GetActiveSession( |
| 597 | &factory_, server1, is_https_), |
| 598 | QuicStreamFactoryPeer::GetActiveSession( |
| 599 | &factory_, server2, is_https_)); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 600 | |
| 601 | EXPECT_TRUE(socket_data1.at_read_eof()); |
| 602 | EXPECT_TRUE(socket_data1.at_write_eof()); |
| 603 | EXPECT_TRUE(socket_data2.at_read_eof()); |
| 604 | EXPECT_TRUE(socket_data2.at_write_eof()); |
| 605 | } |
| 606 | |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame^] | 607 | TEST_P(QuicStreamFactoryTest, HttpsPoolingWithMatchingPins) { |
| 608 | MockRead reads[] = { |
| 609 | MockRead(ASYNC, OK, 0) // EOF |
| 610 | }; |
| 611 | DeterministicSocketData socket_data(reads, arraysize(reads), NULL, 0); |
| 612 | socket_factory_.AddSocketDataProvider(&socket_data); |
| 613 | socket_data.StopAfter(1); |
| 614 | |
| 615 | HostPortPair server1("www.example.org", 443); |
| 616 | HostPortPair server2("mail.example.org", 443); |
| 617 | uint8 primary_pin = 1; |
| 618 | uint8 backup_pin = 2; |
| 619 | test::AddPin(&transport_security_state_, "mail.example.org", primary_pin, |
| 620 | backup_pin); |
| 621 | |
| 622 | // Load a cert that is valid for: |
| 623 | // www.example.org (server1) |
| 624 | // mail.example.org (server2) |
| 625 | base::FilePath certs_dir = GetTestCertsDirectory(); |
| 626 | scoped_refptr<X509Certificate> test_cert( |
| 627 | ImportCertFromFile(certs_dir, "spdy_pooling.pem")); |
| 628 | ASSERT_NE(static_cast<X509Certificate*>(NULL), test_cert); |
| 629 | ProofVerifyDetailsChromium verify_details; |
| 630 | verify_details.cert_verify_result.verified_cert = test_cert; |
| 631 | verify_details.cert_verify_result.is_issued_by_known_root = true; |
| 632 | verify_details.cert_verify_result.public_key_hashes.push_back( |
| 633 | test::GetTestHashValue(primary_pin)); |
| 634 | crypto_client_stream_factory_.set_proof_verify_details(&verify_details); |
| 635 | |
| 636 | |
| 637 | host_resolver_.set_synchronous_mode(true); |
| 638 | host_resolver_.rules()->AddIPLiteralRule(server1.host(), "192.168.0.1", ""); |
| 639 | host_resolver_.rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", ""); |
| 640 | |
| 641 | QuicStreamRequest request(&factory_); |
| 642 | is_https_ = true; |
| 643 | EXPECT_EQ(OK, |
| 644 | request.Request(server1, |
| 645 | is_https_, |
| 646 | privacy_mode_, |
| 647 | "GET", |
| 648 | net_log_, |
| 649 | callback_.callback())); |
| 650 | scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
| 651 | EXPECT_TRUE(stream.get()); |
| 652 | |
| 653 | TestCompletionCallback callback; |
| 654 | QuicStreamRequest request2(&factory_); |
| 655 | EXPECT_EQ(OK, |
| 656 | request2.Request(server2, |
| 657 | is_https_, |
| 658 | privacy_mode_, |
| 659 | "GET", |
| 660 | net_log_, |
| 661 | callback_.callback())); |
| 662 | scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream(); |
| 663 | EXPECT_TRUE(stream2.get()); |
| 664 | |
| 665 | EXPECT_EQ(QuicStreamFactoryPeer::GetActiveSession( |
| 666 | &factory_, server1, is_https_), |
| 667 | QuicStreamFactoryPeer::GetActiveSession( |
| 668 | &factory_, server2, is_https_)); |
| 669 | |
| 670 | EXPECT_TRUE(socket_data.at_read_eof()); |
| 671 | EXPECT_TRUE(socket_data.at_write_eof()); |
| 672 | } |
| 673 | |
| 674 | TEST_P(QuicStreamFactoryTest, NoHttpsPoolingWithDifferentPins) { |
| 675 | MockRead reads[] = { |
| 676 | MockRead(ASYNC, OK, 0) // EOF |
| 677 | }; |
| 678 | DeterministicSocketData socket_data1(reads, arraysize(reads), NULL, 0); |
| 679 | DeterministicSocketData socket_data2(reads, arraysize(reads), NULL, 0); |
| 680 | socket_factory_.AddSocketDataProvider(&socket_data1); |
| 681 | socket_factory_.AddSocketDataProvider(&socket_data2); |
| 682 | socket_data1.StopAfter(1); |
| 683 | socket_data2.StopAfter(1); |
| 684 | |
| 685 | HostPortPair server1("www.example.org", 443); |
| 686 | HostPortPair server2("mail.example.org", 443); |
| 687 | uint8 primary_pin = 1; |
| 688 | uint8 backup_pin = 2; |
| 689 | uint8 bad_pin = 3; |
| 690 | test::AddPin(&transport_security_state_, "mail.example.org", primary_pin, |
| 691 | backup_pin); |
| 692 | |
| 693 | // Load a cert that is valid for: |
| 694 | // www.example.org (server1) |
| 695 | // mail.example.org (server2) |
| 696 | base::FilePath certs_dir = GetTestCertsDirectory(); |
| 697 | scoped_refptr<X509Certificate> test_cert( |
| 698 | ImportCertFromFile(certs_dir, "spdy_pooling.pem")); |
| 699 | ASSERT_NE(static_cast<X509Certificate*>(NULL), test_cert); |
| 700 | ProofVerifyDetailsChromium verify_details; |
| 701 | verify_details.cert_verify_result.verified_cert = test_cert; |
| 702 | verify_details.cert_verify_result.is_issued_by_known_root = true; |
| 703 | verify_details.cert_verify_result.public_key_hashes.push_back( |
| 704 | test::GetTestHashValue(bad_pin)); |
| 705 | crypto_client_stream_factory_.set_proof_verify_details(&verify_details); |
| 706 | |
| 707 | |
| 708 | host_resolver_.set_synchronous_mode(true); |
| 709 | host_resolver_.rules()->AddIPLiteralRule(server1.host(), "192.168.0.1", ""); |
| 710 | host_resolver_.rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", ""); |
| 711 | |
| 712 | QuicStreamRequest request(&factory_); |
| 713 | is_https_ = true; |
| 714 | EXPECT_EQ(OK, |
| 715 | request.Request(server1, |
| 716 | is_https_, |
| 717 | privacy_mode_, |
| 718 | "GET", |
| 719 | net_log_, |
| 720 | callback_.callback())); |
| 721 | scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
| 722 | EXPECT_TRUE(stream.get()); |
| 723 | |
| 724 | TestCompletionCallback callback; |
| 725 | QuicStreamRequest request2(&factory_); |
| 726 | EXPECT_EQ(OK, |
| 727 | request2.Request(server2, |
| 728 | is_https_, |
| 729 | privacy_mode_, |
| 730 | "GET", |
| 731 | net_log_, |
| 732 | callback_.callback())); |
| 733 | scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream(); |
| 734 | EXPECT_TRUE(stream2.get()); |
| 735 | |
| 736 | EXPECT_NE(QuicStreamFactoryPeer::GetActiveSession( |
| 737 | &factory_, server1, is_https_), |
| 738 | QuicStreamFactoryPeer::GetActiveSession( |
| 739 | &factory_, server2, is_https_)); |
| 740 | |
| 741 | EXPECT_TRUE(socket_data1.at_read_eof()); |
| 742 | EXPECT_TRUE(socket_data1.at_write_eof()); |
| 743 | EXPECT_TRUE(socket_data2.at_read_eof()); |
| 744 | EXPECT_TRUE(socket_data2.at_write_eof()); |
| 745 | } |
| 746 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 747 | TEST_P(QuicStreamFactoryTest, Goaway) { |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 748 | MockRead reads[] = { |
| 749 | MockRead(ASYNC, OK, 0) // EOF |
| 750 | }; |
| 751 | DeterministicSocketData socket_data(reads, arraysize(reads), NULL, 0); |
| 752 | socket_data.StopAfter(1); |
| 753 | socket_factory_.AddSocketDataProvider(&socket_data); |
| 754 | DeterministicSocketData socket_data2(reads, arraysize(reads), NULL, 0); |
| 755 | socket_data2.StopAfter(1); |
| 756 | socket_factory_.AddSocketDataProvider(&socket_data2); |
| 757 | |
| 758 | QuicStreamRequest request(&factory_); |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 759 | EXPECT_EQ(ERR_IO_PENDING, |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 760 | request.Request(host_port_pair_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 761 | is_https_, |
[email protected] | 9dd3ff0f | 2014-03-26 09:51:28 | [diff] [blame] | 762 | privacy_mode_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 763 | "GET", |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 764 | net_log_, |
| 765 | callback_.callback())); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 766 | |
| 767 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 768 | scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
| 769 | EXPECT_TRUE(stream.get()); |
| 770 | |
| 771 | // Mark the session as going away. Ensure that while it is still alive |
| 772 | // that it is no longer active. |
| 773 | QuicClientSession* session = QuicStreamFactoryPeer::GetActiveSession( |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 774 | &factory_, host_port_pair_, is_https_); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 775 | factory_.OnSessionGoingAway(session); |
| 776 | EXPECT_EQ(true, QuicStreamFactoryPeer::IsLiveSession(&factory_, session)); |
[email protected] | df157d9d | 2014-03-10 07:27:27 | [diff] [blame] | 777 | EXPECT_FALSE(QuicStreamFactoryPeer::HasActiveSession( |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 778 | &factory_, host_port_pair_, is_https_)); |
| 779 | EXPECT_EQ(NULL, CreateIfSessionExists(host_port_pair_, net_log_).get()); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 780 | |
| 781 | // Create a new request for the same destination and verify that a |
| 782 | // new session is created. |
| 783 | QuicStreamRequest request2(&factory_); |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 784 | EXPECT_EQ(ERR_IO_PENDING, |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 785 | request2.Request(host_port_pair_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 786 | is_https_, |
[email protected] | 9dd3ff0f | 2014-03-26 09:51:28 | [diff] [blame] | 787 | privacy_mode_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 788 | "GET", |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 789 | net_log_, |
| 790 | callback_.callback())); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 791 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 792 | scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream(); |
| 793 | EXPECT_TRUE(stream2.get()); |
| 794 | |
| 795 | EXPECT_TRUE(QuicStreamFactoryPeer::HasActiveSession(&factory_, |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 796 | host_port_pair_, |
[email protected] | df157d9d | 2014-03-10 07:27:27 | [diff] [blame] | 797 | is_https_)); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 798 | EXPECT_NE(session, |
| 799 | QuicStreamFactoryPeer::GetActiveSession( |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 800 | &factory_, host_port_pair_, is_https_)); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 801 | EXPECT_EQ(true, QuicStreamFactoryPeer::IsLiveSession(&factory_, session)); |
| 802 | |
| 803 | stream2.reset(); |
| 804 | stream.reset(); |
| 805 | |
| 806 | EXPECT_TRUE(socket_data.at_read_eof()); |
| 807 | EXPECT_TRUE(socket_data.at_write_eof()); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 808 | EXPECT_TRUE(socket_data2.at_read_eof()); |
| 809 | EXPECT_TRUE(socket_data2.at_write_eof()); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 810 | } |
| 811 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 812 | TEST_P(QuicStreamFactoryTest, MaxOpenStream) { |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 813 | MockRead reads[] = { |
| 814 | MockRead(ASYNC, OK, 0) // EOF |
| 815 | }; |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 816 | QuicStreamId stream_id = kClientDataStreamId1; |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 817 | scoped_ptr<QuicEncryptedPacket> rst( |
| 818 | maker_.MakeRstPacket(1, true, stream_id, QUIC_STREAM_CANCELLED)); |
[email protected] | 06ff515 | 2013-08-29 01:03:05 | [diff] [blame] | 819 | MockWrite writes[] = { |
| 820 | MockWrite(ASYNC, rst->data(), rst->length(), 1), |
| 821 | }; |
| 822 | DeterministicSocketData socket_data(reads, arraysize(reads), |
| 823 | writes, arraysize(writes)); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 824 | socket_factory_.AddSocketDataProvider(&socket_data); |
| 825 | socket_data.StopAfter(1); |
| 826 | |
| 827 | HttpRequestInfo request_info; |
| 828 | std::vector<QuicHttpStream*> streams; |
| 829 | // The MockCryptoClientStream sets max_open_streams to be |
| 830 | // 2 * kDefaultMaxStreamsPerConnection. |
| 831 | for (size_t i = 0; i < 2 * kDefaultMaxStreamsPerConnection; i++) { |
| 832 | QuicStreamRequest request(&factory_); |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 833 | int rv = request.Request(host_port_pair_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 834 | is_https_, |
[email protected] | 9dd3ff0f | 2014-03-26 09:51:28 | [diff] [blame] | 835 | privacy_mode_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 836 | "GET", |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 837 | net_log_, |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 838 | callback_.callback()); |
| 839 | if (i == 0) { |
| 840 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 841 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 842 | } else { |
| 843 | EXPECT_EQ(OK, rv); |
| 844 | } |
| 845 | scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
| 846 | EXPECT_TRUE(stream); |
| 847 | EXPECT_EQ(OK, stream->InitializeStream( |
| 848 | &request_info, DEFAULT_PRIORITY, net_log_, CompletionCallback())); |
| 849 | streams.push_back(stream.release()); |
| 850 | } |
| 851 | |
| 852 | QuicStreamRequest request(&factory_); |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 853 | EXPECT_EQ(OK, |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 854 | request.Request(host_port_pair_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 855 | is_https_, |
[email protected] | 9dd3ff0f | 2014-03-26 09:51:28 | [diff] [blame] | 856 | privacy_mode_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 857 | "GET", |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 858 | net_log_, |
| 859 | CompletionCallback())); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 860 | scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
| 861 | EXPECT_TRUE(stream); |
| 862 | EXPECT_EQ(ERR_IO_PENDING, stream->InitializeStream( |
| 863 | &request_info, DEFAULT_PRIORITY, net_log_, callback_.callback())); |
| 864 | |
| 865 | // Close the first stream. |
| 866 | streams.front()->Close(false); |
| 867 | |
| 868 | ASSERT_TRUE(callback_.have_result()); |
| 869 | |
| 870 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 871 | |
| 872 | EXPECT_TRUE(socket_data.at_read_eof()); |
| 873 | EXPECT_TRUE(socket_data.at_write_eof()); |
| 874 | STLDeleteElements(&streams); |
| 875 | } |
| 876 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 877 | TEST_P(QuicStreamFactoryTest, ResolutionErrorInCreate) { |
[email protected] | 0edce6a | 2013-05-08 18:02:40 | [diff] [blame] | 878 | DeterministicSocketData socket_data(NULL, 0, NULL, 0); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 879 | socket_factory_.AddSocketDataProvider(&socket_data); |
| 880 | |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 881 | host_resolver_.rules()->AddSimulatedFailure(kDefaultServerHostName); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 882 | |
| 883 | QuicStreamRequest request(&factory_); |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 884 | EXPECT_EQ(ERR_IO_PENDING, |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 885 | request.Request(host_port_pair_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 886 | is_https_, |
[email protected] | 9dd3ff0f | 2014-03-26 09:51:28 | [diff] [blame] | 887 | privacy_mode_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 888 | "GET", |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 889 | net_log_, |
| 890 | callback_.callback())); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 891 | |
| 892 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, callback_.WaitForResult()); |
| 893 | |
| 894 | EXPECT_TRUE(socket_data.at_read_eof()); |
| 895 | EXPECT_TRUE(socket_data.at_write_eof()); |
| 896 | } |
| 897 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 898 | TEST_P(QuicStreamFactoryTest, ConnectErrorInCreate) { |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 899 | MockConnect connect(SYNCHRONOUS, ERR_ADDRESS_IN_USE); |
| 900 | DeterministicSocketData socket_data(NULL, 0, NULL, 0); |
| 901 | socket_data.set_connect_data(connect); |
| 902 | socket_factory_.AddSocketDataProvider(&socket_data); |
| 903 | socket_data.StopAfter(1); |
| 904 | |
| 905 | QuicStreamRequest request(&factory_); |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 906 | EXPECT_EQ(ERR_IO_PENDING, |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 907 | request.Request(host_port_pair_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 908 | is_https_, |
[email protected] | 9dd3ff0f | 2014-03-26 09:51:28 | [diff] [blame] | 909 | privacy_mode_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 910 | "GET", |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 911 | net_log_, |
| 912 | callback_.callback())); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 913 | |
| 914 | EXPECT_EQ(ERR_ADDRESS_IN_USE, callback_.WaitForResult()); |
| 915 | |
| 916 | EXPECT_TRUE(socket_data.at_read_eof()); |
| 917 | EXPECT_TRUE(socket_data.at_write_eof()); |
| 918 | } |
| 919 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 920 | TEST_P(QuicStreamFactoryTest, CancelCreate) { |
[email protected] | 69dfd1b | 2013-06-04 22:20:12 | [diff] [blame] | 921 | MockRead reads[] = { |
[email protected] | 25c31dc | 2013-06-05 17:56:04 | [diff] [blame] | 922 | MockRead(ASYNC, OK, 0) // EOF |
[email protected] | 69dfd1b | 2013-06-04 22:20:12 | [diff] [blame] | 923 | }; |
[email protected] | 25c31dc | 2013-06-05 17:56:04 | [diff] [blame] | 924 | DeterministicSocketData socket_data(reads, arraysize(reads), NULL, 0); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 925 | socket_factory_.AddSocketDataProvider(&socket_data); |
| 926 | { |
| 927 | QuicStreamRequest request(&factory_); |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 928 | EXPECT_EQ(ERR_IO_PENDING, |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 929 | request.Request(host_port_pair_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 930 | is_https_, |
[email protected] | 9dd3ff0f | 2014-03-26 09:51:28 | [diff] [blame] | 931 | privacy_mode_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 932 | "GET", |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 933 | net_log_, |
| 934 | callback_.callback())); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 935 | } |
| 936 | |
[email protected] | 25c31dc | 2013-06-05 17:56:04 | [diff] [blame] | 937 | socket_data.StopAfter(1); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 938 | base::RunLoop run_loop; |
| 939 | run_loop.RunUntilIdle(); |
| 940 | |
| 941 | scoped_ptr<QuicHttpStream> stream( |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 942 | CreateIfSessionExists(host_port_pair_, net_log_)); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 943 | EXPECT_TRUE(stream.get()); |
| 944 | stream.reset(); |
| 945 | |
| 946 | EXPECT_TRUE(socket_data.at_read_eof()); |
| 947 | EXPECT_TRUE(socket_data.at_write_eof()); |
| 948 | } |
| 949 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 950 | TEST_P(QuicStreamFactoryTest, CreateConsistentEphemeralPort) { |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 951 | // Sequentially connect to the default host, then another host, and then the |
| 952 | // default host. Verify that the default host gets a consistent ephemeral |
| 953 | // port, that is different from the other host's connection. |
| 954 | |
| 955 | std::string other_server_name = "other.google.com"; |
| 956 | EXPECT_NE(kDefaultServerHostName, other_server_name); |
| 957 | HostPortPair host_port_pair2(other_server_name, kDefaultServerPort); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 958 | |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 959 | int original_port = GetSourcePortForNewSession(host_port_pair_); |
| 960 | EXPECT_NE(original_port, GetSourcePortForNewSession(host_port_pair2)); |
| 961 | EXPECT_EQ(original_port, GetSourcePortForNewSession(host_port_pair_)); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 962 | } |
| 963 | |
[email protected] | d8e2abf8 | 2014-03-06 10:30:10 | [diff] [blame] | 964 | TEST_P(QuicStreamFactoryTest, GoAwayDisablesConsistentEphemeralPort) { |
| 965 | // Get a session to the host using the port suggester. |
| 966 | int original_port = |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 967 | GetSourcePortForNewSessionAndGoAway(host_port_pair_); |
[email protected] | d8e2abf8 | 2014-03-06 10:30:10 | [diff] [blame] | 968 | // Verify that the port is different after the goaway. |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 969 | EXPECT_NE(original_port, GetSourcePortForNewSession(host_port_pair_)); |
[email protected] | d8e2abf8 | 2014-03-06 10:30:10 | [diff] [blame] | 970 | // Since the previous session did not goaway we should see the original port. |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 971 | EXPECT_EQ(original_port, GetSourcePortForNewSession(host_port_pair_)); |
[email protected] | d8e2abf8 | 2014-03-06 10:30:10 | [diff] [blame] | 972 | } |
| 973 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 974 | TEST_P(QuicStreamFactoryTest, CloseAllSessions) { |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 975 | MockRead reads[] = { |
[email protected] | 0edce6a | 2013-05-08 18:02:40 | [diff] [blame] | 976 | MockRead(ASYNC, 0, 0) // EOF |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 977 | }; |
[email protected] | 459a740 | 2014-02-10 12:58:52 | [diff] [blame] | 978 | scoped_ptr<QuicEncryptedPacket> rst(ConstructRstPacket()); |
| 979 | std::vector<MockWrite> writes; |
[email protected] | 08da9adb | 2014-04-24 08:33:31 | [diff] [blame] | 980 | writes.push_back(MockWrite(ASYNC, rst->data(), rst->length(), 1)); |
[email protected] | 459a740 | 2014-02-10 12:58:52 | [diff] [blame] | 981 | DeterministicSocketData socket_data(reads, arraysize(reads), |
| 982 | writes.empty() ? NULL : &writes[0], |
| 983 | writes.size()); |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 984 | socket_factory_.AddSocketDataProvider(&socket_data); |
[email protected] | 0edce6a | 2013-05-08 18:02:40 | [diff] [blame] | 985 | socket_data.StopAfter(1); |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 986 | |
[email protected] | 69dfd1b | 2013-06-04 22:20:12 | [diff] [blame] | 987 | MockRead reads2[] = { |
[email protected] | 25c31dc | 2013-06-05 17:56:04 | [diff] [blame] | 988 | MockRead(ASYNC, 0, 0) // EOF |
[email protected] | 69dfd1b | 2013-06-04 22:20:12 | [diff] [blame] | 989 | }; |
[email protected] | 25c31dc | 2013-06-05 17:56:04 | [diff] [blame] | 990 | DeterministicSocketData socket_data2(reads2, arraysize(reads2), NULL, 0); |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 991 | socket_factory_.AddSocketDataProvider(&socket_data2); |
[email protected] | 0edce6a | 2013-05-08 18:02:40 | [diff] [blame] | 992 | socket_data2.StopAfter(1); |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 993 | |
| 994 | QuicStreamRequest request(&factory_); |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 995 | EXPECT_EQ(ERR_IO_PENDING, |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 996 | request.Request(host_port_pair_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 997 | is_https_, |
[email protected] | 9dd3ff0f | 2014-03-26 09:51:28 | [diff] [blame] | 998 | privacy_mode_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 999 | "GET", |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 1000 | net_log_, |
| 1001 | callback_.callback())); |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 1002 | |
| 1003 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 1004 | scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 1005 | HttpRequestInfo request_info; |
| 1006 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, |
| 1007 | DEFAULT_PRIORITY, |
| 1008 | net_log_, CompletionCallback())); |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 1009 | |
| 1010 | // Close the session and verify that stream saw the error. |
| 1011 | factory_.CloseAllSessions(ERR_INTERNET_DISCONNECTED); |
| 1012 | EXPECT_EQ(ERR_INTERNET_DISCONNECTED, |
| 1013 | stream->ReadResponseHeaders(callback_.callback())); |
| 1014 | |
| 1015 | // Now attempting to request a stream to the same origin should create |
| 1016 | // a new session. |
| 1017 | |
| 1018 | QuicStreamRequest request2(&factory_); |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 1019 | EXPECT_EQ(ERR_IO_PENDING, |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 1020 | request2.Request(host_port_pair_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 1021 | is_https_, |
[email protected] | 9dd3ff0f | 2014-03-26 09:51:28 | [diff] [blame] | 1022 | privacy_mode_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 1023 | "GET", |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 1024 | net_log_, |
| 1025 | callback_.callback())); |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 1026 | |
| 1027 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 1028 | stream = request2.ReleaseStream(); |
| 1029 | stream.reset(); // Will reset stream 3. |
| 1030 | |
| 1031 | EXPECT_TRUE(socket_data.at_read_eof()); |
| 1032 | EXPECT_TRUE(socket_data.at_write_eof()); |
| 1033 | EXPECT_TRUE(socket_data2.at_read_eof()); |
| 1034 | EXPECT_TRUE(socket_data2.at_write_eof()); |
| 1035 | } |
| 1036 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1037 | TEST_P(QuicStreamFactoryTest, OnIPAddressChanged) { |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 1038 | MockRead reads[] = { |
[email protected] | 0edce6a | 2013-05-08 18:02:40 | [diff] [blame] | 1039 | MockRead(ASYNC, 0, 0) // EOF |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 1040 | }; |
[email protected] | 459a740 | 2014-02-10 12:58:52 | [diff] [blame] | 1041 | scoped_ptr<QuicEncryptedPacket> rst(ConstructRstPacket()); |
| 1042 | std::vector<MockWrite> writes; |
[email protected] | 08da9adb | 2014-04-24 08:33:31 | [diff] [blame] | 1043 | writes.push_back(MockWrite(ASYNC, rst->data(), rst->length(), 1)); |
[email protected] | 459a740 | 2014-02-10 12:58:52 | [diff] [blame] | 1044 | DeterministicSocketData socket_data(reads, arraysize(reads), |
| 1045 | writes.empty() ? NULL : &writes[0], |
| 1046 | writes.size()); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 1047 | socket_factory_.AddSocketDataProvider(&socket_data); |
[email protected] | 0edce6a | 2013-05-08 18:02:40 | [diff] [blame] | 1048 | socket_data.StopAfter(1); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 1049 | |
[email protected] | 69dfd1b | 2013-06-04 22:20:12 | [diff] [blame] | 1050 | MockRead reads2[] = { |
[email protected] | 25c31dc | 2013-06-05 17:56:04 | [diff] [blame] | 1051 | MockRead(ASYNC, 0, 0) // EOF |
[email protected] | 69dfd1b | 2013-06-04 22:20:12 | [diff] [blame] | 1052 | }; |
[email protected] | 25c31dc | 2013-06-05 17:56:04 | [diff] [blame] | 1053 | DeterministicSocketData socket_data2(reads2, arraysize(reads2), NULL, 0); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 1054 | socket_factory_.AddSocketDataProvider(&socket_data2); |
[email protected] | 0edce6a | 2013-05-08 18:02:40 | [diff] [blame] | 1055 | socket_data2.StopAfter(1); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 1056 | |
| 1057 | QuicStreamRequest request(&factory_); |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 1058 | EXPECT_EQ(ERR_IO_PENDING, |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 1059 | request.Request(host_port_pair_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 1060 | is_https_, |
[email protected] | 9dd3ff0f | 2014-03-26 09:51:28 | [diff] [blame] | 1061 | privacy_mode_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 1062 | "GET", |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 1063 | net_log_, |
| 1064 | callback_.callback())); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 1065 | |
| 1066 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 1067 | scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 1068 | HttpRequestInfo request_info; |
| 1069 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, |
| 1070 | DEFAULT_PRIORITY, |
| 1071 | net_log_, CompletionCallback())); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 1072 | |
| 1073 | // Change the IP address and verify that stream saw the error. |
| 1074 | factory_.OnIPAddressChanged(); |
| 1075 | EXPECT_EQ(ERR_NETWORK_CHANGED, |
| 1076 | stream->ReadResponseHeaders(callback_.callback())); |
[email protected] | 11c0587 | 2013-08-20 02:04:12 | [diff] [blame] | 1077 | EXPECT_TRUE(factory_.require_confirmation()); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 1078 | |
| 1079 | // Now attempting to request a stream to the same origin should create |
| 1080 | // a new session. |
| 1081 | |
| 1082 | QuicStreamRequest request2(&factory_); |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 1083 | EXPECT_EQ(ERR_IO_PENDING, |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 1084 | request2.Request(host_port_pair_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 1085 | is_https_, |
[email protected] | 9dd3ff0f | 2014-03-26 09:51:28 | [diff] [blame] | 1086 | privacy_mode_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 1087 | "GET", |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 1088 | net_log_, |
| 1089 | callback_.callback())); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 1090 | |
| 1091 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 1092 | stream = request2.ReleaseStream(); |
| 1093 | stream.reset(); // Will reset stream 3. |
| 1094 | |
| 1095 | EXPECT_TRUE(socket_data.at_read_eof()); |
| 1096 | EXPECT_TRUE(socket_data.at_write_eof()); |
| 1097 | EXPECT_TRUE(socket_data2.at_read_eof()); |
| 1098 | EXPECT_TRUE(socket_data2.at_write_eof()); |
| 1099 | } |
| 1100 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1101 | TEST_P(QuicStreamFactoryTest, OnCertAdded) { |
[email protected] | d7d1e50b | 2013-11-25 22:08:09 | [diff] [blame] | 1102 | MockRead reads[] = { |
| 1103 | MockRead(ASYNC, 0, 0) // EOF |
| 1104 | }; |
[email protected] | 459a740 | 2014-02-10 12:58:52 | [diff] [blame] | 1105 | scoped_ptr<QuicEncryptedPacket> rst(ConstructRstPacket()); |
| 1106 | std::vector<MockWrite> writes; |
[email protected] | 08da9adb | 2014-04-24 08:33:31 | [diff] [blame] | 1107 | writes.push_back(MockWrite(ASYNC, rst->data(), rst->length(), 1)); |
[email protected] | 459a740 | 2014-02-10 12:58:52 | [diff] [blame] | 1108 | DeterministicSocketData socket_data(reads, arraysize(reads), |
| 1109 | writes.empty() ? NULL : &writes[0], |
| 1110 | writes.size()); |
[email protected] | d7d1e50b | 2013-11-25 22:08:09 | [diff] [blame] | 1111 | socket_factory_.AddSocketDataProvider(&socket_data); |
| 1112 | socket_data.StopAfter(1); |
| 1113 | |
| 1114 | MockRead reads2[] = { |
| 1115 | MockRead(ASYNC, 0, 0) // EOF |
| 1116 | }; |
| 1117 | DeterministicSocketData socket_data2(reads2, arraysize(reads2), NULL, 0); |
| 1118 | socket_factory_.AddSocketDataProvider(&socket_data2); |
| 1119 | socket_data2.StopAfter(1); |
| 1120 | |
| 1121 | QuicStreamRequest request(&factory_); |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 1122 | EXPECT_EQ(ERR_IO_PENDING, |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 1123 | request.Request(host_port_pair_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 1124 | is_https_, |
[email protected] | 9dd3ff0f | 2014-03-26 09:51:28 | [diff] [blame] | 1125 | privacy_mode_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 1126 | "GET", |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 1127 | net_log_, |
| 1128 | callback_.callback())); |
[email protected] | d7d1e50b | 2013-11-25 22:08:09 | [diff] [blame] | 1129 | |
| 1130 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 1131 | scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
| 1132 | HttpRequestInfo request_info; |
| 1133 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, |
| 1134 | DEFAULT_PRIORITY, |
| 1135 | net_log_, CompletionCallback())); |
| 1136 | |
| 1137 | // Add a cert and verify that stream saw the event. |
| 1138 | factory_.OnCertAdded(NULL); |
| 1139 | EXPECT_EQ(ERR_CERT_DATABASE_CHANGED, |
| 1140 | stream->ReadResponseHeaders(callback_.callback())); |
| 1141 | EXPECT_FALSE(factory_.require_confirmation()); |
| 1142 | |
| 1143 | // Now attempting to request a stream to the same origin should create |
| 1144 | // a new session. |
| 1145 | |
| 1146 | QuicStreamRequest request2(&factory_); |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 1147 | EXPECT_EQ(ERR_IO_PENDING, |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 1148 | request2.Request(host_port_pair_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 1149 | is_https_, |
[email protected] | 9dd3ff0f | 2014-03-26 09:51:28 | [diff] [blame] | 1150 | privacy_mode_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 1151 | "GET", |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 1152 | net_log_, |
| 1153 | callback_.callback())); |
[email protected] | d7d1e50b | 2013-11-25 22:08:09 | [diff] [blame] | 1154 | |
| 1155 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 1156 | stream = request2.ReleaseStream(); |
| 1157 | stream.reset(); // Will reset stream 3. |
| 1158 | |
| 1159 | EXPECT_TRUE(socket_data.at_read_eof()); |
| 1160 | EXPECT_TRUE(socket_data.at_write_eof()); |
| 1161 | EXPECT_TRUE(socket_data2.at_read_eof()); |
| 1162 | EXPECT_TRUE(socket_data2.at_write_eof()); |
| 1163 | } |
| 1164 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1165 | TEST_P(QuicStreamFactoryTest, OnCACertChanged) { |
[email protected] | d7d1e50b | 2013-11-25 22:08:09 | [diff] [blame] | 1166 | MockRead reads[] = { |
| 1167 | MockRead(ASYNC, 0, 0) // EOF |
| 1168 | }; |
[email protected] | 459a740 | 2014-02-10 12:58:52 | [diff] [blame] | 1169 | scoped_ptr<QuicEncryptedPacket> rst(ConstructRstPacket()); |
| 1170 | std::vector<MockWrite> writes; |
[email protected] | 08da9adb | 2014-04-24 08:33:31 | [diff] [blame] | 1171 | writes.push_back(MockWrite(ASYNC, rst->data(), rst->length(), 1)); |
[email protected] | 459a740 | 2014-02-10 12:58:52 | [diff] [blame] | 1172 | DeterministicSocketData socket_data(reads, arraysize(reads), |
| 1173 | writes.empty() ? NULL : &writes[0], |
| 1174 | writes.size()); |
[email protected] | d7d1e50b | 2013-11-25 22:08:09 | [diff] [blame] | 1175 | socket_factory_.AddSocketDataProvider(&socket_data); |
| 1176 | socket_data.StopAfter(1); |
| 1177 | |
| 1178 | MockRead reads2[] = { |
| 1179 | MockRead(ASYNC, 0, 0) // EOF |
| 1180 | }; |
| 1181 | DeterministicSocketData socket_data2(reads2, arraysize(reads2), NULL, 0); |
| 1182 | socket_factory_.AddSocketDataProvider(&socket_data2); |
| 1183 | socket_data2.StopAfter(1); |
| 1184 | |
| 1185 | QuicStreamRequest request(&factory_); |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 1186 | EXPECT_EQ(ERR_IO_PENDING, |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 1187 | request.Request(host_port_pair_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 1188 | is_https_, |
[email protected] | 9dd3ff0f | 2014-03-26 09:51:28 | [diff] [blame] | 1189 | privacy_mode_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 1190 | "GET", |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 1191 | net_log_, |
| 1192 | callback_.callback())); |
[email protected] | d7d1e50b | 2013-11-25 22:08:09 | [diff] [blame] | 1193 | |
| 1194 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 1195 | scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
| 1196 | HttpRequestInfo request_info; |
| 1197 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, |
| 1198 | DEFAULT_PRIORITY, |
| 1199 | net_log_, CompletionCallback())); |
| 1200 | |
| 1201 | // Change the CA cert and verify that stream saw the event. |
| 1202 | factory_.OnCACertChanged(NULL); |
| 1203 | EXPECT_EQ(ERR_CERT_DATABASE_CHANGED, |
| 1204 | stream->ReadResponseHeaders(callback_.callback())); |
| 1205 | EXPECT_FALSE(factory_.require_confirmation()); |
| 1206 | |
| 1207 | // Now attempting to request a stream to the same origin should create |
| 1208 | // a new session. |
| 1209 | |
| 1210 | QuicStreamRequest request2(&factory_); |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 1211 | EXPECT_EQ(ERR_IO_PENDING, |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 1212 | request2.Request(host_port_pair_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 1213 | is_https_, |
[email protected] | 9dd3ff0f | 2014-03-26 09:51:28 | [diff] [blame] | 1214 | privacy_mode_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 1215 | "GET", |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 1216 | net_log_, |
| 1217 | callback_.callback())); |
[email protected] | d7d1e50b | 2013-11-25 22:08:09 | [diff] [blame] | 1218 | |
| 1219 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 1220 | stream = request2.ReleaseStream(); |
| 1221 | stream.reset(); // Will reset stream 3. |
| 1222 | |
| 1223 | EXPECT_TRUE(socket_data.at_read_eof()); |
| 1224 | EXPECT_TRUE(socket_data.at_write_eof()); |
| 1225 | EXPECT_TRUE(socket_data2.at_read_eof()); |
| 1226 | EXPECT_TRUE(socket_data2.at_write_eof()); |
| 1227 | } |
| 1228 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1229 | TEST_P(QuicStreamFactoryTest, SharedCryptoConfig) { |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 1230 | vector<string> cannoncial_suffixes; |
| 1231 | cannoncial_suffixes.push_back(string(".c.youtube.com")); |
| 1232 | cannoncial_suffixes.push_back(string(".googlevideo.com")); |
[email protected] | c49ff18 | 2013-09-28 08:33:26 | [diff] [blame] | 1233 | |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 1234 | for (unsigned i = 0; i < cannoncial_suffixes.size(); ++i) { |
| 1235 | string r1_host_name("r1"); |
| 1236 | string r2_host_name("r2"); |
| 1237 | r1_host_name.append(cannoncial_suffixes[i]); |
| 1238 | r2_host_name.append(cannoncial_suffixes[i]); |
[email protected] | b70fdb79 | 2013-10-25 19:04:14 | [diff] [blame] | 1239 | |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 1240 | HostPortPair host_port_pair1(r1_host_name, 80); |
[email protected] | 59c0bbd | 2014-03-22 04:08:12 | [diff] [blame] | 1241 | QuicCryptoClientConfig* crypto_config = |
| 1242 | QuicStreamFactoryPeer::GetCryptoConfig(&factory_); |
[email protected] | 257f24f | 2014-04-01 09:15:37 | [diff] [blame] | 1243 | QuicServerId server_id1(host_port_pair1, is_https_, privacy_mode_); |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 1244 | QuicCryptoClientConfig::CachedState* cached1 = |
[email protected] | 257f24f | 2014-04-01 09:15:37 | [diff] [blame] | 1245 | crypto_config->LookupOrCreate(server_id1); |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 1246 | EXPECT_FALSE(cached1->proof_valid()); |
| 1247 | EXPECT_TRUE(cached1->source_address_token().empty()); |
| 1248 | |
| 1249 | // Mutate the cached1 to have different data. |
| 1250 | // TODO(rtenneti): mutate other members of CachedState. |
| 1251 | cached1->set_source_address_token(r1_host_name); |
| 1252 | cached1->SetProofValid(); |
| 1253 | |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 1254 | HostPortPair host_port_pair2(r2_host_name, 80); |
[email protected] | 257f24f | 2014-04-01 09:15:37 | [diff] [blame] | 1255 | QuicServerId server_id2(host_port_pair2, is_https_, privacy_mode_); |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 1256 | QuicCryptoClientConfig::CachedState* cached2 = |
[email protected] | 257f24f | 2014-04-01 09:15:37 | [diff] [blame] | 1257 | crypto_config->LookupOrCreate(server_id2); |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 1258 | EXPECT_EQ(cached1->source_address_token(), cached2->source_address_token()); |
| 1259 | EXPECT_TRUE(cached2->proof_valid()); |
| 1260 | } |
[email protected] | b70fdb79 | 2013-10-25 19:04:14 | [diff] [blame] | 1261 | } |
| 1262 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1263 | TEST_P(QuicStreamFactoryTest, CryptoConfigWhenProofIsInvalid) { |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 1264 | vector<string> cannoncial_suffixes; |
| 1265 | cannoncial_suffixes.push_back(string(".c.youtube.com")); |
| 1266 | cannoncial_suffixes.push_back(string(".googlevideo.com")); |
[email protected] | b70fdb79 | 2013-10-25 19:04:14 | [diff] [blame] | 1267 | |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 1268 | for (unsigned i = 0; i < cannoncial_suffixes.size(); ++i) { |
| 1269 | string r3_host_name("r3"); |
| 1270 | string r4_host_name("r4"); |
| 1271 | r3_host_name.append(cannoncial_suffixes[i]); |
| 1272 | r4_host_name.append(cannoncial_suffixes[i]); |
[email protected] | b70fdb79 | 2013-10-25 19:04:14 | [diff] [blame] | 1273 | |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 1274 | HostPortPair host_port_pair1(r3_host_name, 80); |
[email protected] | 59c0bbd | 2014-03-22 04:08:12 | [diff] [blame] | 1275 | QuicCryptoClientConfig* crypto_config = |
| 1276 | QuicStreamFactoryPeer::GetCryptoConfig(&factory_); |
[email protected] | 257f24f | 2014-04-01 09:15:37 | [diff] [blame] | 1277 | QuicServerId server_id1(host_port_pair1, is_https_, privacy_mode_); |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 1278 | QuicCryptoClientConfig::CachedState* cached1 = |
[email protected] | 257f24f | 2014-04-01 09:15:37 | [diff] [blame] | 1279 | crypto_config->LookupOrCreate(server_id1); |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 1280 | EXPECT_FALSE(cached1->proof_valid()); |
| 1281 | EXPECT_TRUE(cached1->source_address_token().empty()); |
| 1282 | |
| 1283 | // Mutate the cached1 to have different data. |
| 1284 | // TODO(rtenneti): mutate other members of CachedState. |
| 1285 | cached1->set_source_address_token(r3_host_name); |
| 1286 | cached1->SetProofInvalid(); |
| 1287 | |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 1288 | HostPortPair host_port_pair2(r4_host_name, 80); |
[email protected] | 257f24f | 2014-04-01 09:15:37 | [diff] [blame] | 1289 | QuicServerId server_id2(host_port_pair2, is_https_, privacy_mode_); |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 1290 | QuicCryptoClientConfig::CachedState* cached2 = |
[email protected] | 257f24f | 2014-04-01 09:15:37 | [diff] [blame] | 1291 | crypto_config->LookupOrCreate(server_id2); |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 1292 | EXPECT_NE(cached1->source_address_token(), cached2->source_address_token()); |
| 1293 | EXPECT_TRUE(cached2->source_address_token().empty()); |
| 1294 | EXPECT_FALSE(cached2->proof_valid()); |
| 1295 | } |
[email protected] | c49ff18 | 2013-09-28 08:33:26 | [diff] [blame] | 1296 | } |
| 1297 | |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 1298 | } // namespace test |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 1299 | } // namespace net |