| 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/chromium/quic_stream_factory.h" | 5 #include "net/quic/chromium/quic_stream_factory.h" |
| 6 | 6 |
| 7 #include <ostream> | 7 #include <ostream> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 threshold_timeouts_with_open_streams_(2), | 318 threshold_timeouts_with_open_streams_(2), |
| 319 threshold_public_resets_post_handshake_(2), | 319 threshold_public_resets_post_handshake_(2), |
| 320 receive_buffer_size_(0), | 320 receive_buffer_size_(0), |
| 321 delay_tcp_race_(true), | 321 delay_tcp_race_(true), |
| 322 close_sessions_on_ip_change_(false), | 322 close_sessions_on_ip_change_(false), |
| 323 disable_quic_on_timeout_with_open_streams_(false), | 323 disable_quic_on_timeout_with_open_streams_(false), |
| 324 idle_connection_timeout_seconds_(kIdleConnectionTimeoutSeconds), | 324 idle_connection_timeout_seconds_(kIdleConnectionTimeoutSeconds), |
| 325 migrate_sessions_on_network_change_(false), | 325 migrate_sessions_on_network_change_(false), |
| 326 migrate_sessions_early_(false), | 326 migrate_sessions_early_(false), |
| 327 allow_server_migration_(false), | 327 allow_server_migration_(false), |
| 328 force_hol_blocking_(false), | 328 force_hol_blocking_(false) { |
| 329 race_cert_verification_(false) { | |
| 330 clock_->AdvanceTime(QuicTime::Delta::FromSeconds(1)); | 329 clock_->AdvanceTime(QuicTime::Delta::FromSeconds(1)); |
| 331 } | 330 } |
| 332 | 331 |
| 333 ~QuicStreamFactoryTestBase() { | 332 ~QuicStreamFactoryTestBase() { |
| 334 // If |factory_| was initialized, then it took over ownership of |clock_|. | 333 // If |factory_| was initialized, then it took over ownership of |clock_|. |
| 335 // If |factory_| was not initialized, then |clock_| needs to be destroyed. | 334 // If |factory_| was not initialized, then |clock_| needs to be destroyed. |
| 336 if (!factory_) | 335 if (!factory_) { |
| 337 delete clock_; | 336 delete clock_; |
| 337 } |
| 338 } | 338 } |
| 339 | 339 |
| 340 void Initialize() { | 340 void Initialize() { |
| 341 DCHECK(!factory_); | 341 DCHECK(!factory_); |
| 342 factory_.reset(new QuicStreamFactory( | 342 factory_.reset(new QuicStreamFactory( |
| 343 net_log_.net_log(), &host_resolver_, ssl_config_service_.get(), | 343 net_log_.net_log(), &host_resolver_, ssl_config_service_.get(), |
| 344 &socket_factory_, &http_server_properties_, cert_verifier_.get(), | 344 &socket_factory_, &http_server_properties_, cert_verifier_.get(), |
| 345 &ct_policy_enforcer_, channel_id_service_.get(), | 345 &ct_policy_enforcer_, channel_id_service_.get(), |
| 346 &transport_security_state_, cert_transparency_verifier_.get(), | 346 &transport_security_state_, cert_transparency_verifier_.get(), |
| 347 /*SocketPerformanceWatcherFactory*/ nullptr, | 347 /*SocketPerformanceWatcherFactory*/ nullptr, |
| 348 &crypto_client_stream_factory_, &random_generator_, clock_, | 348 &crypto_client_stream_factory_, &random_generator_, clock_, |
| 349 kDefaultMaxPacketSize, string(), SupportedVersions(version_), | 349 kDefaultMaxPacketSize, string(), SupportedVersions(version_), |
| 350 enable_port_selection_, always_require_handshake_confirmation_, | 350 enable_port_selection_, always_require_handshake_confirmation_, |
| 351 disable_connection_pooling_, load_server_info_timeout_srtt_multiplier_, | 351 disable_connection_pooling_, load_server_info_timeout_srtt_multiplier_, |
| 352 enable_connection_racing_, enable_non_blocking_io_, disable_disk_cache_, | 352 enable_connection_racing_, enable_non_blocking_io_, disable_disk_cache_, |
| 353 prefer_aes_, max_number_of_lossy_connections_, packet_loss_threshold_, | 353 prefer_aes_, max_number_of_lossy_connections_, packet_loss_threshold_, |
| 354 max_disabled_reasons_, threshold_timeouts_with_open_streams_, | 354 max_disabled_reasons_, threshold_timeouts_with_open_streams_, |
| 355 threshold_public_resets_post_handshake_, receive_buffer_size_, | 355 threshold_public_resets_post_handshake_, receive_buffer_size_, |
| 356 delay_tcp_race_, /*max_server_configs_stored_in_properties*/ 0, | 356 delay_tcp_race_, /*max_server_configs_stored_in_properties*/ 0, |
| 357 close_sessions_on_ip_change_, | 357 close_sessions_on_ip_change_, |
| 358 disable_quic_on_timeout_with_open_streams_, | 358 disable_quic_on_timeout_with_open_streams_, |
| 359 idle_connection_timeout_seconds_, migrate_sessions_on_network_change_, | 359 idle_connection_timeout_seconds_, migrate_sessions_on_network_change_, |
| 360 migrate_sessions_early_, allow_server_migration_, force_hol_blocking_, | 360 migrate_sessions_early_, allow_server_migration_, force_hol_blocking_, |
| 361 race_cert_verification_, QuicTagVector(), | 361 QuicTagVector(), /*enable_token_binding*/ false)); |
| 362 /*enable_token_binding*/ false)); | |
| 363 factory_->set_require_confirmation(false); | 362 factory_->set_require_confirmation(false); |
| 364 EXPECT_FALSE(factory_->has_quic_server_info_factory()); | 363 EXPECT_FALSE(factory_->has_quic_server_info_factory()); |
| 365 factory_->set_quic_server_info_factory(new MockQuicServerInfoFactory()); | 364 factory_->set_quic_server_info_factory(new MockQuicServerInfoFactory()); |
| 366 EXPECT_TRUE(factory_->has_quic_server_info_factory()); | 365 EXPECT_TRUE(factory_->has_quic_server_info_factory()); |
| 367 } | 366 } |
| 368 | 367 |
| 369 void InitializeConnectionMigrationTest( | 368 void InitializeConnectionMigrationTest( |
| 370 NetworkChangeNotifier::NetworkList connected_networks) { | 369 NetworkChangeNotifier::NetworkList connected_networks) { |
| 371 scoped_mock_network_change_notifier_.reset( | 370 scoped_mock_network_change_notifier_.reset( |
| 372 new ScopedMockNetworkChangeNotifier()); | 371 new ScopedMockNetworkChangeNotifier()); |
| 373 MockNetworkChangeNotifier* mock_ncn = | 372 MockNetworkChangeNotifier* mock_ncn = |
| 374 scoped_mock_network_change_notifier_->mock_network_change_notifier(); | 373 scoped_mock_network_change_notifier_->mock_network_change_notifier(); |
| 375 mock_ncn->ForceNetworkHandlesSupported(); | 374 mock_ncn->ForceNetworkHandlesSupported(); |
| 376 mock_ncn->SetConnectedNetworksList(connected_networks); | 375 mock_ncn->SetConnectedNetworksList(connected_networks); |
| 377 migrate_sessions_on_network_change_ = true; | 376 migrate_sessions_on_network_change_ = true; |
| 378 migrate_sessions_early_ = true; | 377 migrate_sessions_early_ = true; |
| 379 Initialize(); | 378 Initialize(); |
| 380 } | 379 } |
| 381 | 380 |
| 382 bool HasActiveSession(const HostPortPair& host_port_pair) { | 381 bool HasActiveSession(const HostPortPair& host_port_pair) { |
| 383 QuicServerId server_id(host_port_pair, PRIVACY_MODE_DISABLED); | 382 QuicServerId server_id(host_port_pair, PRIVACY_MODE_DISABLED); |
| 384 return QuicStreamFactoryPeer::HasActiveSession(factory_.get(), server_id); | 383 return QuicStreamFactoryPeer::HasActiveSession(factory_.get(), server_id); |
| 385 } | 384 } |
| 386 | 385 |
| 387 bool HasActiveCertVerifierJob(const QuicServerId& server_id) { | |
| 388 return QuicStreamFactoryPeer::HasActiveCertVerifierJob(factory_.get(), | |
| 389 server_id); | |
| 390 } | |
| 391 | |
| 392 QuicChromiumClientSession* GetActiveSession( | 386 QuicChromiumClientSession* GetActiveSession( |
| 393 const HostPortPair& host_port_pair) { | 387 const HostPortPair& host_port_pair) { |
| 394 QuicServerId server_id(host_port_pair, PRIVACY_MODE_DISABLED); | 388 QuicServerId server_id(host_port_pair, PRIVACY_MODE_DISABLED); |
| 395 return QuicStreamFactoryPeer::GetActiveSession(factory_.get(), server_id); | 389 return QuicStreamFactoryPeer::GetActiveSession(factory_.get(), server_id); |
| 396 } | 390 } |
| 397 | 391 |
| 398 std::unique_ptr<QuicHttpStream> CreateFromSession( | 392 std::unique_ptr<QuicHttpStream> CreateFromSession( |
| 399 const HostPortPair& host_port_pair) { | 393 const HostPortPair& host_port_pair) { |
| 400 QuicChromiumClientSession* session = GetActiveSession(host_port_pair); | 394 QuicChromiumClientSession* session = GetActiveSession(host_port_pair); |
| 401 return QuicStreamFactoryPeer::CreateFromSession(factory_.get(), session); | 395 return QuicStreamFactoryPeer::CreateFromSession(factory_.get(), session); |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 551 int threshold_public_resets_post_handshake_; | 545 int threshold_public_resets_post_handshake_; |
| 552 int receive_buffer_size_; | 546 int receive_buffer_size_; |
| 553 bool delay_tcp_race_; | 547 bool delay_tcp_race_; |
| 554 bool close_sessions_on_ip_change_; | 548 bool close_sessions_on_ip_change_; |
| 555 bool disable_quic_on_timeout_with_open_streams_; | 549 bool disable_quic_on_timeout_with_open_streams_; |
| 556 int idle_connection_timeout_seconds_; | 550 int idle_connection_timeout_seconds_; |
| 557 bool migrate_sessions_on_network_change_; | 551 bool migrate_sessions_on_network_change_; |
| 558 bool migrate_sessions_early_; | 552 bool migrate_sessions_early_; |
| 559 bool allow_server_migration_; | 553 bool allow_server_migration_; |
| 560 bool force_hol_blocking_; | 554 bool force_hol_blocking_; |
| 561 bool race_cert_verification_; | |
| 562 }; | 555 }; |
| 563 | 556 |
| 564 class QuicStreamFactoryTest : public QuicStreamFactoryTestBase, | 557 class QuicStreamFactoryTest : public QuicStreamFactoryTestBase, |
| 565 public ::testing::TestWithParam<TestParams> { | 558 public ::testing::TestWithParam<TestParams> { |
| 566 protected: | 559 protected: |
| 567 QuicStreamFactoryTest() | 560 QuicStreamFactoryTest() |
| 568 : QuicStreamFactoryTestBase(GetParam().version, | 561 : QuicStreamFactoryTestBase(GetParam().version, |
| 569 GetParam().enable_connection_racing) {} | 562 GetParam().enable_connection_racing) {} |
| 570 }; | 563 }; |
| 571 | 564 |
| (...skipping 3866 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4438 EXPECT_TRUE(cached2->GetServerConfig()); | 4431 EXPECT_TRUE(cached2->GetServerConfig()); |
| 4439 EXPECT_EQ(server_config2, cached2->server_config()); | 4432 EXPECT_EQ(server_config2, cached2->server_config()); |
| 4440 EXPECT_EQ(source_address_token2, cached2->source_address_token()); | 4433 EXPECT_EQ(source_address_token2, cached2->source_address_token()); |
| 4441 EXPECT_EQ(cert_sct2, cached2->cert_sct()); | 4434 EXPECT_EQ(cert_sct2, cached2->cert_sct()); |
| 4442 EXPECT_EQ(chlo_hash2, cached2->chlo_hash()); | 4435 EXPECT_EQ(chlo_hash2, cached2->chlo_hash()); |
| 4443 EXPECT_EQ(signature2, cached2->signature()); | 4436 EXPECT_EQ(signature2, cached2->signature()); |
| 4444 ASSERT_EQ(1U, cached->certs().size()); | 4437 ASSERT_EQ(1U, cached->certs().size()); |
| 4445 EXPECT_EQ(test_cert2, cached2->certs()[0]); | 4438 EXPECT_EQ(test_cert2, cached2->certs()[0]); |
| 4446 } | 4439 } |
| 4447 | 4440 |
| 4448 TEST_P(QuicStreamFactoryTest, StartCertVerifyJob) { | |
| 4449 Initialize(); | |
| 4450 | |
| 4451 MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; | |
| 4452 SequencedSocketData socket_data(reads, arraysize(reads), nullptr, 0); | |
| 4453 socket_factory_.AddSocketDataProvider(&socket_data); | |
| 4454 | |
| 4455 // Save current state of |race_cert_verification|. | |
| 4456 bool race_cert_verification = | |
| 4457 QuicStreamFactoryPeer::GetRaceCertVerification(factory_.get()); | |
| 4458 | |
| 4459 // Load server config. | |
| 4460 HostPortPair host_port_pair(kDefaultServerHostName, kDefaultServerPort); | |
| 4461 QuicServerId quic_server_id(host_port_pair_, privacy_mode_); | |
| 4462 QuicStreamFactoryPeer::CacheDummyServerConfig(factory_.get(), quic_server_id); | |
| 4463 | |
| 4464 QuicStreamFactoryPeer::SetRaceCertVerification(factory_.get(), true); | |
| 4465 EXPECT_FALSE(HasActiveCertVerifierJob(quic_server_id)); | |
| 4466 | |
| 4467 // Start CertVerifyJob. | |
| 4468 QuicAsyncStatus status = QuicStreamFactoryPeer::StartCertVerifyJob( | |
| 4469 factory_.get(), quic_server_id, /*cert_verify_flags=*/0, net_log_); | |
| 4470 if (status == QUIC_PENDING) { | |
| 4471 // Verify CertVerifierJob has started. | |
| 4472 EXPECT_TRUE(HasActiveCertVerifierJob(quic_server_id)); | |
| 4473 | |
| 4474 while (HasActiveCertVerifierJob(quic_server_id)) { | |
| 4475 base::RunLoop().RunUntilIdle(); | |
| 4476 } | |
| 4477 } | |
| 4478 // Verify CertVerifierJob has finished. | |
| 4479 EXPECT_FALSE(HasActiveCertVerifierJob(quic_server_id)); | |
| 4480 | |
| 4481 // Start a QUIC request. | |
| 4482 QuicStreamRequest request(factory_.get()); | |
| 4483 EXPECT_EQ(ERR_IO_PENDING, | |
| 4484 request.Request(host_port_pair_, privacy_mode_, | |
| 4485 /*cert_verify_flags=*/0, url_, "GET", net_log_, | |
| 4486 callback_.callback())); | |
| 4487 | |
| 4488 EXPECT_EQ(OK, callback_.WaitForResult()); | |
| 4489 | |
| 4490 std::unique_ptr<QuicHttpStream> stream = request.CreateStream(); | |
| 4491 EXPECT_TRUE(stream.get()); | |
| 4492 | |
| 4493 // Restore |race_cert_verification|. | |
| 4494 QuicStreamFactoryPeer::SetRaceCertVerification(factory_.get(), | |
| 4495 race_cert_verification); | |
| 4496 | |
| 4497 EXPECT_TRUE(socket_data.AllReadDataConsumed()); | |
| 4498 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); | |
| 4499 | |
| 4500 // Verify there are no outstanding CertVerifierJobs after request has | |
| 4501 // finished. | |
| 4502 EXPECT_FALSE(HasActiveCertVerifierJob(quic_server_id)); | |
| 4503 } | |
| 4504 | |
| 4505 TEST_P(QuicStreamFactoryTest, QuicDoingZeroRTT) { | 4441 TEST_P(QuicStreamFactoryTest, QuicDoingZeroRTT) { |
| 4506 Initialize(); | 4442 Initialize(); |
| 4507 | 4443 |
| 4508 factory_->set_require_confirmation(true); | 4444 factory_->set_require_confirmation(true); |
| 4509 QuicServerId quic_server_id(host_port_pair_, PRIVACY_MODE_DISABLED); | 4445 QuicServerId quic_server_id(host_port_pair_, PRIVACY_MODE_DISABLED); |
| 4510 EXPECT_FALSE(factory_->ZeroRTTEnabledFor(quic_server_id)); | 4446 EXPECT_FALSE(factory_->ZeroRTTEnabledFor(quic_server_id)); |
| 4511 | 4447 |
| 4512 factory_->set_require_confirmation(false); | 4448 factory_->set_require_confirmation(false); |
| 4513 EXPECT_FALSE(factory_->ZeroRTTEnabledFor(quic_server_id)); | 4449 EXPECT_FALSE(factory_->ZeroRTTEnabledFor(quic_server_id)); |
| 4514 | 4450 |
| (...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5117 // Clear all cached states. | 5053 // Clear all cached states. |
| 5118 factory_->ClearCachedStatesInCryptoConfig( | 5054 factory_->ClearCachedStatesInCryptoConfig( |
| 5119 base::Callback<bool(const GURL&)>()); | 5055 base::Callback<bool(const GURL&)>()); |
| 5120 EXPECT_TRUE(test_cases[0].state->certs().empty()); | 5056 EXPECT_TRUE(test_cases[0].state->certs().empty()); |
| 5121 EXPECT_TRUE(test_cases[1].state->certs().empty()); | 5057 EXPECT_TRUE(test_cases[1].state->certs().empty()); |
| 5122 EXPECT_TRUE(test_cases[2].state->certs().empty()); | 5058 EXPECT_TRUE(test_cases[2].state->certs().empty()); |
| 5123 } | 5059 } |
| 5124 | 5060 |
| 5125 } // namespace test | 5061 } // namespace test |
| 5126 } // namespace net | 5062 } // namespace net |
| OLD | NEW |