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/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 allow_server_migration_(false), | 324 allow_server_migration_(false), |
325 force_hol_blocking_(false) { | 325 force_hol_blocking_(false), |
| 326 race_cert_verification_(false) { |
326 clock_->AdvanceTime(QuicTime::Delta::FromSeconds(1)); | 327 clock_->AdvanceTime(QuicTime::Delta::FromSeconds(1)); |
327 } | 328 } |
328 | 329 |
329 ~QuicStreamFactoryTestBase() { | 330 ~QuicStreamFactoryTestBase() { |
330 // If |factory_| was initialized, then it took over ownership of |clock_|. | 331 // If |factory_| was initialized, then it took over ownership of |clock_|. |
331 // If |factory_| was not initialized, then |clock_| needs to be destroyed. | 332 // If |factory_| was not initialized, then |clock_| needs to be destroyed. |
332 if (!factory_) { | 333 if (!factory_) |
333 delete clock_; | 334 delete clock_; |
334 } | |
335 } | 335 } |
336 | 336 |
337 void Initialize() { | 337 void Initialize() { |
338 DCHECK(!factory_); | 338 DCHECK(!factory_); |
339 factory_.reset(new QuicStreamFactory( | 339 factory_.reset(new QuicStreamFactory( |
340 net_log_.net_log(), &host_resolver_, ssl_config_service_.get(), | 340 net_log_.net_log(), &host_resolver_, ssl_config_service_.get(), |
341 &socket_factory_, &http_server_properties_, cert_verifier_.get(), | 341 &socket_factory_, &http_server_properties_, cert_verifier_.get(), |
342 &ct_policy_enforcer_, channel_id_service_.get(), | 342 &ct_policy_enforcer_, channel_id_service_.get(), |
343 &transport_security_state_, cert_transparency_verifier_.get(), | 343 &transport_security_state_, cert_transparency_verifier_.get(), |
344 /*SocketPerformanceWatcherFactory*/ nullptr, | 344 /*SocketPerformanceWatcherFactory*/ nullptr, |
345 &crypto_client_stream_factory_, &random_generator_, clock_, | 345 &crypto_client_stream_factory_, &random_generator_, clock_, |
346 kDefaultMaxPacketSize, string(), SupportedVersions(version_), | 346 kDefaultMaxPacketSize, string(), SupportedVersions(version_), |
347 enable_port_selection_, always_require_handshake_confirmation_, | 347 enable_port_selection_, always_require_handshake_confirmation_, |
348 disable_connection_pooling_, load_server_info_timeout_srtt_multiplier_, | 348 disable_connection_pooling_, load_server_info_timeout_srtt_multiplier_, |
349 enable_connection_racing_, enable_non_blocking_io_, disable_disk_cache_, | 349 enable_connection_racing_, enable_non_blocking_io_, disable_disk_cache_, |
350 prefer_aes_, max_number_of_lossy_connections_, packet_loss_threshold_, | 350 prefer_aes_, max_number_of_lossy_connections_, packet_loss_threshold_, |
351 max_disabled_reasons_, threshold_timeouts_with_open_streams_, | 351 max_disabled_reasons_, threshold_timeouts_with_open_streams_, |
352 threshold_public_resets_post_handshake_, receive_buffer_size_, | 352 threshold_public_resets_post_handshake_, receive_buffer_size_, |
353 delay_tcp_race_, /*max_server_configs_stored_in_properties*/ 0, | 353 delay_tcp_race_, /*max_server_configs_stored_in_properties*/ 0, |
354 close_sessions_on_ip_change_, | 354 close_sessions_on_ip_change_, |
355 disable_quic_on_timeout_with_open_streams_, | 355 disable_quic_on_timeout_with_open_streams_, |
356 idle_connection_timeout_seconds_, migrate_sessions_on_network_change_, | 356 idle_connection_timeout_seconds_, migrate_sessions_on_network_change_, |
357 migrate_sessions_early_, allow_server_migration_, force_hol_blocking_, | 357 migrate_sessions_early_, allow_server_migration_, force_hol_blocking_, |
358 QuicTagVector(), /*enable_token_binding*/ false)); | 358 race_cert_verification_, QuicTagVector(), |
| 359 /*enable_token_binding*/ false)); |
359 factory_->set_require_confirmation(false); | 360 factory_->set_require_confirmation(false); |
360 EXPECT_FALSE(factory_->has_quic_server_info_factory()); | 361 EXPECT_FALSE(factory_->has_quic_server_info_factory()); |
361 factory_->set_quic_server_info_factory(new MockQuicServerInfoFactory()); | 362 factory_->set_quic_server_info_factory(new MockQuicServerInfoFactory()); |
362 EXPECT_TRUE(factory_->has_quic_server_info_factory()); | 363 EXPECT_TRUE(factory_->has_quic_server_info_factory()); |
363 } | 364 } |
364 | 365 |
365 void InitializeConnectionMigrationTest( | 366 void InitializeConnectionMigrationTest( |
366 NetworkChangeNotifier::NetworkList connected_networks) { | 367 NetworkChangeNotifier::NetworkList connected_networks) { |
367 scoped_mock_network_change_notifier_.reset( | 368 scoped_mock_network_change_notifier_.reset( |
368 new ScopedMockNetworkChangeNotifier()); | 369 new ScopedMockNetworkChangeNotifier()); |
369 MockNetworkChangeNotifier* mock_ncn = | 370 MockNetworkChangeNotifier* mock_ncn = |
370 scoped_mock_network_change_notifier_->mock_network_change_notifier(); | 371 scoped_mock_network_change_notifier_->mock_network_change_notifier(); |
371 mock_ncn->ForceNetworkHandlesSupported(); | 372 mock_ncn->ForceNetworkHandlesSupported(); |
372 mock_ncn->SetConnectedNetworksList(connected_networks); | 373 mock_ncn->SetConnectedNetworksList(connected_networks); |
373 migrate_sessions_on_network_change_ = true; | 374 migrate_sessions_on_network_change_ = true; |
374 migrate_sessions_early_ = true; | 375 migrate_sessions_early_ = true; |
375 Initialize(); | 376 Initialize(); |
376 } | 377 } |
377 | 378 |
378 bool HasActiveSession(const HostPortPair& host_port_pair) { | 379 bool HasActiveSession(const HostPortPair& host_port_pair) { |
379 QuicServerId server_id(host_port_pair, PRIVACY_MODE_DISABLED); | 380 QuicServerId server_id(host_port_pair, PRIVACY_MODE_DISABLED); |
380 return QuicStreamFactoryPeer::HasActiveSession(factory_.get(), server_id); | 381 return QuicStreamFactoryPeer::HasActiveSession(factory_.get(), server_id); |
381 } | 382 } |
382 | 383 |
| 384 bool HasActiveCertVerifierJob(const QuicServerId& server_id) { |
| 385 return QuicStreamFactoryPeer::HasActiveCertVerifierJob(factory_.get(), |
| 386 server_id); |
| 387 } |
| 388 |
383 QuicChromiumClientSession* GetActiveSession( | 389 QuicChromiumClientSession* GetActiveSession( |
384 const HostPortPair& host_port_pair) { | 390 const HostPortPair& host_port_pair) { |
385 QuicServerId server_id(host_port_pair, PRIVACY_MODE_DISABLED); | 391 QuicServerId server_id(host_port_pair, PRIVACY_MODE_DISABLED); |
386 return QuicStreamFactoryPeer::GetActiveSession(factory_.get(), server_id); | 392 return QuicStreamFactoryPeer::GetActiveSession(factory_.get(), server_id); |
387 } | 393 } |
388 | 394 |
389 std::unique_ptr<QuicHttpStream> CreateFromSession( | 395 std::unique_ptr<QuicHttpStream> CreateFromSession( |
390 const HostPortPair& host_port_pair) { | 396 const HostPortPair& host_port_pair) { |
391 QuicChromiumClientSession* session = GetActiveSession(host_port_pair); | 397 QuicChromiumClientSession* session = GetActiveSession(host_port_pair); |
392 return QuicStreamFactoryPeer::CreateFromSession(factory_.get(), session); | 398 return QuicStreamFactoryPeer::CreateFromSession(factory_.get(), session); |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
542 int threshold_public_resets_post_handshake_; | 548 int threshold_public_resets_post_handshake_; |
543 int receive_buffer_size_; | 549 int receive_buffer_size_; |
544 bool delay_tcp_race_; | 550 bool delay_tcp_race_; |
545 bool close_sessions_on_ip_change_; | 551 bool close_sessions_on_ip_change_; |
546 bool disable_quic_on_timeout_with_open_streams_; | 552 bool disable_quic_on_timeout_with_open_streams_; |
547 int idle_connection_timeout_seconds_; | 553 int idle_connection_timeout_seconds_; |
548 bool migrate_sessions_on_network_change_; | 554 bool migrate_sessions_on_network_change_; |
549 bool migrate_sessions_early_; | 555 bool migrate_sessions_early_; |
550 bool allow_server_migration_; | 556 bool allow_server_migration_; |
551 bool force_hol_blocking_; | 557 bool force_hol_blocking_; |
| 558 bool race_cert_verification_; |
552 }; | 559 }; |
553 | 560 |
554 class QuicStreamFactoryTest : public QuicStreamFactoryTestBase, | 561 class QuicStreamFactoryTest : public QuicStreamFactoryTestBase, |
555 public ::testing::TestWithParam<TestParams> { | 562 public ::testing::TestWithParam<TestParams> { |
556 protected: | 563 protected: |
557 QuicStreamFactoryTest() | 564 QuicStreamFactoryTest() |
558 : QuicStreamFactoryTestBase(GetParam().version, | 565 : QuicStreamFactoryTestBase(GetParam().version, |
559 GetParam().enable_connection_racing) {} | 566 GetParam().enable_connection_racing) {} |
560 }; | 567 }; |
561 | 568 |
(...skipping 3670 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4232 EXPECT_TRUE(cached2->GetServerConfig()); | 4239 EXPECT_TRUE(cached2->GetServerConfig()); |
4233 EXPECT_EQ(server_config2, cached2->server_config()); | 4240 EXPECT_EQ(server_config2, cached2->server_config()); |
4234 EXPECT_EQ(source_address_token2, cached2->source_address_token()); | 4241 EXPECT_EQ(source_address_token2, cached2->source_address_token()); |
4235 EXPECT_EQ(cert_sct2, cached2->cert_sct()); | 4242 EXPECT_EQ(cert_sct2, cached2->cert_sct()); |
4236 EXPECT_EQ(chlo_hash2, cached2->chlo_hash()); | 4243 EXPECT_EQ(chlo_hash2, cached2->chlo_hash()); |
4237 EXPECT_EQ(signature2, cached2->signature()); | 4244 EXPECT_EQ(signature2, cached2->signature()); |
4238 ASSERT_EQ(1U, cached->certs().size()); | 4245 ASSERT_EQ(1U, cached->certs().size()); |
4239 EXPECT_EQ(test_cert2, cached2->certs()[0]); | 4246 EXPECT_EQ(test_cert2, cached2->certs()[0]); |
4240 } | 4247 } |
4241 | 4248 |
| 4249 TEST_P(QuicStreamFactoryTest, StartCertVerifyJob) { |
| 4250 Initialize(); |
| 4251 |
| 4252 MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; |
| 4253 SequencedSocketData socket_data(reads, arraysize(reads), nullptr, 0); |
| 4254 socket_factory_.AddSocketDataProvider(&socket_data); |
| 4255 |
| 4256 // Save current state of |race_cert_verification|. |
| 4257 bool race_cert_verification = |
| 4258 QuicStreamFactoryPeer::GetRaceCertVerification(factory_.get()); |
| 4259 |
| 4260 // Load server config. |
| 4261 HostPortPair host_port_pair(kDefaultServerHostName, kDefaultServerPort); |
| 4262 QuicServerId quic_server_id(host_port_pair_, privacy_mode_); |
| 4263 QuicStreamFactoryPeer::CacheDummyServerConfig(factory_.get(), quic_server_id); |
| 4264 |
| 4265 QuicStreamFactoryPeer::SetRaceCertVerification(factory_.get(), true); |
| 4266 EXPECT_FALSE(HasActiveCertVerifierJob(quic_server_id)); |
| 4267 |
| 4268 // Start CertVerifyJob. |
| 4269 QuicAsyncStatus status = QuicStreamFactoryPeer::StartCertVerifyJob( |
| 4270 factory_.get(), quic_server_id, /*cert_verify_flags=*/0, net_log_); |
| 4271 if (status == QUIC_PENDING) { |
| 4272 // Verify CertVerifierJob has started. |
| 4273 EXPECT_TRUE(HasActiveCertVerifierJob(quic_server_id)); |
| 4274 |
| 4275 while (HasActiveCertVerifierJob(quic_server_id)) { |
| 4276 base::RunLoop().RunUntilIdle(); |
| 4277 } |
| 4278 } |
| 4279 // Verify CertVerifierJob has finished. |
| 4280 EXPECT_FALSE(HasActiveCertVerifierJob(quic_server_id)); |
| 4281 |
| 4282 // Start a QUIC request. |
| 4283 QuicStreamRequest request(factory_.get()); |
| 4284 EXPECT_EQ(ERR_IO_PENDING, |
| 4285 request.Request(host_port_pair_, privacy_mode_, |
| 4286 /*cert_verify_flags=*/0, url_, "GET", net_log_, |
| 4287 callback_.callback())); |
| 4288 |
| 4289 EXPECT_EQ(OK, callback_.WaitForResult()); |
| 4290 |
| 4291 std::unique_ptr<QuicHttpStream> stream = request.CreateStream(); |
| 4292 EXPECT_TRUE(stream.get()); |
| 4293 |
| 4294 // Restore |race_cert_verification|. |
| 4295 QuicStreamFactoryPeer::SetRaceCertVerification(factory_.get(), |
| 4296 race_cert_verification); |
| 4297 |
| 4298 EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 4299 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 4300 |
| 4301 // Verify there are no outstanding CertVerifierJobs after request has |
| 4302 // finished. |
| 4303 EXPECT_FALSE(HasActiveCertVerifierJob(quic_server_id)); |
| 4304 } |
| 4305 |
4242 TEST_P(QuicStreamFactoryTest, QuicDoingZeroRTT) { | 4306 TEST_P(QuicStreamFactoryTest, QuicDoingZeroRTT) { |
4243 Initialize(); | 4307 Initialize(); |
4244 | 4308 |
4245 factory_->set_require_confirmation(true); | 4309 factory_->set_require_confirmation(true); |
4246 QuicServerId quic_server_id(host_port_pair_, PRIVACY_MODE_DISABLED); | 4310 QuicServerId quic_server_id(host_port_pair_, PRIVACY_MODE_DISABLED); |
4247 EXPECT_FALSE(factory_->ZeroRTTEnabledFor(quic_server_id)); | 4311 EXPECT_FALSE(factory_->ZeroRTTEnabledFor(quic_server_id)); |
4248 | 4312 |
4249 factory_->set_require_confirmation(false); | 4313 factory_->set_require_confirmation(false); |
4250 EXPECT_FALSE(factory_->ZeroRTTEnabledFor(quic_server_id)); | 4314 EXPECT_FALSE(factory_->ZeroRTTEnabledFor(quic_server_id)); |
4251 | 4315 |
(...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4807 EXPECT_NE(session1, session2); | 4871 EXPECT_NE(session1, session2); |
4808 | 4872 |
4809 EXPECT_EQ(QuicServerId(origin1_, privacy_mode_), session1->server_id()); | 4873 EXPECT_EQ(QuicServerId(origin1_, privacy_mode_), session1->server_id()); |
4810 EXPECT_EQ(QuicServerId(origin2_, privacy_mode_), session2->server_id()); | 4874 EXPECT_EQ(QuicServerId(origin2_, privacy_mode_), session2->server_id()); |
4811 | 4875 |
4812 EXPECT_TRUE(AllDataConsumed()); | 4876 EXPECT_TRUE(AllDataConsumed()); |
4813 } | 4877 } |
4814 | 4878 |
4815 } // namespace test | 4879 } // namespace test |
4816 } // namespace net | 4880 } // namespace net |
OLD | NEW |