Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(922)

Side by Side Diff: net/quic/quic_stream_factory_test.cc

Issue 2120703003: QUIC - Race Cert Verification with host resolution if certs are (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix comments. Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 packet_loss_threshold_(1.0f), 308 packet_loss_threshold_(1.0f),
309 max_disabled_reasons_(3), 309 max_disabled_reasons_(3),
310 threshold_timeouts_with_open_streams_(2), 310 threshold_timeouts_with_open_streams_(2),
311 threshold_public_resets_post_handshake_(2), 311 threshold_public_resets_post_handshake_(2),
312 receive_buffer_size_(0), 312 receive_buffer_size_(0),
313 delay_tcp_race_(true), 313 delay_tcp_race_(true),
314 close_sessions_on_ip_change_(false), 314 close_sessions_on_ip_change_(false),
315 disable_quic_on_timeout_with_open_streams_(false), 315 disable_quic_on_timeout_with_open_streams_(false),
316 idle_connection_timeout_seconds_(kIdleConnectionTimeoutSeconds), 316 idle_connection_timeout_seconds_(kIdleConnectionTimeoutSeconds),
317 migrate_sessions_on_network_change_(false), 317 migrate_sessions_on_network_change_(false),
318 migrate_sessions_early_(false) { 318 migrate_sessions_early_(false),
319 race_cert_verification_(false) {
319 clock_->AdvanceTime(QuicTime::Delta::FromSeconds(1)); 320 clock_->AdvanceTime(QuicTime::Delta::FromSeconds(1));
320 } 321 }
321 322
322 ~QuicStreamFactoryTestBase() { 323 ~QuicStreamFactoryTestBase() {
323 // If |factory_| was initialized, then it took over ownership of |clock_|. 324 // If |factory_| was initialized, then it took over ownership of |clock_|.
324 // If |factory_| was not initialized, then |clock_| needs to be destroyed. 325 // If |factory_| was not initialized, then |clock_| needs to be destroyed.
325 if (!factory_) { 326 if (!factory_)
326 delete clock_; 327 delete clock_;
327 }
328 } 328 }
329 329
330 void Initialize() { 330 void Initialize() {
331 DCHECK(!factory_); 331 DCHECK(!factory_);
332 factory_.reset(new QuicStreamFactory( 332 factory_.reset(new QuicStreamFactory(
333 net_log_.net_log(), &host_resolver_, ssl_config_service_.get(), 333 net_log_.net_log(), &host_resolver_, ssl_config_service_.get(),
334 &socket_factory_, &http_server_properties_, cert_verifier_.get(), 334 &socket_factory_, &http_server_properties_, cert_verifier_.get(),
335 &ct_policy_enforcer_, channel_id_service_.get(), 335 &ct_policy_enforcer_, channel_id_service_.get(),
336 &transport_security_state_, cert_transparency_verifier_.get(), 336 &transport_security_state_, cert_transparency_verifier_.get(),
337 /*SocketPerformanceWatcherFactory*/ nullptr, 337 /*SocketPerformanceWatcherFactory*/ nullptr,
338 &crypto_client_stream_factory_, &random_generator_, clock_, 338 &crypto_client_stream_factory_, &random_generator_, clock_,
339 kDefaultMaxPacketSize, string(), SupportedVersions(version_), 339 kDefaultMaxPacketSize, string(), SupportedVersions(version_),
340 enable_port_selection_, always_require_handshake_confirmation_, 340 enable_port_selection_, always_require_handshake_confirmation_,
341 disable_connection_pooling_, load_server_info_timeout_srtt_multiplier_, 341 disable_connection_pooling_, load_server_info_timeout_srtt_multiplier_,
342 enable_connection_racing_, enable_non_blocking_io_, disable_disk_cache_, 342 enable_connection_racing_, enable_non_blocking_io_, disable_disk_cache_,
343 prefer_aes_, max_number_of_lossy_connections_, packet_loss_threshold_, 343 prefer_aes_, max_number_of_lossy_connections_, packet_loss_threshold_,
344 max_disabled_reasons_, threshold_timeouts_with_open_streams_, 344 max_disabled_reasons_, threshold_timeouts_with_open_streams_,
345 threshold_public_resets_post_handshake_, receive_buffer_size_, 345 threshold_public_resets_post_handshake_, receive_buffer_size_,
346 delay_tcp_race_, /*max_server_configs_stored_in_properties*/ 0, 346 delay_tcp_race_, /*max_server_configs_stored_in_properties*/ 0,
347 close_sessions_on_ip_change_, 347 close_sessions_on_ip_change_,
348 disable_quic_on_timeout_with_open_streams_, 348 disable_quic_on_timeout_with_open_streams_,
349 idle_connection_timeout_seconds_, migrate_sessions_on_network_change_, 349 idle_connection_timeout_seconds_, migrate_sessions_on_network_change_,
350 migrate_sessions_early_, QuicTagVector(), 350 migrate_sessions_early_, race_cert_verification_, QuicTagVector(),
351 /*enable_token_binding*/ false)); 351 /*enable_token_binding*/ false));
352 factory_->set_require_confirmation(false); 352 factory_->set_require_confirmation(false);
353 EXPECT_FALSE(factory_->has_quic_server_info_factory()); 353 EXPECT_FALSE(factory_->has_quic_server_info_factory());
354 factory_->set_quic_server_info_factory(new MockQuicServerInfoFactory()); 354 factory_->set_quic_server_info_factory(new MockQuicServerInfoFactory());
355 EXPECT_TRUE(factory_->has_quic_server_info_factory()); 355 EXPECT_TRUE(factory_->has_quic_server_info_factory());
356 } 356 }
357 357
358 void InitializeConnectionMigrationTest( 358 void InitializeConnectionMigrationTest(
359 NetworkChangeNotifier::NetworkList connected_networks) { 359 NetworkChangeNotifier::NetworkList connected_networks) {
360 scoped_mock_network_change_notifier_.reset( 360 scoped_mock_network_change_notifier_.reset(
361 new ScopedMockNetworkChangeNotifier()); 361 new ScopedMockNetworkChangeNotifier());
362 MockNetworkChangeNotifier* mock_ncn = 362 MockNetworkChangeNotifier* mock_ncn =
363 scoped_mock_network_change_notifier_->mock_network_change_notifier(); 363 scoped_mock_network_change_notifier_->mock_network_change_notifier();
364 mock_ncn->ForceNetworkHandlesSupported(); 364 mock_ncn->ForceNetworkHandlesSupported();
365 mock_ncn->SetConnectedNetworksList(connected_networks); 365 mock_ncn->SetConnectedNetworksList(connected_networks);
366 migrate_sessions_on_network_change_ = true; 366 migrate_sessions_on_network_change_ = true;
367 migrate_sessions_early_ = true; 367 migrate_sessions_early_ = true;
368 Initialize(); 368 Initialize();
369 } 369 }
370 370
371 bool HasActiveSession(const HostPortPair& host_port_pair) { 371 bool HasActiveSession(const HostPortPair& host_port_pair) {
372 QuicServerId server_id(host_port_pair, PRIVACY_MODE_DISABLED); 372 QuicServerId server_id(host_port_pair, PRIVACY_MODE_DISABLED);
373 return QuicStreamFactoryPeer::HasActiveSession(factory_.get(), server_id); 373 return QuicStreamFactoryPeer::HasActiveSession(factory_.get(), server_id);
374 } 374 }
375 375
376 bool HasActiveCertVerifierJob(const QuicServerId& server_id) {
377 return QuicStreamFactoryPeer::HasActiveCertVerifierJob(factory_.get(),
378 server_id);
379 }
380
376 QuicChromiumClientSession* GetActiveSession( 381 QuicChromiumClientSession* GetActiveSession(
377 const HostPortPair& host_port_pair) { 382 const HostPortPair& host_port_pair) {
378 QuicServerId server_id(host_port_pair, PRIVACY_MODE_DISABLED); 383 QuicServerId server_id(host_port_pair, PRIVACY_MODE_DISABLED);
379 return QuicStreamFactoryPeer::GetActiveSession(factory_.get(), server_id); 384 return QuicStreamFactoryPeer::GetActiveSession(factory_.get(), server_id);
380 } 385 }
381 386
382 std::unique_ptr<QuicHttpStream> CreateFromSession( 387 std::unique_ptr<QuicHttpStream> CreateFromSession(
383 const HostPortPair& host_port_pair) { 388 const HostPortPair& host_port_pair) {
384 QuicChromiumClientSession* session = GetActiveSession(host_port_pair); 389 QuicChromiumClientSession* session = GetActiveSession(host_port_pair);
385 return QuicStreamFactoryPeer::CreateFromSession(factory_.get(), session); 390 return QuicStreamFactoryPeer::CreateFromSession(factory_.get(), session);
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 int max_disabled_reasons_; 538 int max_disabled_reasons_;
534 int threshold_timeouts_with_open_streams_; 539 int threshold_timeouts_with_open_streams_;
535 int threshold_public_resets_post_handshake_; 540 int threshold_public_resets_post_handshake_;
536 int receive_buffer_size_; 541 int receive_buffer_size_;
537 bool delay_tcp_race_; 542 bool delay_tcp_race_;
538 bool close_sessions_on_ip_change_; 543 bool close_sessions_on_ip_change_;
539 bool disable_quic_on_timeout_with_open_streams_; 544 bool disable_quic_on_timeout_with_open_streams_;
540 int idle_connection_timeout_seconds_; 545 int idle_connection_timeout_seconds_;
541 bool migrate_sessions_on_network_change_; 546 bool migrate_sessions_on_network_change_;
542 bool migrate_sessions_early_; 547 bool migrate_sessions_early_;
548 bool race_cert_verification_;
543 }; 549 };
544 550
545 class QuicStreamFactoryTest : public QuicStreamFactoryTestBase, 551 class QuicStreamFactoryTest : public QuicStreamFactoryTestBase,
546 public ::testing::TestWithParam<TestParams> { 552 public ::testing::TestWithParam<TestParams> {
547 protected: 553 protected:
548 QuicStreamFactoryTest() 554 QuicStreamFactoryTest()
549 : QuicStreamFactoryTestBase(GetParam().version, 555 : QuicStreamFactoryTestBase(GetParam().version,
550 GetParam().enable_connection_racing) {} 556 GetParam().enable_connection_racing) {}
551 }; 557 };
552 558
(...skipping 3310 matching lines...) Expand 10 before | Expand all | Expand 10 after
3863 EXPECT_TRUE(cached2->GetServerConfig()); 3869 EXPECT_TRUE(cached2->GetServerConfig());
3864 EXPECT_EQ(server_config2, cached2->server_config()); 3870 EXPECT_EQ(server_config2, cached2->server_config());
3865 EXPECT_EQ(source_address_token2, cached2->source_address_token()); 3871 EXPECT_EQ(source_address_token2, cached2->source_address_token());
3866 EXPECT_EQ(cert_sct2, cached2->cert_sct()); 3872 EXPECT_EQ(cert_sct2, cached2->cert_sct());
3867 EXPECT_EQ(chlo_hash2, cached2->chlo_hash()); 3873 EXPECT_EQ(chlo_hash2, cached2->chlo_hash());
3868 EXPECT_EQ(signature2, cached2->signature()); 3874 EXPECT_EQ(signature2, cached2->signature());
3869 ASSERT_EQ(1U, cached->certs().size()); 3875 ASSERT_EQ(1U, cached->certs().size());
3870 EXPECT_EQ(test_cert2, cached2->certs()[0]); 3876 EXPECT_EQ(test_cert2, cached2->certs()[0]);
3871 } 3877 }
3872 3878
3879 TEST_P(QuicStreamFactoryTest, StartCertVerifyJob) {
3880 Initialize();
3881
3882 MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)};
3883 SequencedSocketData socket_data(reads, arraysize(reads), nullptr, 0);
3884 socket_factory_.AddSocketDataProvider(&socket_data);
3885
3886 // Save current state of |race_cert_verification|.
3887 bool race_cert_verification =
3888 QuicStreamFactoryPeer::GetRaceCertVerification(factory_.get());
3889
3890 // Load server config.
3891 HostPortPair host_port_pair("test.example.com", kDefaultServerPort);
3892 QuicServerId quic_server_id(host_port_pair_, privacy_mode_);
3893 QuicStreamFactoryPeer::CacheDummyServerConfig(factory_.get(), quic_server_id);
3894
3895 QuicStreamFactoryPeer::SetRaceCertVerification(factory_.get(), true);
3896
3897 // Start CertVerifyJob.
3898 QuicStreamFactoryPeer::StartCertVerifyJob(factory_.get(), quic_server_id,
3899 /*cert_verify_flags=*/0, net_log_);
3900
3901 // Verify CertVerifierJob has started.
3902 EXPECT_TRUE(HasActiveCertVerifierJob(quic_server_id));
3903
3904 while (HasActiveCertVerifierJob(quic_server_id)) {
3905 base::RunLoop().RunUntilIdle();
3906 }
3907 // Verify CertVerifierJob has finished.
3908 EXPECT_FALSE(HasActiveCertVerifierJob(quic_server_id));
3909
3910 // Start a QUIC request.
3911 QuicStreamRequest request(factory_.get());
3912 EXPECT_EQ(ERR_IO_PENDING,
3913 request.Request(host_port_pair_, privacy_mode_,
3914 /*cert_verify_flags=*/0, url_, "GET", net_log_,
3915 callback_.callback()));
3916
3917 EXPECT_EQ(OK, callback_.WaitForResult());
3918
3919 std::unique_ptr<QuicHttpStream> stream = request.CreateStream();
3920 EXPECT_TRUE(stream.get());
3921
3922 // Restore |race_cert_verification|.
3923 QuicStreamFactoryPeer::SetRaceCertVerification(factory_.get(),
3924 race_cert_verification);
3925
3926 EXPECT_TRUE(socket_data.AllReadDataConsumed());
3927 EXPECT_TRUE(socket_data.AllWriteDataConsumed());
3928
3929 // Verify there are no outstanding CertVerifierJobs after request has
3930 // finished.
3931 EXPECT_FALSE(HasActiveCertVerifierJob(quic_server_id));
3932 }
3933
3873 TEST_P(QuicStreamFactoryTest, QuicDoingZeroRTT) { 3934 TEST_P(QuicStreamFactoryTest, QuicDoingZeroRTT) {
3874 Initialize(); 3935 Initialize();
3875 3936
3876 factory_->set_require_confirmation(true); 3937 factory_->set_require_confirmation(true);
3877 QuicServerId quic_server_id(host_port_pair_, PRIVACY_MODE_DISABLED); 3938 QuicServerId quic_server_id(host_port_pair_, PRIVACY_MODE_DISABLED);
3878 EXPECT_FALSE(factory_->ZeroRTTEnabledFor(quic_server_id)); 3939 EXPECT_FALSE(factory_->ZeroRTTEnabledFor(quic_server_id));
3879 3940
3880 factory_->set_require_confirmation(false); 3941 factory_->set_require_confirmation(false);
3881 EXPECT_FALSE(factory_->ZeroRTTEnabledFor(quic_server_id)); 3942 EXPECT_FALSE(factory_->ZeroRTTEnabledFor(quic_server_id));
3882 3943
(...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after
4411 EXPECT_NE(session1, session2); 4472 EXPECT_NE(session1, session2);
4412 4473
4413 EXPECT_EQ(QuicServerId(origin1_, privacy_mode_), session1->server_id()); 4474 EXPECT_EQ(QuicServerId(origin1_, privacy_mode_), session1->server_id());
4414 EXPECT_EQ(QuicServerId(origin2_, privacy_mode_), session2->server_id()); 4475 EXPECT_EQ(QuicServerId(origin2_, privacy_mode_), session2->server_id());
4415 4476
4416 EXPECT_TRUE(AllDataConsumed()); 4477 EXPECT_TRUE(AllDataConsumed());
4417 } 4478 }
4418 4479
4419 } // namespace test 4480 } // namespace test
4420 } // namespace net 4481 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698