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

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: Minor optimization, when verifying certs only skip policy checks. 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 }
(...skipping 11 matching lines...) Expand all
340 enable_port_selection_, always_require_handshake_confirmation_, 341 enable_port_selection_, always_require_handshake_confirmation_,
341 disable_connection_pooling_, load_server_info_timeout_srtt_multiplier_, 342 disable_connection_pooling_, load_server_info_timeout_srtt_multiplier_,
342 enable_connection_racing_, enable_non_blocking_io_, disable_disk_cache_, 343 enable_connection_racing_, enable_non_blocking_io_, disable_disk_cache_,
343 prefer_aes_, max_number_of_lossy_connections_, packet_loss_threshold_, 344 prefer_aes_, max_number_of_lossy_connections_, packet_loss_threshold_,
344 max_disabled_reasons_, threshold_timeouts_with_open_streams_, 345 max_disabled_reasons_, threshold_timeouts_with_open_streams_,
345 threshold_public_resets_post_handshake_, receive_buffer_size_, 346 threshold_public_resets_post_handshake_, receive_buffer_size_,
346 delay_tcp_race_, /*max_server_configs_stored_in_properties*/ 0, 347 delay_tcp_race_, /*max_server_configs_stored_in_properties*/ 0,
347 close_sessions_on_ip_change_, 348 close_sessions_on_ip_change_,
348 disable_quic_on_timeout_with_open_streams_, 349 disable_quic_on_timeout_with_open_streams_,
349 idle_connection_timeout_seconds_, migrate_sessions_on_network_change_, 350 idle_connection_timeout_seconds_, migrate_sessions_on_network_change_,
350 migrate_sessions_early_, QuicTagVector(), 351 migrate_sessions_early_, race_cert_verification_, QuicTagVector(),
351 /*enable_token_binding*/ false)); 352 /*enable_token_binding*/ false));
352 factory_->set_require_confirmation(false); 353 factory_->set_require_confirmation(false);
353 EXPECT_FALSE(factory_->has_quic_server_info_factory()); 354 EXPECT_FALSE(factory_->has_quic_server_info_factory());
354 factory_->set_quic_server_info_factory(new MockQuicServerInfoFactory()); 355 factory_->set_quic_server_info_factory(new MockQuicServerInfoFactory());
355 EXPECT_TRUE(factory_->has_quic_server_info_factory()); 356 EXPECT_TRUE(factory_->has_quic_server_info_factory());
356 } 357 }
357 358
358 void InitializeConnectionMigrationTest( 359 void InitializeConnectionMigrationTest(
359 NetworkChangeNotifier::NetworkList connected_networks) { 360 NetworkChangeNotifier::NetworkList connected_networks) {
360 scoped_mock_network_change_notifier_.reset( 361 scoped_mock_network_change_notifier_.reset(
361 new ScopedMockNetworkChangeNotifier()); 362 new ScopedMockNetworkChangeNotifier());
362 MockNetworkChangeNotifier* mock_ncn = 363 MockNetworkChangeNotifier* mock_ncn =
363 scoped_mock_network_change_notifier_->mock_network_change_notifier(); 364 scoped_mock_network_change_notifier_->mock_network_change_notifier();
364 mock_ncn->ForceNetworkHandlesSupported(); 365 mock_ncn->ForceNetworkHandlesSupported();
365 mock_ncn->SetConnectedNetworksList(connected_networks); 366 mock_ncn->SetConnectedNetworksList(connected_networks);
366 migrate_sessions_on_network_change_ = true; 367 migrate_sessions_on_network_change_ = true;
367 migrate_sessions_early_ = true; 368 migrate_sessions_early_ = true;
368 Initialize(); 369 Initialize();
369 } 370 }
370 371
371 bool HasActiveSession(const HostPortPair& host_port_pair) { 372 bool HasActiveSession(const HostPortPair& host_port_pair) {
372 QuicServerId server_id(host_port_pair, PRIVACY_MODE_DISABLED); 373 QuicServerId server_id(host_port_pair, PRIVACY_MODE_DISABLED);
373 return QuicStreamFactoryPeer::HasActiveSession(factory_.get(), server_id); 374 return QuicStreamFactoryPeer::HasActiveSession(factory_.get(), server_id);
374 } 375 }
375 376
377 bool HasActiveCertVerifierJob(const QuicServerId& server_id) {
378 return QuicStreamFactoryPeer::HasActiveCertVerifierJob(factory_.get(),
379 server_id);
380 }
381
376 QuicChromiumClientSession* GetActiveSession( 382 QuicChromiumClientSession* GetActiveSession(
377 const HostPortPair& host_port_pair) { 383 const HostPortPair& host_port_pair) {
378 QuicServerId server_id(host_port_pair, PRIVACY_MODE_DISABLED); 384 QuicServerId server_id(host_port_pair, PRIVACY_MODE_DISABLED);
379 return QuicStreamFactoryPeer::GetActiveSession(factory_.get(), server_id); 385 return QuicStreamFactoryPeer::GetActiveSession(factory_.get(), server_id);
380 } 386 }
381 387
382 std::unique_ptr<QuicHttpStream> CreateFromSession( 388 std::unique_ptr<QuicHttpStream> CreateFromSession(
383 const HostPortPair& host_port_pair) { 389 const HostPortPair& host_port_pair) {
384 QuicChromiumClientSession* session = GetActiveSession(host_port_pair); 390 QuicChromiumClientSession* session = GetActiveSession(host_port_pair);
385 return QuicStreamFactoryPeer::CreateFromSession(factory_.get(), session); 391 return QuicStreamFactoryPeer::CreateFromSession(factory_.get(), session);
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 int max_disabled_reasons_; 539 int max_disabled_reasons_;
534 int threshold_timeouts_with_open_streams_; 540 int threshold_timeouts_with_open_streams_;
535 int threshold_public_resets_post_handshake_; 541 int threshold_public_resets_post_handshake_;
536 int receive_buffer_size_; 542 int receive_buffer_size_;
537 bool delay_tcp_race_; 543 bool delay_tcp_race_;
538 bool close_sessions_on_ip_change_; 544 bool close_sessions_on_ip_change_;
539 bool disable_quic_on_timeout_with_open_streams_; 545 bool disable_quic_on_timeout_with_open_streams_;
540 int idle_connection_timeout_seconds_; 546 int idle_connection_timeout_seconds_;
541 bool migrate_sessions_on_network_change_; 547 bool migrate_sessions_on_network_change_;
542 bool migrate_sessions_early_; 548 bool migrate_sessions_early_;
549 bool race_cert_verification_;
543 }; 550 };
544 551
545 class QuicStreamFactoryTest : public QuicStreamFactoryTestBase, 552 class QuicStreamFactoryTest : public QuicStreamFactoryTestBase,
546 public ::testing::TestWithParam<TestParams> { 553 public ::testing::TestWithParam<TestParams> {
547 protected: 554 protected:
548 QuicStreamFactoryTest() 555 QuicStreamFactoryTest()
549 : QuicStreamFactoryTestBase(GetParam().version, 556 : QuicStreamFactoryTestBase(GetParam().version,
550 GetParam().enable_connection_racing) {} 557 GetParam().enable_connection_racing) {}
551 }; 558 };
552 559
(...skipping 3310 matching lines...) Expand 10 before | Expand all | Expand 10 after
3863 EXPECT_TRUE(cached2->GetServerConfig()); 3870 EXPECT_TRUE(cached2->GetServerConfig());
3864 EXPECT_EQ(server_config2, cached2->server_config()); 3871 EXPECT_EQ(server_config2, cached2->server_config());
3865 EXPECT_EQ(source_address_token2, cached2->source_address_token()); 3872 EXPECT_EQ(source_address_token2, cached2->source_address_token());
3866 EXPECT_EQ(cert_sct2, cached2->cert_sct()); 3873 EXPECT_EQ(cert_sct2, cached2->cert_sct());
3867 EXPECT_EQ(chlo_hash2, cached2->chlo_hash()); 3874 EXPECT_EQ(chlo_hash2, cached2->chlo_hash());
3868 EXPECT_EQ(signature2, cached2->signature()); 3875 EXPECT_EQ(signature2, cached2->signature());
3869 ASSERT_EQ(1U, cached->certs().size()); 3876 ASSERT_EQ(1U, cached->certs().size());
3870 EXPECT_EQ(test_cert2, cached2->certs()[0]); 3877 EXPECT_EQ(test_cert2, cached2->certs()[0]);
3871 } 3878 }
3872 3879
3880 TEST_P(QuicStreamFactoryTest, StartCertVerifyJob) {
3881 Initialize();
3882
3883 MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)};
3884 SequencedSocketData socket_data(reads, arraysize(reads), nullptr, 0);
3885 socket_factory_.AddSocketDataProvider(&socket_data);
3886
3887 // Save current state of |race_cert_verification|.
3888 bool race_cert_verification =
3889 QuicStreamFactoryPeer::GetRaceCertVerification(factory_.get());
3890
3891 // Load server config.
3892 HostPortPair host_port_pair("test.example.com", kDefaultServerPort);
3893 QuicServerId quic_server_id(host_port_pair_, privacy_mode_);
3894 QuicStreamFactoryPeer::CacheDummyServerConfig(factory_.get(), quic_server_id);
3895
3896 QuicStreamFactoryPeer::SetRaceCertVerification(factory_.get(), true);
3897
3898 // Start CertVerifyJob.
3899 QuicStreamFactoryPeer::StartCertVerifyJob(factory_.get(), quic_server_id,
3900 /*cert_verify_flags=*/0, net_log_);
3901
3902 // Verify CertVerifierJob has started.
3903 EXPECT_TRUE(HasActiveCertVerifierJob(quic_server_id));
3904
3905 while (HasActiveCertVerifierJob(quic_server_id)) {
3906 base::RunLoop().RunUntilIdle();
3907 }
3908 // Verify CertVerifierJob has finished.
3909 EXPECT_FALSE(HasActiveCertVerifierJob(quic_server_id));
3910
3911 // Start a QUIC request.
3912 QuicStreamRequest request(factory_.get());
3913 EXPECT_EQ(ERR_IO_PENDING,
3914 request.Request(host_port_pair_, privacy_mode_,
3915 /*cert_verify_flags=*/0, url_, "GET", net_log_,
3916 callback_.callback()));
3917
3918 EXPECT_EQ(OK, callback_.WaitForResult());
3919
3920 std::unique_ptr<QuicHttpStream> stream = request.CreateStream();
3921 EXPECT_TRUE(stream.get());
3922
3923 // Restore |race_cert_verification|.
3924 QuicStreamFactoryPeer::SetRaceCertVerification(factory_.get(),
3925 race_cert_verification);
3926
3927 EXPECT_TRUE(socket_data.AllReadDataConsumed());
3928 EXPECT_TRUE(socket_data.AllWriteDataConsumed());
3929
3930 // Verify there are no outstanding CertVerifierJobs after request has
3931 // finished.
3932 EXPECT_FALSE(HasActiveCertVerifierJob(quic_server_id));
3933 }
3934
3873 TEST_P(QuicStreamFactoryTest, QuicDoingZeroRTT) { 3935 TEST_P(QuicStreamFactoryTest, QuicDoingZeroRTT) {
3874 Initialize(); 3936 Initialize();
3875 3937
3876 factory_->set_require_confirmation(true); 3938 factory_->set_require_confirmation(true);
3877 QuicServerId quic_server_id(host_port_pair_, PRIVACY_MODE_DISABLED); 3939 QuicServerId quic_server_id(host_port_pair_, PRIVACY_MODE_DISABLED);
3878 EXPECT_FALSE(factory_->ZeroRTTEnabledFor(quic_server_id)); 3940 EXPECT_FALSE(factory_->ZeroRTTEnabledFor(quic_server_id));
3879 3941
3880 factory_->set_require_confirmation(false); 3942 factory_->set_require_confirmation(false);
3881 EXPECT_FALSE(factory_->ZeroRTTEnabledFor(quic_server_id)); 3943 EXPECT_FALSE(factory_->ZeroRTTEnabledFor(quic_server_id));
3882 3944
(...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after
4411 EXPECT_NE(session1, session2); 4473 EXPECT_NE(session1, session2);
4412 4474
4413 EXPECT_EQ(QuicServerId(origin1_, privacy_mode_), session1->server_id()); 4475 EXPECT_EQ(QuicServerId(origin1_, privacy_mode_), session1->server_id());
4414 EXPECT_EQ(QuicServerId(origin2_, privacy_mode_), session2->server_id()); 4476 EXPECT_EQ(QuicServerId(origin2_, privacy_mode_), session2->server_id());
4415 4477
4416 EXPECT_TRUE(AllDataConsumed()); 4478 EXPECT_TRUE(AllDataConsumed());
4417 } 4479 }
4418 4480
4419 } // namespace test 4481 } // namespace test
4420 } // namespace net 4482 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698