Chromium Code Reviews| 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 <memory> | 7 #include <memory> |
| 8 #include <ostream> | 8 #include <ostream> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
| 14 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
| 15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
| 16 #include "base/threading/thread_task_runner_handle.h" | 16 #include "base/threading/thread_task_runner_handle.h" |
| 17 #include "net/base/test_proxy_delegate.h" | |
| 17 #include "net/cert/cert_verifier.h" | 18 #include "net/cert/cert_verifier.h" |
| 18 #include "net/cert/ct_policy_enforcer.h" | 19 #include "net/cert/ct_policy_enforcer.h" |
| 19 #include "net/cert/multi_log_ct_verifier.h" | 20 #include "net/cert/multi_log_ct_verifier.h" |
| 20 #include "net/dns/mock_host_resolver.h" | 21 #include "net/dns/mock_host_resolver.h" |
| 21 #include "net/http/http_response_headers.h" | 22 #include "net/http/http_response_headers.h" |
| 22 #include "net/http/http_response_info.h" | 23 #include "net/http/http_response_info.h" |
| 23 #include "net/http/http_server_properties_impl.h" | 24 #include "net/http/http_server_properties_impl.h" |
| 24 #include "net/http/http_util.h" | 25 #include "net/http/http_util.h" |
| 25 #include "net/http/transport_security_state.h" | 26 #include "net/http/transport_security_state.h" |
| 26 #include "net/quic/chromium/crypto/proof_verifier_chromium.h" | 27 #include "net/quic/chromium/crypto/proof_verifier_chromium.h" |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 269 // If |factory_| was initialized, then it took over ownership of |clock_|. | 270 // If |factory_| was initialized, then it took over ownership of |clock_|. |
| 270 // If |factory_| was not initialized, then |clock_| needs to be destroyed. | 271 // If |factory_| was not initialized, then |clock_| needs to be destroyed. |
| 271 if (!factory_) | 272 if (!factory_) |
| 272 delete clock_; | 273 delete clock_; |
| 273 } | 274 } |
| 274 | 275 |
| 275 void Initialize() { | 276 void Initialize() { |
| 276 DCHECK(!factory_); | 277 DCHECK(!factory_); |
| 277 factory_.reset(new QuicStreamFactory( | 278 factory_.reset(new QuicStreamFactory( |
| 278 net_log_.net_log(), &host_resolver_, ssl_config_service_.get(), | 279 net_log_.net_log(), &host_resolver_, ssl_config_service_.get(), |
| 279 &socket_factory_, &http_server_properties_, cert_verifier_.get(), | 280 &socket_factory_, &http_server_properties_, &test_proxy_delegate_, |
| 280 &ct_policy_enforcer_, channel_id_service_.get(), | 281 cert_verifier_.get(), &ct_policy_enforcer_, channel_id_service_.get(), |
| 281 &transport_security_state_, cert_transparency_verifier_.get(), | 282 &transport_security_state_, cert_transparency_verifier_.get(), |
| 282 /*SocketPerformanceWatcherFactory*/ nullptr, | 283 /*SocketPerformanceWatcherFactory*/ nullptr, |
| 283 &crypto_client_stream_factory_, &random_generator_, clock_, | 284 &crypto_client_stream_factory_, &random_generator_, clock_, |
| 284 kDefaultMaxPacketSize, string(), SupportedVersions(version_), | 285 kDefaultMaxPacketSize, string(), SupportedVersions(version_), |
| 285 enable_port_selection_, always_require_handshake_confirmation_, | 286 enable_port_selection_, always_require_handshake_confirmation_, |
| 286 disable_connection_pooling_, load_server_info_timeout_srtt_multiplier_, | 287 disable_connection_pooling_, load_server_info_timeout_srtt_multiplier_, |
| 287 enable_connection_racing_, enable_non_blocking_io_, disable_disk_cache_, | 288 enable_connection_racing_, enable_non_blocking_io_, disable_disk_cache_, |
| 288 prefer_aes_, receive_buffer_size_, delay_tcp_race_, | 289 prefer_aes_, receive_buffer_size_, delay_tcp_race_, |
| 289 /*max_server_configs_stored_in_properties*/ 0, | 290 /*max_server_configs_stored_in_properties*/ 0, |
| 290 close_sessions_on_ip_change_, | 291 close_sessions_on_ip_change_, |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 492 << " " << actual_address.port(); | 493 << " " << actual_address.port(); |
| 493 DVLOG(1) << "Expected address: " << expected_address.address().ToString() | 494 DVLOG(1) << "Expected address: " << expected_address.address().ToString() |
| 494 << " " << expected_address.port(); | 495 << " " << expected_address.port(); |
| 495 | 496 |
| 496 stream.reset(); | 497 stream.reset(); |
| 497 EXPECT_TRUE(socket_data1.AllReadDataConsumed()); | 498 EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 498 EXPECT_TRUE(socket_data2.AllReadDataConsumed()); | 499 EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 499 EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); | 500 EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
| 500 } | 501 } |
| 501 | 502 |
| 503 // Verifies that the QUIC stream factory is initialized correctly. | |
| 504 // If |proxy_delegate_provides_quic_supported_proxy| is true, then | |
| 505 // ProxyDelegate provides a proxy that supports QUIC at startup. Otherwise, | |
| 506 // a non proxy server that support alternative services is added to the | |
| 507 // HttpServerProperties map. | |
| 508 void VerifyInitialization(bool proxy_delegate_provides_quic_supported_proxy) { | |
| 509 idle_connection_timeout_seconds_ = 500; | |
| 510 Initialize(); | |
| 511 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); | |
| 512 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); | |
| 513 const QuicConfig* config = QuicStreamFactoryPeer::GetConfig(factory_.get()); | |
| 514 EXPECT_EQ(500, config->IdleConnectionStateLifetime().ToSeconds()); | |
| 515 | |
| 516 QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), runner_.get()); | |
| 517 | |
| 518 const AlternativeService alternative_service1(QUIC, host_port_pair_.host(), | |
| 519 host_port_pair_.port()); | |
| 520 AlternativeServiceInfoVector alternative_service_info_vector; | |
| 521 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); | |
| 522 alternative_service_info_vector.push_back( | |
| 523 AlternativeServiceInfo(alternative_service1, expiration)); | |
| 524 http_server_properties_.SetAlternativeServices( | |
| 525 url::SchemeHostPort(url_), alternative_service_info_vector); | |
| 526 | |
| 527 HostPortPair host_port_pair2(kServer2HostName, kDefaultServerPort); | |
| 528 url::SchemeHostPort server2("https", kServer2HostName, kDefaultServerPort); | |
| 529 const AlternativeService alternative_service2(QUIC, host_port_pair2.host(), | |
| 530 host_port_pair2.port()); | |
| 531 AlternativeServiceInfoVector alternative_service_info_vector2; | |
| 532 alternative_service_info_vector2.push_back( | |
| 533 AlternativeServiceInfo(alternative_service2, expiration)); | |
| 534 if (!proxy_delegate_provides_quic_supported_proxy) { | |
| 535 http_server_properties_.SetAlternativeServices( | |
| 536 server2, alternative_service_info_vector2); | |
| 537 } | |
| 538 // Verify that the properties of both QUIC servers are stored in the | |
| 539 // HTTP properties map. | |
| 540 EXPECT_EQ(proxy_delegate_provides_quic_supported_proxy ? 1U : 2U, | |
| 541 http_server_properties_.alternative_service_map().size()); | |
| 542 | |
| 543 http_server_properties_.SetMaxServerConfigsStoredInProperties( | |
| 544 kMaxQuicServersToPersist); | |
| 545 | |
| 546 QuicServerId quic_server_id(kDefaultServerHostName, 80, | |
| 547 PRIVACY_MODE_DISABLED); | |
| 548 QuicServerInfoFactory* quic_server_info_factory = | |
| 549 new PropertiesBasedQuicServerInfoFactory(&http_server_properties_); | |
| 550 factory_->set_quic_server_info_factory(quic_server_info_factory); | |
| 551 | |
| 552 std::unique_ptr<QuicServerInfo> quic_server_info( | |
| 553 quic_server_info_factory->GetForServer(quic_server_id)); | |
| 554 | |
| 555 // Update quic_server_info's server_config and persist it. | |
| 556 QuicServerInfo::State* state = quic_server_info->mutable_state(); | |
| 557 // Minimum SCFG that passes config validation checks. | |
| 558 const char scfg[] = {// SCFG | |
| 559 0x53, 0x43, 0x46, 0x47, | |
| 560 // num entries | |
| 561 0x01, 0x00, | |
| 562 // padding | |
| 563 0x00, 0x00, | |
| 564 // EXPY | |
| 565 0x45, 0x58, 0x50, 0x59, | |
| 566 // EXPY end offset | |
| 567 0x08, 0x00, 0x00, 0x00, | |
| 568 // Value | |
| 569 '1', '2', '3', '4', '5', '6', '7', '8'}; | |
| 570 | |
| 571 // Create temporary strings becasue Persist() clears string data in |state|. | |
| 572 string server_config(reinterpret_cast<const char*>(&scfg), sizeof(scfg)); | |
| 573 string source_address_token("test_source_address_token"); | |
| 574 string cert_sct("test_cert_sct"); | |
| 575 string chlo_hash("test_chlo_hash"); | |
| 576 string signature("test_signature"); | |
| 577 string test_cert("test_cert"); | |
| 578 vector<string> certs; | |
| 579 certs.push_back(test_cert); | |
| 580 state->server_config = server_config; | |
| 581 state->source_address_token = source_address_token; | |
| 582 state->cert_sct = cert_sct; | |
| 583 state->chlo_hash = chlo_hash; | |
| 584 state->server_config_sig = signature; | |
| 585 state->certs = certs; | |
| 586 | |
| 587 quic_server_info->Persist(); | |
| 588 | |
| 589 QuicServerId quic_server_id2(kServer2HostName, 80, PRIVACY_MODE_DISABLED); | |
| 590 std::unique_ptr<QuicServerInfo> quic_server_info2( | |
| 591 quic_server_info_factory->GetForServer(quic_server_id2)); | |
| 592 | |
| 593 // Update quic_server_info2's server_config and persist it. | |
| 594 QuicServerInfo::State* state2 = quic_server_info2->mutable_state(); | |
| 595 | |
| 596 // Minimum SCFG that passes config validation checks. | |
| 597 const char scfg2[] = {// SCFG | |
| 598 0x53, 0x43, 0x46, 0x47, | |
| 599 // num entries | |
| 600 0x01, 0x00, | |
| 601 // padding | |
| 602 0x00, 0x00, | |
| 603 // EXPY | |
| 604 0x45, 0x58, 0x50, 0x59, | |
| 605 // EXPY end offset | |
| 606 0x08, 0x00, 0x00, 0x00, | |
| 607 // Value | |
| 608 '8', '7', '3', '4', '5', '6', '2', '1'}; | |
| 609 | |
| 610 // Create temporary strings becasue Persist() clears string data in | |
| 611 // |state2|. | |
| 612 string server_config2(reinterpret_cast<const char*>(&scfg2), sizeof(scfg2)); | |
| 613 string source_address_token2("test_source_address_token2"); | |
| 614 string cert_sct2("test_cert_sct2"); | |
| 615 string chlo_hash2("test_chlo_hash2"); | |
| 616 string signature2("test_signature2"); | |
| 617 string test_cert2("test_cert2"); | |
| 618 vector<string> certs2; | |
| 619 certs2.push_back(test_cert2); | |
| 620 state2->server_config = server_config2; | |
| 621 state2->source_address_token = source_address_token2; | |
| 622 state2->cert_sct = cert_sct2; | |
| 623 state2->chlo_hash = chlo_hash2; | |
| 624 state2->server_config_sig = signature2; | |
| 625 state2->certs = certs2; | |
| 626 | |
| 627 quic_server_info2->Persist(); | |
| 628 if (proxy_delegate_provides_quic_supported_proxy) { | |
| 629 test_proxy_delegate_.set_alternative_proxy_server(net::ProxyServer( | |
| 630 net::ProxyServer::SCHEME_QUIC, | |
| 631 net::HostPortPair(kServer2HostName, kDefaultServerPort))); | |
| 632 } | |
|
Zhongyi Shi
2016/10/24 21:02:40
nit: is that possible to move this setting up to l
tbansal1
2016/10/24 21:10:12
Done.
| |
| 633 | |
| 634 QuicStreamFactoryPeer::MaybeInitialize(factory_.get()); | |
| 635 EXPECT_TRUE(QuicStreamFactoryPeer::HasInitializedData(factory_.get())); | |
| 636 | |
| 637 // Verify the MRU order is maintained. | |
| 638 const QuicServerInfoMap& quic_server_info_map = | |
| 639 http_server_properties_.quic_server_info_map(); | |
| 640 EXPECT_EQ(2u, quic_server_info_map.size()); | |
| 641 QuicServerInfoMap::const_iterator quic_server_info_map_it = | |
| 642 quic_server_info_map.begin(); | |
| 643 EXPECT_EQ(quic_server_info_map_it->first, quic_server_id2); | |
| 644 ++quic_server_info_map_it; | |
| 645 EXPECT_EQ(quic_server_info_map_it->first, quic_server_id); | |
| 646 | |
| 647 EXPECT_TRUE(QuicStreamFactoryPeer::SupportsQuicAtStartUp(factory_.get(), | |
| 648 host_port_pair_)); | |
| 649 EXPECT_FALSE(QuicStreamFactoryPeer::CryptoConfigCacheIsEmpty( | |
| 650 factory_.get(), quic_server_id)); | |
| 651 QuicCryptoClientConfig* crypto_config = | |
| 652 QuicStreamFactoryPeer::GetCryptoConfig(factory_.get()); | |
| 653 QuicCryptoClientConfig::CachedState* cached = | |
| 654 crypto_config->LookupOrCreate(quic_server_id); | |
| 655 EXPECT_FALSE(cached->server_config().empty()); | |
| 656 EXPECT_TRUE(cached->GetServerConfig()); | |
| 657 EXPECT_EQ(server_config, cached->server_config()); | |
| 658 EXPECT_EQ(source_address_token, cached->source_address_token()); | |
| 659 EXPECT_EQ(cert_sct, cached->cert_sct()); | |
| 660 EXPECT_EQ(chlo_hash, cached->chlo_hash()); | |
| 661 EXPECT_EQ(signature, cached->signature()); | |
| 662 ASSERT_EQ(1U, cached->certs().size()); | |
| 663 EXPECT_EQ(test_cert, cached->certs()[0]); | |
| 664 | |
| 665 EXPECT_TRUE(QuicStreamFactoryPeer::SupportsQuicAtStartUp(factory_.get(), | |
| 666 host_port_pair2)); | |
| 667 EXPECT_FALSE(QuicStreamFactoryPeer::CryptoConfigCacheIsEmpty( | |
| 668 factory_.get(), quic_server_id2)); | |
| 669 QuicCryptoClientConfig::CachedState* cached2 = | |
| 670 crypto_config->LookupOrCreate(quic_server_id2); | |
| 671 EXPECT_FALSE(cached2->server_config().empty()); | |
| 672 EXPECT_TRUE(cached2->GetServerConfig()); | |
| 673 EXPECT_EQ(server_config2, cached2->server_config()); | |
| 674 EXPECT_EQ(source_address_token2, cached2->source_address_token()); | |
| 675 EXPECT_EQ(cert_sct2, cached2->cert_sct()); | |
| 676 EXPECT_EQ(chlo_hash2, cached2->chlo_hash()); | |
| 677 EXPECT_EQ(signature2, cached2->signature()); | |
| 678 ASSERT_EQ(1U, cached->certs().size()); | |
| 679 EXPECT_EQ(test_cert2, cached2->certs()[0]); | |
| 680 } | |
| 681 | |
| 502 void RunTestLoopUntilIdle() { | 682 void RunTestLoopUntilIdle() { |
| 503 while (!runner_->GetPostedTasks().empty()) | 683 while (!runner_->GetPostedTasks().empty()) |
| 504 runner_->RunNextTask(); | 684 runner_->RunNextTask(); |
| 505 } | 685 } |
| 506 | 686 |
| 507 // Helper methods for tests of connection migration on write error. | 687 // Helper methods for tests of connection migration on write error. |
| 508 void TestMigrationOnWriteErrorNonMigratableStream(IoMode write_error_mode); | 688 void TestMigrationOnWriteErrorNonMigratableStream(IoMode write_error_mode); |
| 509 void TestMigrationOnWriteErrorMigrationDisabled(IoMode write_error_mode); | 689 void TestMigrationOnWriteErrorMigrationDisabled(IoMode write_error_mode); |
| 510 void TestMigrationOnWriteError(IoMode write_error_mode); | 690 void TestMigrationOnWriteError(IoMode write_error_mode); |
| 511 void TestMigrationOnWriteErrorNoNewNetwork(IoMode write_error_mode); | 691 void TestMigrationOnWriteErrorNoNewNetwork(IoMode write_error_mode); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 526 scoped_refptr<SSLConfigService> ssl_config_service_; | 706 scoped_refptr<SSLConfigService> ssl_config_service_; |
| 527 MockClientSocketFactory socket_factory_; | 707 MockClientSocketFactory socket_factory_; |
| 528 MockCryptoClientStreamFactory crypto_client_stream_factory_; | 708 MockCryptoClientStreamFactory crypto_client_stream_factory_; |
| 529 MockRandom random_generator_; | 709 MockRandom random_generator_; |
| 530 MockClock* clock_; // Owned by |factory_| once created. | 710 MockClock* clock_; // Owned by |factory_| once created. |
| 531 scoped_refptr<TestTaskRunner> runner_; | 711 scoped_refptr<TestTaskRunner> runner_; |
| 532 QuicVersion version_; | 712 QuicVersion version_; |
| 533 QuicTestPacketMaker client_maker_; | 713 QuicTestPacketMaker client_maker_; |
| 534 QuicTestPacketMaker server_maker_; | 714 QuicTestPacketMaker server_maker_; |
| 535 HttpServerPropertiesImpl http_server_properties_; | 715 HttpServerPropertiesImpl http_server_properties_; |
| 716 TestProxyDelegate test_proxy_delegate_; | |
| 536 std::unique_ptr<CertVerifier> cert_verifier_; | 717 std::unique_ptr<CertVerifier> cert_verifier_; |
| 537 std::unique_ptr<ChannelIDService> channel_id_service_; | 718 std::unique_ptr<ChannelIDService> channel_id_service_; |
| 538 TransportSecurityState transport_security_state_; | 719 TransportSecurityState transport_security_state_; |
| 539 std::unique_ptr<CTVerifier> cert_transparency_verifier_; | 720 std::unique_ptr<CTVerifier> cert_transparency_verifier_; |
| 540 CTPolicyEnforcer ct_policy_enforcer_; | 721 CTPolicyEnforcer ct_policy_enforcer_; |
| 541 std::unique_ptr<ScopedMockNetworkChangeNotifier> | 722 std::unique_ptr<ScopedMockNetworkChangeNotifier> |
| 542 scoped_mock_network_change_notifier_; | 723 scoped_mock_network_change_notifier_; |
| 543 std::unique_ptr<QuicStreamFactory> factory_; | 724 std::unique_ptr<QuicStreamFactory> factory_; |
| 544 HostPortPair host_port_pair_; | 725 HostPortPair host_port_pair_; |
| 545 GURL url_; | 726 GURL url_; |
| (...skipping 3848 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4394 | 4575 |
| 4395 EXPECT_THAT(callback_.WaitForResult(), IsOk()); | 4576 EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 4396 | 4577 |
| 4397 std::unique_ptr<QuicHttpStream> stream = request.CreateStream(); | 4578 std::unique_ptr<QuicHttpStream> stream = request.CreateStream(); |
| 4398 EXPECT_TRUE(stream.get()); | 4579 EXPECT_TRUE(stream.get()); |
| 4399 EXPECT_TRUE(socket_data.AllReadDataConsumed()); | 4580 EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 4400 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); | 4581 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 4401 QuicStreamFactoryPeer::SetDelayTcpRace(factory_.get(), delay_tcp_race); | 4582 QuicStreamFactoryPeer::SetDelayTcpRace(factory_.get(), delay_tcp_race); |
| 4402 } | 4583 } |
| 4403 | 4584 |
| 4585 // Verifies that the QUIC stream factory is initialized correctly. | |
| 4404 TEST_P(QuicStreamFactoryTest, MaybeInitialize) { | 4586 TEST_P(QuicStreamFactoryTest, MaybeInitialize) { |
| 4405 idle_connection_timeout_seconds_ = 500; | 4587 VerifyInitialization(false); |
| 4406 Initialize(); | 4588 } |
| 4407 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); | |
| 4408 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); | |
| 4409 const QuicConfig* config = QuicStreamFactoryPeer::GetConfig(factory_.get()); | |
| 4410 EXPECT_EQ(500, config->IdleConnectionStateLifetime().ToSeconds()); | |
| 4411 | 4589 |
| 4412 QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), runner_.get()); | 4590 // Verifies that the alternative proxy server provided by the proxy delegate |
| 4413 | 4591 // is added to the list of supported QUIC proxy servers, and the QUIC stream |
| 4414 const AlternativeService alternative_service1(QUIC, host_port_pair_.host(), | 4592 // factory is initialized correctly. |
| 4415 host_port_pair_.port()); | 4593 TEST_P(QuicStreamFactoryTest, MaybeInitializeAlternativeProxyServer) { |
| 4416 AlternativeServiceInfoVector alternative_service_info_vector; | 4594 VerifyInitialization(true); |
| 4417 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); | |
| 4418 alternative_service_info_vector.push_back( | |
| 4419 AlternativeServiceInfo(alternative_service1, expiration)); | |
| 4420 http_server_properties_.SetAlternativeServices( | |
| 4421 url::SchemeHostPort(url_), alternative_service_info_vector); | |
| 4422 | |
| 4423 HostPortPair host_port_pair2(kServer2HostName, kDefaultServerPort); | |
| 4424 url::SchemeHostPort server2("https", kServer2HostName, kDefaultServerPort); | |
| 4425 const AlternativeService alternative_service2(QUIC, host_port_pair2.host(), | |
| 4426 host_port_pair2.port()); | |
| 4427 AlternativeServiceInfoVector alternative_service_info_vector2; | |
| 4428 alternative_service_info_vector2.push_back( | |
| 4429 AlternativeServiceInfo(alternative_service2, expiration)); | |
| 4430 http_server_properties_.SetAlternativeServices( | |
| 4431 server2, alternative_service_info_vector2); | |
| 4432 | |
| 4433 http_server_properties_.SetMaxServerConfigsStoredInProperties( | |
| 4434 kMaxQuicServersToPersist); | |
| 4435 | |
| 4436 QuicServerId quic_server_id(kDefaultServerHostName, 80, | |
| 4437 PRIVACY_MODE_DISABLED); | |
| 4438 QuicServerInfoFactory* quic_server_info_factory = | |
| 4439 new PropertiesBasedQuicServerInfoFactory(&http_server_properties_); | |
| 4440 factory_->set_quic_server_info_factory(quic_server_info_factory); | |
| 4441 | |
| 4442 std::unique_ptr<QuicServerInfo> quic_server_info( | |
| 4443 quic_server_info_factory->GetForServer(quic_server_id)); | |
| 4444 | |
| 4445 // Update quic_server_info's server_config and persist it. | |
| 4446 QuicServerInfo::State* state = quic_server_info->mutable_state(); | |
| 4447 // Minimum SCFG that passes config validation checks. | |
| 4448 const char scfg[] = {// SCFG | |
| 4449 0x53, 0x43, 0x46, 0x47, | |
| 4450 // num entries | |
| 4451 0x01, 0x00, | |
| 4452 // padding | |
| 4453 0x00, 0x00, | |
| 4454 // EXPY | |
| 4455 0x45, 0x58, 0x50, 0x59, | |
| 4456 // EXPY end offset | |
| 4457 0x08, 0x00, 0x00, 0x00, | |
| 4458 // Value | |
| 4459 '1', '2', '3', '4', '5', '6', '7', '8'}; | |
| 4460 | |
| 4461 // Create temporary strings becasue Persist() clears string data in |state|. | |
| 4462 string server_config(reinterpret_cast<const char*>(&scfg), sizeof(scfg)); | |
| 4463 string source_address_token("test_source_address_token"); | |
| 4464 string cert_sct("test_cert_sct"); | |
| 4465 string chlo_hash("test_chlo_hash"); | |
| 4466 string signature("test_signature"); | |
| 4467 string test_cert("test_cert"); | |
| 4468 vector<string> certs; | |
| 4469 certs.push_back(test_cert); | |
| 4470 state->server_config = server_config; | |
| 4471 state->source_address_token = source_address_token; | |
| 4472 state->cert_sct = cert_sct; | |
| 4473 state->chlo_hash = chlo_hash; | |
| 4474 state->server_config_sig = signature; | |
| 4475 state->certs = certs; | |
| 4476 | |
| 4477 quic_server_info->Persist(); | |
| 4478 | |
| 4479 QuicServerId quic_server_id2(kServer2HostName, 80, PRIVACY_MODE_DISABLED); | |
| 4480 std::unique_ptr<QuicServerInfo> quic_server_info2( | |
| 4481 quic_server_info_factory->GetForServer(quic_server_id2)); | |
| 4482 | |
| 4483 // Update quic_server_info2's server_config and persist it. | |
| 4484 QuicServerInfo::State* state2 = quic_server_info2->mutable_state(); | |
| 4485 | |
| 4486 // Minimum SCFG that passes config validation checks. | |
| 4487 const char scfg2[] = {// SCFG | |
| 4488 0x53, 0x43, 0x46, 0x47, | |
| 4489 // num entries | |
| 4490 0x01, 0x00, | |
| 4491 // padding | |
| 4492 0x00, 0x00, | |
| 4493 // EXPY | |
| 4494 0x45, 0x58, 0x50, 0x59, | |
| 4495 // EXPY end offset | |
| 4496 0x08, 0x00, 0x00, 0x00, | |
| 4497 // Value | |
| 4498 '8', '7', '3', '4', '5', '6', '2', '1'}; | |
| 4499 | |
| 4500 // Create temporary strings becasue Persist() clears string data in |state2|. | |
| 4501 string server_config2(reinterpret_cast<const char*>(&scfg2), sizeof(scfg2)); | |
| 4502 string source_address_token2("test_source_address_token2"); | |
| 4503 string cert_sct2("test_cert_sct2"); | |
| 4504 string chlo_hash2("test_chlo_hash2"); | |
| 4505 string signature2("test_signature2"); | |
| 4506 string test_cert2("test_cert2"); | |
| 4507 vector<string> certs2; | |
| 4508 certs2.push_back(test_cert2); | |
| 4509 state2->server_config = server_config2; | |
| 4510 state2->source_address_token = source_address_token2; | |
| 4511 state2->cert_sct = cert_sct2; | |
| 4512 state2->chlo_hash = chlo_hash2; | |
| 4513 state2->server_config_sig = signature2; | |
| 4514 state2->certs = certs2; | |
| 4515 | |
| 4516 quic_server_info2->Persist(); | |
| 4517 | |
| 4518 QuicStreamFactoryPeer::MaybeInitialize(factory_.get()); | |
| 4519 EXPECT_TRUE(QuicStreamFactoryPeer::HasInitializedData(factory_.get())); | |
| 4520 | |
| 4521 // Verify the MRU order is maintained. | |
| 4522 const QuicServerInfoMap& quic_server_info_map = | |
| 4523 http_server_properties_.quic_server_info_map(); | |
| 4524 EXPECT_EQ(2u, quic_server_info_map.size()); | |
| 4525 QuicServerInfoMap::const_iterator quic_server_info_map_it = | |
| 4526 quic_server_info_map.begin(); | |
| 4527 EXPECT_EQ(quic_server_info_map_it->first, quic_server_id2); | |
| 4528 ++quic_server_info_map_it; | |
| 4529 EXPECT_EQ(quic_server_info_map_it->first, quic_server_id); | |
| 4530 | |
| 4531 EXPECT_TRUE(QuicStreamFactoryPeer::SupportsQuicAtStartUp(factory_.get(), | |
| 4532 host_port_pair_)); | |
| 4533 EXPECT_FALSE(QuicStreamFactoryPeer::CryptoConfigCacheIsEmpty(factory_.get(), | |
| 4534 quic_server_id)); | |
| 4535 QuicCryptoClientConfig* crypto_config = | |
| 4536 QuicStreamFactoryPeer::GetCryptoConfig(factory_.get()); | |
| 4537 QuicCryptoClientConfig::CachedState* cached = | |
| 4538 crypto_config->LookupOrCreate(quic_server_id); | |
| 4539 EXPECT_FALSE(cached->server_config().empty()); | |
| 4540 EXPECT_TRUE(cached->GetServerConfig()); | |
| 4541 EXPECT_EQ(server_config, cached->server_config()); | |
| 4542 EXPECT_EQ(source_address_token, cached->source_address_token()); | |
| 4543 EXPECT_EQ(cert_sct, cached->cert_sct()); | |
| 4544 EXPECT_EQ(chlo_hash, cached->chlo_hash()); | |
| 4545 EXPECT_EQ(signature, cached->signature()); | |
| 4546 ASSERT_EQ(1U, cached->certs().size()); | |
| 4547 EXPECT_EQ(test_cert, cached->certs()[0]); | |
| 4548 | |
| 4549 EXPECT_TRUE(QuicStreamFactoryPeer::SupportsQuicAtStartUp(factory_.get(), | |
| 4550 host_port_pair2)); | |
| 4551 EXPECT_FALSE(QuicStreamFactoryPeer::CryptoConfigCacheIsEmpty( | |
| 4552 factory_.get(), quic_server_id2)); | |
| 4553 QuicCryptoClientConfig::CachedState* cached2 = | |
| 4554 crypto_config->LookupOrCreate(quic_server_id2); | |
| 4555 EXPECT_FALSE(cached2->server_config().empty()); | |
| 4556 EXPECT_TRUE(cached2->GetServerConfig()); | |
| 4557 EXPECT_EQ(server_config2, cached2->server_config()); | |
| 4558 EXPECT_EQ(source_address_token2, cached2->source_address_token()); | |
| 4559 EXPECT_EQ(cert_sct2, cached2->cert_sct()); | |
| 4560 EXPECT_EQ(chlo_hash2, cached2->chlo_hash()); | |
| 4561 EXPECT_EQ(signature2, cached2->signature()); | |
| 4562 ASSERT_EQ(1U, cached->certs().size()); | |
| 4563 EXPECT_EQ(test_cert2, cached2->certs()[0]); | |
| 4564 } | 4595 } |
| 4565 | 4596 |
| 4566 TEST_P(QuicStreamFactoryTest, StartCertVerifyJob) { | 4597 TEST_P(QuicStreamFactoryTest, StartCertVerifyJob) { |
| 4567 Initialize(); | 4598 Initialize(); |
| 4568 | 4599 |
| 4569 MockQuicData socket_data; | 4600 MockQuicData socket_data; |
| 4570 socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); | 4601 socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 4571 socket_data.AddSocketDataToFactory(&socket_factory_); | 4602 socket_data.AddSocketDataToFactory(&socket_factory_); |
| 4572 | 4603 |
| 4573 // Save current state of |race_cert_verification|. | 4604 // Save current state of |race_cert_verification|. |
| (...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5222 // Clear all cached states. | 5253 // Clear all cached states. |
| 5223 factory_->ClearCachedStatesInCryptoConfig( | 5254 factory_->ClearCachedStatesInCryptoConfig( |
| 5224 base::Callback<bool(const GURL&)>()); | 5255 base::Callback<bool(const GURL&)>()); |
| 5225 EXPECT_TRUE(test_cases[0].state->certs().empty()); | 5256 EXPECT_TRUE(test_cases[0].state->certs().empty()); |
| 5226 EXPECT_TRUE(test_cases[1].state->certs().empty()); | 5257 EXPECT_TRUE(test_cases[1].state->certs().empty()); |
| 5227 EXPECT_TRUE(test_cases[2].state->certs().empty()); | 5258 EXPECT_TRUE(test_cases[2].state->certs().empty()); |
| 5228 } | 5259 } |
| 5229 | 5260 |
| 5230 } // namespace test | 5261 } // namespace test |
| 5231 } // namespace net | 5262 } // namespace net |
| OLD | NEW |