OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/quic/quic_stream_factory.h" | 5 #include "net/quic/quic_stream_factory.h" |
6 | 6 |
7 #include <ostream> | 7 #include <ostream> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 packet_loss_threshold_(1.0f), | 313 packet_loss_threshold_(1.0f), |
314 max_disabled_reasons_(3), | 314 max_disabled_reasons_(3), |
315 threshold_timeouts_with_open_streams_(2), | 315 threshold_timeouts_with_open_streams_(2), |
316 threshold_public_resets_post_handshake_(2), | 316 threshold_public_resets_post_handshake_(2), |
317 receive_buffer_size_(0), | 317 receive_buffer_size_(0), |
318 delay_tcp_race_(true), | 318 delay_tcp_race_(true), |
319 close_sessions_on_ip_change_(false), | 319 close_sessions_on_ip_change_(false), |
320 disable_quic_on_timeout_with_open_streams_(false), | 320 disable_quic_on_timeout_with_open_streams_(false), |
321 idle_connection_timeout_seconds_(kIdleConnectionTimeoutSeconds), | 321 idle_connection_timeout_seconds_(kIdleConnectionTimeoutSeconds), |
322 migrate_sessions_on_network_change_(false), | 322 migrate_sessions_on_network_change_(false), |
323 migrate_sessions_early_(false) { | 323 migrate_sessions_early_(false), |
| 324 race_cert_verification_(false) { |
324 clock_->AdvanceTime(QuicTime::Delta::FromSeconds(1)); | 325 clock_->AdvanceTime(QuicTime::Delta::FromSeconds(1)); |
325 } | 326 } |
326 | 327 |
327 ~QuicStreamFactoryTestBase() { | 328 ~QuicStreamFactoryTestBase() { |
328 // If |factory_| was initialized, then it took over ownership of |clock_|. | 329 // If |factory_| was initialized, then it took over ownership of |clock_|. |
329 // If |factory_| was not initialized, then |clock_| needs to be destroyed. | 330 // If |factory_| was not initialized, then |clock_| needs to be destroyed. |
330 if (!factory_) { | 331 if (!factory_) |
331 delete clock_; | 332 delete clock_; |
332 } | |
333 } | 333 } |
334 | 334 |
335 void Initialize() { | 335 void Initialize() { |
336 DCHECK(!factory_); | 336 DCHECK(!factory_); |
337 factory_.reset(new QuicStreamFactory( | 337 factory_.reset(new QuicStreamFactory( |
338 net_log_.net_log(), &host_resolver_, ssl_config_service_.get(), | 338 net_log_.net_log(), &host_resolver_, ssl_config_service_.get(), |
339 &socket_factory_, &http_server_properties_, cert_verifier_.get(), | 339 &socket_factory_, &http_server_properties_, cert_verifier_.get(), |
340 &ct_policy_enforcer_, channel_id_service_.get(), | 340 &ct_policy_enforcer_, channel_id_service_.get(), |
341 &transport_security_state_, cert_transparency_verifier_.get(), | 341 &transport_security_state_, cert_transparency_verifier_.get(), |
342 /*SocketPerformanceWatcherFactory*/ nullptr, | 342 /*SocketPerformanceWatcherFactory*/ nullptr, |
343 &crypto_client_stream_factory_, &random_generator_, clock_, | 343 &crypto_client_stream_factory_, &random_generator_, clock_, |
344 kDefaultMaxPacketSize, string(), SupportedVersions(version_), | 344 kDefaultMaxPacketSize, string(), SupportedVersions(version_), |
345 enable_port_selection_, always_require_handshake_confirmation_, | 345 enable_port_selection_, always_require_handshake_confirmation_, |
346 disable_connection_pooling_, load_server_info_timeout_srtt_multiplier_, | 346 disable_connection_pooling_, load_server_info_timeout_srtt_multiplier_, |
347 enable_connection_racing_, enable_non_blocking_io_, disable_disk_cache_, | 347 enable_connection_racing_, enable_non_blocking_io_, disable_disk_cache_, |
348 prefer_aes_, max_number_of_lossy_connections_, packet_loss_threshold_, | 348 prefer_aes_, max_number_of_lossy_connections_, packet_loss_threshold_, |
349 max_disabled_reasons_, threshold_timeouts_with_open_streams_, | 349 max_disabled_reasons_, threshold_timeouts_with_open_streams_, |
350 threshold_public_resets_post_handshake_, receive_buffer_size_, | 350 threshold_public_resets_post_handshake_, receive_buffer_size_, |
351 delay_tcp_race_, /*max_server_configs_stored_in_properties*/ 0, | 351 delay_tcp_race_, /*max_server_configs_stored_in_properties*/ 0, |
352 close_sessions_on_ip_change_, | 352 close_sessions_on_ip_change_, |
353 disable_quic_on_timeout_with_open_streams_, | 353 disable_quic_on_timeout_with_open_streams_, |
354 idle_connection_timeout_seconds_, migrate_sessions_on_network_change_, | 354 idle_connection_timeout_seconds_, migrate_sessions_on_network_change_, |
355 migrate_sessions_early_, QuicTagVector(), | 355 migrate_sessions_early_, race_cert_verification_, QuicTagVector(), |
356 /*enable_token_binding*/ false)); | 356 /*enable_token_binding*/ false)); |
357 factory_->set_require_confirmation(false); | 357 factory_->set_require_confirmation(false); |
358 EXPECT_FALSE(factory_->has_quic_server_info_factory()); | 358 EXPECT_FALSE(factory_->has_quic_server_info_factory()); |
359 factory_->set_quic_server_info_factory(new MockQuicServerInfoFactory()); | 359 factory_->set_quic_server_info_factory(new MockQuicServerInfoFactory()); |
360 EXPECT_TRUE(factory_->has_quic_server_info_factory()); | 360 EXPECT_TRUE(factory_->has_quic_server_info_factory()); |
361 } | 361 } |
362 | 362 |
363 void InitializeConnectionMigrationTest( | 363 void InitializeConnectionMigrationTest( |
364 NetworkChangeNotifier::NetworkList connected_networks) { | 364 NetworkChangeNotifier::NetworkList connected_networks) { |
365 scoped_mock_network_change_notifier_.reset( | 365 scoped_mock_network_change_notifier_.reset( |
366 new ScopedMockNetworkChangeNotifier()); | 366 new ScopedMockNetworkChangeNotifier()); |
367 MockNetworkChangeNotifier* mock_ncn = | 367 MockNetworkChangeNotifier* mock_ncn = |
368 scoped_mock_network_change_notifier_->mock_network_change_notifier(); | 368 scoped_mock_network_change_notifier_->mock_network_change_notifier(); |
369 mock_ncn->ForceNetworkHandlesSupported(); | 369 mock_ncn->ForceNetworkHandlesSupported(); |
370 mock_ncn->SetConnectedNetworksList(connected_networks); | 370 mock_ncn->SetConnectedNetworksList(connected_networks); |
371 migrate_sessions_on_network_change_ = true; | 371 migrate_sessions_on_network_change_ = true; |
372 migrate_sessions_early_ = true; | 372 migrate_sessions_early_ = true; |
373 Initialize(); | 373 Initialize(); |
374 } | 374 } |
375 | 375 |
376 bool HasActiveSession(const HostPortPair& host_port_pair) { | 376 bool HasActiveSession(const HostPortPair& host_port_pair) { |
377 QuicServerId server_id(host_port_pair, PRIVACY_MODE_DISABLED); | 377 QuicServerId server_id(host_port_pair, PRIVACY_MODE_DISABLED); |
378 return QuicStreamFactoryPeer::HasActiveSession(factory_.get(), server_id); | 378 return QuicStreamFactoryPeer::HasActiveSession(factory_.get(), server_id); |
379 } | 379 } |
380 | 380 |
| 381 bool HasActiveCertVerifierJob(const QuicServerId& server_id) { |
| 382 return QuicStreamFactoryPeer::HasActiveCertVerifierJob(factory_.get(), |
| 383 server_id); |
| 384 } |
| 385 |
381 QuicChromiumClientSession* GetActiveSession( | 386 QuicChromiumClientSession* GetActiveSession( |
382 const HostPortPair& host_port_pair) { | 387 const HostPortPair& host_port_pair) { |
383 QuicServerId server_id(host_port_pair, PRIVACY_MODE_DISABLED); | 388 QuicServerId server_id(host_port_pair, PRIVACY_MODE_DISABLED); |
384 return QuicStreamFactoryPeer::GetActiveSession(factory_.get(), server_id); | 389 return QuicStreamFactoryPeer::GetActiveSession(factory_.get(), server_id); |
385 } | 390 } |
386 | 391 |
387 std::unique_ptr<QuicHttpStream> CreateFromSession( | 392 std::unique_ptr<QuicHttpStream> CreateFromSession( |
388 const HostPortPair& host_port_pair) { | 393 const HostPortPair& host_port_pair) { |
389 QuicChromiumClientSession* session = GetActiveSession(host_port_pair); | 394 QuicChromiumClientSession* session = GetActiveSession(host_port_pair); |
390 return QuicStreamFactoryPeer::CreateFromSession(factory_.get(), session); | 395 return QuicStreamFactoryPeer::CreateFromSession(factory_.get(), session); |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
538 int max_disabled_reasons_; | 543 int max_disabled_reasons_; |
539 int threshold_timeouts_with_open_streams_; | 544 int threshold_timeouts_with_open_streams_; |
540 int threshold_public_resets_post_handshake_; | 545 int threshold_public_resets_post_handshake_; |
541 int receive_buffer_size_; | 546 int receive_buffer_size_; |
542 bool delay_tcp_race_; | 547 bool delay_tcp_race_; |
543 bool close_sessions_on_ip_change_; | 548 bool close_sessions_on_ip_change_; |
544 bool disable_quic_on_timeout_with_open_streams_; | 549 bool disable_quic_on_timeout_with_open_streams_; |
545 int idle_connection_timeout_seconds_; | 550 int idle_connection_timeout_seconds_; |
546 bool migrate_sessions_on_network_change_; | 551 bool migrate_sessions_on_network_change_; |
547 bool migrate_sessions_early_; | 552 bool migrate_sessions_early_; |
| 553 bool race_cert_verification_; |
548 }; | 554 }; |
549 | 555 |
550 class QuicStreamFactoryTest : public QuicStreamFactoryTestBase, | 556 class QuicStreamFactoryTest : public QuicStreamFactoryTestBase, |
551 public ::testing::TestWithParam<TestParams> { | 557 public ::testing::TestWithParam<TestParams> { |
552 protected: | 558 protected: |
553 QuicStreamFactoryTest() | 559 QuicStreamFactoryTest() |
554 : QuicStreamFactoryTestBase(GetParam().version, | 560 : QuicStreamFactoryTestBase(GetParam().version, |
555 GetParam().enable_connection_racing) {} | 561 GetParam().enable_connection_racing) {} |
556 }; | 562 }; |
557 | 563 |
(...skipping 3569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4127 EXPECT_TRUE(cached2->GetServerConfig()); | 4133 EXPECT_TRUE(cached2->GetServerConfig()); |
4128 EXPECT_EQ(server_config2, cached2->server_config()); | 4134 EXPECT_EQ(server_config2, cached2->server_config()); |
4129 EXPECT_EQ(source_address_token2, cached2->source_address_token()); | 4135 EXPECT_EQ(source_address_token2, cached2->source_address_token()); |
4130 EXPECT_EQ(cert_sct2, cached2->cert_sct()); | 4136 EXPECT_EQ(cert_sct2, cached2->cert_sct()); |
4131 EXPECT_EQ(chlo_hash2, cached2->chlo_hash()); | 4137 EXPECT_EQ(chlo_hash2, cached2->chlo_hash()); |
4132 EXPECT_EQ(signature2, cached2->signature()); | 4138 EXPECT_EQ(signature2, cached2->signature()); |
4133 ASSERT_EQ(1U, cached->certs().size()); | 4139 ASSERT_EQ(1U, cached->certs().size()); |
4134 EXPECT_EQ(test_cert2, cached2->certs()[0]); | 4140 EXPECT_EQ(test_cert2, cached2->certs()[0]); |
4135 } | 4141 } |
4136 | 4142 |
| 4143 TEST_P(QuicStreamFactoryTest, StartCertVerifyJob) { |
| 4144 Initialize(); |
| 4145 |
| 4146 MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; |
| 4147 SequencedSocketData socket_data(reads, arraysize(reads), nullptr, 0); |
| 4148 socket_factory_.AddSocketDataProvider(&socket_data); |
| 4149 |
| 4150 // Save current state of |race_cert_verification|. |
| 4151 bool race_cert_verification = |
| 4152 QuicStreamFactoryPeer::GetRaceCertVerification(factory_.get()); |
| 4153 |
| 4154 // Load server config. |
| 4155 HostPortPair host_port_pair("test.example.com", kDefaultServerPort); |
| 4156 QuicServerId quic_server_id(host_port_pair_, privacy_mode_); |
| 4157 QuicStreamFactoryPeer::CacheDummyServerConfig(factory_.get(), quic_server_id); |
| 4158 |
| 4159 QuicStreamFactoryPeer::SetRaceCertVerification(factory_.get(), true); |
| 4160 |
| 4161 // Start CertVerifyJob. |
| 4162 QuicAsyncStatus status = QuicStreamFactoryPeer::StartCertVerifyJob( |
| 4163 factory_.get(), quic_server_id, /*cert_verify_flags=*/0, net_log_); |
| 4164 EXPECT_NE(QUIC_FAILURE, status); |
| 4165 |
| 4166 if (status == QUIC_PENDING) { |
| 4167 // Verify CertVerifierJob has started. |
| 4168 EXPECT_TRUE(HasActiveCertVerifierJob(quic_server_id)); |
| 4169 |
| 4170 while (HasActiveCertVerifierJob(quic_server_id)) { |
| 4171 base::RunLoop().RunUntilIdle(); |
| 4172 } |
| 4173 } |
| 4174 // Verify CertVerifierJob has finished. |
| 4175 EXPECT_FALSE(HasActiveCertVerifierJob(quic_server_id)); |
| 4176 |
| 4177 // Start a QUIC request. |
| 4178 QuicStreamRequest request(factory_.get()); |
| 4179 EXPECT_EQ(ERR_IO_PENDING, |
| 4180 request.Request(host_port_pair_, privacy_mode_, |
| 4181 /*cert_verify_flags=*/0, url_, "GET", net_log_, |
| 4182 callback_.callback())); |
| 4183 |
| 4184 EXPECT_EQ(OK, callback_.WaitForResult()); |
| 4185 |
| 4186 std::unique_ptr<QuicHttpStream> stream = request.CreateStream(); |
| 4187 EXPECT_TRUE(stream.get()); |
| 4188 |
| 4189 // Restore |race_cert_verification|. |
| 4190 QuicStreamFactoryPeer::SetRaceCertVerification(factory_.get(), |
| 4191 race_cert_verification); |
| 4192 |
| 4193 EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 4194 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 4195 |
| 4196 // Verify there are no outstanding CertVerifierJobs after request has |
| 4197 // finished. |
| 4198 EXPECT_FALSE(HasActiveCertVerifierJob(quic_server_id)); |
| 4199 } |
| 4200 |
4137 TEST_P(QuicStreamFactoryTest, QuicDoingZeroRTT) { | 4201 TEST_P(QuicStreamFactoryTest, QuicDoingZeroRTT) { |
4138 Initialize(); | 4202 Initialize(); |
4139 | 4203 |
4140 factory_->set_require_confirmation(true); | 4204 factory_->set_require_confirmation(true); |
4141 QuicServerId quic_server_id(host_port_pair_, PRIVACY_MODE_DISABLED); | 4205 QuicServerId quic_server_id(host_port_pair_, PRIVACY_MODE_DISABLED); |
4142 EXPECT_FALSE(factory_->ZeroRTTEnabledFor(quic_server_id)); | 4206 EXPECT_FALSE(factory_->ZeroRTTEnabledFor(quic_server_id)); |
4143 | 4207 |
4144 factory_->set_require_confirmation(false); | 4208 factory_->set_require_confirmation(false); |
4145 EXPECT_FALSE(factory_->ZeroRTTEnabledFor(quic_server_id)); | 4209 EXPECT_FALSE(factory_->ZeroRTTEnabledFor(quic_server_id)); |
4146 | 4210 |
(...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4675 EXPECT_NE(session1, session2); | 4739 EXPECT_NE(session1, session2); |
4676 | 4740 |
4677 EXPECT_EQ(QuicServerId(origin1_, privacy_mode_), session1->server_id()); | 4741 EXPECT_EQ(QuicServerId(origin1_, privacy_mode_), session1->server_id()); |
4678 EXPECT_EQ(QuicServerId(origin2_, privacy_mode_), session2->server_id()); | 4742 EXPECT_EQ(QuicServerId(origin2_, privacy_mode_), session2->server_id()); |
4679 | 4743 |
4680 EXPECT_TRUE(AllDataConsumed()); | 4744 EXPECT_TRUE(AllDataConsumed()); |
4681 } | 4745 } |
4682 | 4746 |
4683 } // namespace test | 4747 } // namespace test |
4684 } // namespace net | 4748 } // namespace net |
OLD | NEW |