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) { | |
327 clock_->AdvanceTime(QuicTime::Delta::FromSeconds(1)); | 326 clock_->AdvanceTime(QuicTime::Delta::FromSeconds(1)); |
328 } | 327 } |
329 | 328 |
330 ~QuicStreamFactoryTestBase() { | 329 ~QuicStreamFactoryTestBase() { |
331 // If |factory_| was initialized, then it took over ownership of |clock_|. | 330 // If |factory_| was initialized, then it took over ownership of |clock_|. |
332 // If |factory_| was not initialized, then |clock_| needs to be destroyed. | 331 // If |factory_| was not initialized, then |clock_| needs to be destroyed. |
333 if (!factory_) | 332 if (!factory_) { |
334 delete clock_; | 333 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 race_cert_verification_, QuicTagVector(), | 358 QuicTagVector(), /*enable_token_binding*/ false)); |
359 /*enable_token_binding*/ false)); | |
360 factory_->set_require_confirmation(false); | 359 factory_->set_require_confirmation(false); |
361 EXPECT_FALSE(factory_->has_quic_server_info_factory()); | 360 EXPECT_FALSE(factory_->has_quic_server_info_factory()); |
362 factory_->set_quic_server_info_factory(new MockQuicServerInfoFactory()); | 361 factory_->set_quic_server_info_factory(new MockQuicServerInfoFactory()); |
363 EXPECT_TRUE(factory_->has_quic_server_info_factory()); | 362 EXPECT_TRUE(factory_->has_quic_server_info_factory()); |
364 } | 363 } |
365 | 364 |
366 void InitializeConnectionMigrationTest( | 365 void InitializeConnectionMigrationTest( |
367 NetworkChangeNotifier::NetworkList connected_networks) { | 366 NetworkChangeNotifier::NetworkList connected_networks) { |
368 scoped_mock_network_change_notifier_.reset( | 367 scoped_mock_network_change_notifier_.reset( |
369 new ScopedMockNetworkChangeNotifier()); | 368 new ScopedMockNetworkChangeNotifier()); |
370 MockNetworkChangeNotifier* mock_ncn = | 369 MockNetworkChangeNotifier* mock_ncn = |
371 scoped_mock_network_change_notifier_->mock_network_change_notifier(); | 370 scoped_mock_network_change_notifier_->mock_network_change_notifier(); |
372 mock_ncn->ForceNetworkHandlesSupported(); | 371 mock_ncn->ForceNetworkHandlesSupported(); |
373 mock_ncn->SetConnectedNetworksList(connected_networks); | 372 mock_ncn->SetConnectedNetworksList(connected_networks); |
374 migrate_sessions_on_network_change_ = true; | 373 migrate_sessions_on_network_change_ = true; |
375 migrate_sessions_early_ = true; | 374 migrate_sessions_early_ = true; |
376 Initialize(); | 375 Initialize(); |
377 } | 376 } |
378 | 377 |
379 bool HasActiveSession(const HostPortPair& host_port_pair) { | 378 bool HasActiveSession(const HostPortPair& host_port_pair) { |
380 QuicServerId server_id(host_port_pair, PRIVACY_MODE_DISABLED); | 379 QuicServerId server_id(host_port_pair, PRIVACY_MODE_DISABLED); |
381 return QuicStreamFactoryPeer::HasActiveSession(factory_.get(), server_id); | 380 return QuicStreamFactoryPeer::HasActiveSession(factory_.get(), server_id); |
382 } | 381 } |
383 | 382 |
384 bool HasActiveCertVerifierJob(const QuicServerId& server_id) { | |
385 return QuicStreamFactoryPeer::HasActiveCertVerifierJob(factory_.get(), | |
386 server_id); | |
387 } | |
388 | |
389 QuicChromiumClientSession* GetActiveSession( | 383 QuicChromiumClientSession* GetActiveSession( |
390 const HostPortPair& host_port_pair) { | 384 const HostPortPair& host_port_pair) { |
391 QuicServerId server_id(host_port_pair, PRIVACY_MODE_DISABLED); | 385 QuicServerId server_id(host_port_pair, PRIVACY_MODE_DISABLED); |
392 return QuicStreamFactoryPeer::GetActiveSession(factory_.get(), server_id); | 386 return QuicStreamFactoryPeer::GetActiveSession(factory_.get(), server_id); |
393 } | 387 } |
394 | 388 |
395 std::unique_ptr<QuicHttpStream> CreateFromSession( | 389 std::unique_ptr<QuicHttpStream> CreateFromSession( |
396 const HostPortPair& host_port_pair) { | 390 const HostPortPair& host_port_pair) { |
397 QuicChromiumClientSession* session = GetActiveSession(host_port_pair); | 391 QuicChromiumClientSession* session = GetActiveSession(host_port_pair); |
398 return QuicStreamFactoryPeer::CreateFromSession(factory_.get(), session); | 392 return QuicStreamFactoryPeer::CreateFromSession(factory_.get(), session); |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
548 int threshold_public_resets_post_handshake_; | 542 int threshold_public_resets_post_handshake_; |
549 int receive_buffer_size_; | 543 int receive_buffer_size_; |
550 bool delay_tcp_race_; | 544 bool delay_tcp_race_; |
551 bool close_sessions_on_ip_change_; | 545 bool close_sessions_on_ip_change_; |
552 bool disable_quic_on_timeout_with_open_streams_; | 546 bool disable_quic_on_timeout_with_open_streams_; |
553 int idle_connection_timeout_seconds_; | 547 int idle_connection_timeout_seconds_; |
554 bool migrate_sessions_on_network_change_; | 548 bool migrate_sessions_on_network_change_; |
555 bool migrate_sessions_early_; | 549 bool migrate_sessions_early_; |
556 bool allow_server_migration_; | 550 bool allow_server_migration_; |
557 bool force_hol_blocking_; | 551 bool force_hol_blocking_; |
558 bool race_cert_verification_; | |
559 }; | 552 }; |
560 | 553 |
561 class QuicStreamFactoryTest : public QuicStreamFactoryTestBase, | 554 class QuicStreamFactoryTest : public QuicStreamFactoryTestBase, |
562 public ::testing::TestWithParam<TestParams> { | 555 public ::testing::TestWithParam<TestParams> { |
563 protected: | 556 protected: |
564 QuicStreamFactoryTest() | 557 QuicStreamFactoryTest() |
565 : QuicStreamFactoryTestBase(GetParam().version, | 558 : QuicStreamFactoryTestBase(GetParam().version, |
566 GetParam().enable_connection_racing) {} | 559 GetParam().enable_connection_racing) {} |
567 }; | 560 }; |
568 | 561 |
(...skipping 3670 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4239 EXPECT_TRUE(cached2->GetServerConfig()); | 4232 EXPECT_TRUE(cached2->GetServerConfig()); |
4240 EXPECT_EQ(server_config2, cached2->server_config()); | 4233 EXPECT_EQ(server_config2, cached2->server_config()); |
4241 EXPECT_EQ(source_address_token2, cached2->source_address_token()); | 4234 EXPECT_EQ(source_address_token2, cached2->source_address_token()); |
4242 EXPECT_EQ(cert_sct2, cached2->cert_sct()); | 4235 EXPECT_EQ(cert_sct2, cached2->cert_sct()); |
4243 EXPECT_EQ(chlo_hash2, cached2->chlo_hash()); | 4236 EXPECT_EQ(chlo_hash2, cached2->chlo_hash()); |
4244 EXPECT_EQ(signature2, cached2->signature()); | 4237 EXPECT_EQ(signature2, cached2->signature()); |
4245 ASSERT_EQ(1U, cached->certs().size()); | 4238 ASSERT_EQ(1U, cached->certs().size()); |
4246 EXPECT_EQ(test_cert2, cached2->certs()[0]); | 4239 EXPECT_EQ(test_cert2, cached2->certs()[0]); |
4247 } | 4240 } |
4248 | 4241 |
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 EXPECT_NE(QUIC_FAILURE, status); | |
4272 | |
4273 if (status == QUIC_PENDING) { | |
4274 // Verify CertVerifierJob has started. | |
4275 EXPECT_TRUE(HasActiveCertVerifierJob(quic_server_id)); | |
4276 | |
4277 while (HasActiveCertVerifierJob(quic_server_id)) { | |
4278 base::RunLoop().RunUntilIdle(); | |
4279 } | |
4280 } | |
4281 // Verify CertVerifierJob has finished. | |
4282 EXPECT_FALSE(HasActiveCertVerifierJob(quic_server_id)); | |
4283 | |
4284 // Start a QUIC request. | |
4285 QuicStreamRequest request(factory_.get()); | |
4286 EXPECT_EQ(ERR_IO_PENDING, | |
4287 request.Request(host_port_pair_, privacy_mode_, | |
4288 /*cert_verify_flags=*/0, url_, "GET", net_log_, | |
4289 callback_.callback())); | |
4290 | |
4291 EXPECT_EQ(OK, callback_.WaitForResult()); | |
4292 | |
4293 std::unique_ptr<QuicHttpStream> stream = request.CreateStream(); | |
4294 EXPECT_TRUE(stream.get()); | |
4295 | |
4296 // Restore |race_cert_verification|. | |
4297 QuicStreamFactoryPeer::SetRaceCertVerification(factory_.get(), | |
4298 race_cert_verification); | |
4299 | |
4300 EXPECT_TRUE(socket_data.AllReadDataConsumed()); | |
4301 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); | |
4302 | |
4303 // Verify there are no outstanding CertVerifierJobs after request has | |
4304 // finished. | |
4305 EXPECT_FALSE(HasActiveCertVerifierJob(quic_server_id)); | |
4306 } | |
4307 | |
4308 TEST_P(QuicStreamFactoryTest, QuicDoingZeroRTT) { | 4242 TEST_P(QuicStreamFactoryTest, QuicDoingZeroRTT) { |
4309 Initialize(); | 4243 Initialize(); |
4310 | 4244 |
4311 factory_->set_require_confirmation(true); | 4245 factory_->set_require_confirmation(true); |
4312 QuicServerId quic_server_id(host_port_pair_, PRIVACY_MODE_DISABLED); | 4246 QuicServerId quic_server_id(host_port_pair_, PRIVACY_MODE_DISABLED); |
4313 EXPECT_FALSE(factory_->ZeroRTTEnabledFor(quic_server_id)); | 4247 EXPECT_FALSE(factory_->ZeroRTTEnabledFor(quic_server_id)); |
4314 | 4248 |
4315 factory_->set_require_confirmation(false); | 4249 factory_->set_require_confirmation(false); |
4316 EXPECT_FALSE(factory_->ZeroRTTEnabledFor(quic_server_id)); | 4250 EXPECT_FALSE(factory_->ZeroRTTEnabledFor(quic_server_id)); |
4317 | 4251 |
(...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4873 EXPECT_NE(session1, session2); | 4807 EXPECT_NE(session1, session2); |
4874 | 4808 |
4875 EXPECT_EQ(QuicServerId(origin1_, privacy_mode_), session1->server_id()); | 4809 EXPECT_EQ(QuicServerId(origin1_, privacy_mode_), session1->server_id()); |
4876 EXPECT_EQ(QuicServerId(origin2_, privacy_mode_), session2->server_id()); | 4810 EXPECT_EQ(QuicServerId(origin2_, privacy_mode_), session2->server_id()); |
4877 | 4811 |
4878 EXPECT_TRUE(AllDataConsumed()); | 4812 EXPECT_TRUE(AllDataConsumed()); |
4879 } | 4813 } |
4880 | 4814 |
4881 } // namespace test | 4815 } // namespace test |
4882 } // namespace net | 4816 } // namespace net |
OLD | NEW |