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

Side by Side Diff: net/quic/chromium/quic_network_transaction_unittest.cc

Issue 2901093004: Add and persist a new field in AlternativeServiceInfo to list QUIC verisons advertised (Closed)
Patch Set: fix Canonical test Created 3 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 <algorithm> 5 #include <algorithm>
6 #include <memory> 6 #include <memory>
7 #include <ostream> 7 #include <ostream>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/memory/ptr_util.h" 14 #include "base/memory/ptr_util.h"
15 #include "base/run_loop.h" 15 #include "base/run_loop.h"
16 #include "base/stl_util.h" 16 #include "base/stl_util.h"
17 #include "base/strings/string_number_conversions.h"
17 #include "base/strings/stringprintf.h" 18 #include "base/strings/stringprintf.h"
18 #include "base/test/histogram_tester.h" 19 #include "base/test/histogram_tester.h"
19 #include "net/base/chunked_upload_data_stream.h" 20 #include "net/base/chunked_upload_data_stream.h"
20 #include "net/base/mock_network_change_notifier.h" 21 #include "net/base/mock_network_change_notifier.h"
21 #include "net/base/test_completion_callback.h" 22 #include "net/base/test_completion_callback.h"
22 #include "net/base/test_proxy_delegate.h" 23 #include "net/base/test_proxy_delegate.h"
23 #include "net/cert/ct_policy_enforcer.h" 24 #include "net/cert/ct_policy_enforcer.h"
24 #include "net/cert/mock_cert_verifier.h" 25 #include "net/cert/mock_cert_verifier.h"
25 #include "net/cert/multi_log_ct_verifier.h" 26 #include "net/cert/multi_log_ct_verifier.h"
26 #include "net/dns/mock_host_resolver.h" 27 #include "net/dns/mock_host_resolver.h"
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 break; 121 break;
121 } 122 }
122 os << " }"; 123 os << " }";
123 return os; 124 return os;
124 } 125 }
125 126
126 QuicVersion version; 127 QuicVersion version;
127 DestinationType destination_type; 128 DestinationType destination_type;
128 }; 129 };
129 130
131 std::string GenerateQuicVersionsListForAltSvcHeader(
132 const QuicVersionVector& versions) {
133 std::string result = "";
134 for (const QuicVersion& version : versions) {
135 if (!result.empty())
136 result.append(",");
137 result.append(base::IntToString(version));
138 }
139 return result;
140 }
141
130 std::vector<PoolingTestParams> GetPoolingTestParams() { 142 std::vector<PoolingTestParams> GetPoolingTestParams() {
131 std::vector<PoolingTestParams> params; 143 std::vector<PoolingTestParams> params;
132 QuicVersionVector all_supported_versions = AllSupportedVersions(); 144 QuicVersionVector all_supported_versions = AllSupportedVersions();
133 for (const QuicVersion version : all_supported_versions) { 145 for (const QuicVersion version : all_supported_versions) {
134 params.push_back(PoolingTestParams{version, SAME_AS_FIRST}); 146 params.push_back(PoolingTestParams{version, SAME_AS_FIRST});
135 params.push_back(PoolingTestParams{version, SAME_AS_SECOND}); 147 params.push_back(PoolingTestParams{version, SAME_AS_SECOND});
136 params.push_back(PoolingTestParams{version, DIFFERENT}); 148 params.push_back(PoolingTestParams{version, DIFFERENT});
137 } 149 }
138 return params; 150 return params;
139 } 151 }
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 QuicStreamId stream_id, 504 QuicStreamId stream_id,
493 bool should_include_version, 505 bool should_include_version,
494 bool fin, 506 bool fin,
495 SpdyHeaderBlock headers, 507 SpdyHeaderBlock headers,
496 QuicStreamOffset* offset) { 508 QuicStreamOffset* offset) {
497 return server_maker_.MakeResponseHeadersPacketWithOffsetTracking( 509 return server_maker_.MakeResponseHeadersPacketWithOffsetTracking(
498 packet_number, stream_id, should_include_version, fin, 510 packet_number, stream_id, should_include_version, fin,
499 std::move(headers), offset); 511 std::move(headers), offset);
500 } 512 }
501 513
502 void CreateSession() { 514 void CreateSession(const QuicVersionVector& supported_versions) {
503 session_params_.enable_quic = true; 515 session_params_.enable_quic = true;
504 session_params_.quic_supported_versions = SupportedVersions(version_); 516 session_params_.quic_supported_versions = supported_versions;
505 517
506 session_context_.quic_clock = &clock_; 518 session_context_.quic_clock = &clock_;
507 session_context_.quic_random = &random_generator_; 519 session_context_.quic_random = &random_generator_;
508 session_context_.client_socket_factory = &socket_factory_; 520 session_context_.client_socket_factory = &socket_factory_;
509 session_context_.quic_crypto_client_stream_factory = 521 session_context_.quic_crypto_client_stream_factory =
510 &crypto_client_stream_factory_; 522 &crypto_client_stream_factory_;
511 session_context_.host_resolver = &host_resolver_; 523 session_context_.host_resolver = &host_resolver_;
512 session_context_.cert_verifier = &cert_verifier_; 524 session_context_.cert_verifier = &cert_verifier_;
513 session_context_.transport_security_state = &transport_security_state_; 525 session_context_.transport_security_state = &transport_security_state_;
514 session_context_.cert_transparency_verifier = 526 session_context_.cert_transparency_verifier =
515 cert_transparency_verifier_.get(); 527 cert_transparency_verifier_.get();
516 session_context_.ct_policy_enforcer = &ct_policy_enforcer_; 528 session_context_.ct_policy_enforcer = &ct_policy_enforcer_;
517 session_context_.socket_performance_watcher_factory = 529 session_context_.socket_performance_watcher_factory =
518 &test_socket_performance_watcher_factory_; 530 &test_socket_performance_watcher_factory_;
519 session_context_.proxy_service = proxy_service_.get(); 531 session_context_.proxy_service = proxy_service_.get();
520 session_context_.ssl_config_service = ssl_config_service_.get(); 532 session_context_.ssl_config_service = ssl_config_service_.get();
521 session_context_.http_auth_handler_factory = auth_handler_factory_.get(); 533 session_context_.http_auth_handler_factory = auth_handler_factory_.get();
522 session_context_.http_server_properties = &http_server_properties_; 534 session_context_.http_server_properties = &http_server_properties_;
523 session_context_.net_log = net_log_.bound().net_log(); 535 session_context_.net_log = net_log_.bound().net_log();
524 536
525 session_.reset(new HttpNetworkSession(session_params_, session_context_)); 537 session_.reset(new HttpNetworkSession(session_params_, session_context_));
526 session_->quic_stream_factory()->set_require_confirmation(false); 538 session_->quic_stream_factory()->set_require_confirmation(false);
527 } 539 }
528 540
541 void CreateSession() { return CreateSession(SupportedVersions(version_)); }
542
529 void CheckWasQuicResponse(HttpNetworkTransaction* trans) { 543 void CheckWasQuicResponse(HttpNetworkTransaction* trans) {
530 const HttpResponseInfo* response = trans->GetResponseInfo(); 544 const HttpResponseInfo* response = trans->GetResponseInfo();
531 ASSERT_TRUE(response != nullptr); 545 ASSERT_TRUE(response != nullptr);
532 ASSERT_TRUE(response->headers.get() != nullptr); 546 ASSERT_TRUE(response->headers.get() != nullptr);
533 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); 547 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
534 EXPECT_TRUE(response->was_fetched_via_spdy); 548 EXPECT_TRUE(response->was_fetched_via_spdy);
535 EXPECT_TRUE(response->was_alpn_negotiated); 549 EXPECT_TRUE(response->was_alpn_negotiated);
536 EXPECT_EQ(QuicHttpStream::ConnectionInfoFromQuicVersion(version_), 550 EXPECT_EQ(QuicHttpStream::ConnectionInfoFromQuicVersion(version_),
537 response->connection_info); 551 response->connection_info);
538 } 552 }
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
604 uint16_t port) { 618 uint16_t port) {
605 SendRequestAndExpectQuicResponseMaybeFromProxy(expected, true, port); 619 SendRequestAndExpectQuicResponseMaybeFromProxy(expected, true, port);
606 } 620 }
607 621
608 void AddQuicAlternateProtocolMapping( 622 void AddQuicAlternateProtocolMapping(
609 MockCryptoClientStream::HandshakeMode handshake_mode) { 623 MockCryptoClientStream::HandshakeMode handshake_mode) {
610 crypto_client_stream_factory_.set_handshake_mode(handshake_mode); 624 crypto_client_stream_factory_.set_handshake_mode(handshake_mode);
611 url::SchemeHostPort server(request_.url); 625 url::SchemeHostPort server(request_.url);
612 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); 626 AlternativeService alternative_service(kProtoQUIC, server.host(), 443);
613 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); 627 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1);
614 http_server_properties_.SetAlternativeService(server, alternative_service, 628 http_server_properties_.SetQuicAlternativeService(
615 expiration); 629 server, alternative_service, expiration,
630 HttpNetworkSession::Params().quic_supported_versions);
616 } 631 }
617 632
618 void AddQuicRemoteAlternativeServiceMapping( 633 void AddQuicRemoteAlternativeServiceMapping(
619 MockCryptoClientStream::HandshakeMode handshake_mode, 634 MockCryptoClientStream::HandshakeMode handshake_mode,
620 const HostPortPair& alternative) { 635 const HostPortPair& alternative) {
621 crypto_client_stream_factory_.set_handshake_mode(handshake_mode); 636 crypto_client_stream_factory_.set_handshake_mode(handshake_mode);
622 url::SchemeHostPort server(request_.url); 637 url::SchemeHostPort server(request_.url);
623 AlternativeService alternative_service(kProtoQUIC, alternative.host(), 638 AlternativeService alternative_service(kProtoQUIC, alternative.host(),
624 alternative.port()); 639 alternative.port());
625 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); 640 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1);
626 http_server_properties_.SetAlternativeService(server, alternative_service, 641 http_server_properties_.SetQuicAlternativeService(
627 expiration); 642 server, alternative_service, expiration,
643 HttpNetworkSession::Params().quic_supported_versions);
628 } 644 }
629 645
630 void ExpectBrokenAlternateProtocolMapping() { 646 void ExpectBrokenAlternateProtocolMapping() {
631 const url::SchemeHostPort server(request_.url); 647 const url::SchemeHostPort server(request_.url);
632 const AlternativeServiceInfoVector alternative_service_info_vector = 648 const AlternativeServiceInfoVector alternative_service_info_vector =
633 http_server_properties_.GetAlternativeServiceInfos(server); 649 http_server_properties_.GetAlternativeServiceInfos(server);
634 EXPECT_EQ(1u, alternative_service_info_vector.size()); 650 EXPECT_EQ(1u, alternative_service_info_vector.size());
635 EXPECT_TRUE(http_server_properties_.IsAlternativeServiceBroken( 651 EXPECT_TRUE(http_server_properties_.IsAlternativeServiceBroken(
636 alternative_service_info_vector[0].alternative_service())); 652 alternative_service_info_vector[0].alternative_service()));
637 } 653 }
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after
1180 // HttpNetworkTransaction should reset the request and retry without using 1196 // HttpNetworkTransaction should reset the request and retry without using
1181 // alternative services. 1197 // alternative services.
1182 TEST_P(QuicNetworkTransactionTest, RetryMisdirectedRequest) { 1198 TEST_P(QuicNetworkTransactionTest, RetryMisdirectedRequest) {
1183 // Set up alternative service to use QUIC. 1199 // Set up alternative service to use QUIC.
1184 // Note that |origins_to_force_quic_on| cannot be used in this test, because 1200 // Note that |origins_to_force_quic_on| cannot be used in this test, because
1185 // that overrides |enable_alternative_services|. 1201 // that overrides |enable_alternative_services|.
1186 url::SchemeHostPort server(request_.url); 1202 url::SchemeHostPort server(request_.url);
1187 AlternativeService alternative_service(kProtoQUIC, kDefaultServerHostName, 1203 AlternativeService alternative_service(kProtoQUIC, kDefaultServerHostName,
1188 443); 1204 443);
1189 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); 1205 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1);
1190 http_server_properties_.SetAlternativeService(server, alternative_service, 1206 http_server_properties_.SetQuicAlternativeService(
1191 expiration); 1207 server, alternative_service, expiration,
1208 HttpNetworkSession::Params().quic_supported_versions);
1192 1209
1193 // First try: The alternative job uses QUIC and reports an HTTP 421 1210 // First try: The alternative job uses QUIC and reports an HTTP 421
1194 // Misdirected Request error. The main job uses TCP, but |http_data| below is 1211 // Misdirected Request error. The main job uses TCP, but |http_data| below is
1195 // paused at Connect(), so it will never exit the socket pool. This ensures 1212 // paused at Connect(), so it will never exit the socket pool. This ensures
1196 // that the alternate job always wins the race and keeps whether the 1213 // that the alternate job always wins the race and keeps whether the
1197 // |http_data| exits the socket pool before the main job is aborted 1214 // |http_data| exits the socket pool before the main job is aborted
1198 // deterministic. The first main job gets aborted without the socket pool ever 1215 // deterministic. The first main job gets aborted without the socket pool ever
1199 // dispensing the socket, making it available for the second try. 1216 // dispensing the socket, making it available for the second try.
1200 MockQuicData mock_quic_data; 1217 MockQuicData mock_quic_data;
1201 QuicStreamOffset request_header_offset = 0; 1218 QuicStreamOffset request_header_offset = 0;
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
1441 EXPECT_EQ( 1458 EXPECT_EQ(
1442 2u, 1459 2u,
1443 http_server_properties->GetAlternativeServiceInfos(https_server).size()); 1460 http_server_properties->GetAlternativeServiceInfos(https_server).size());
1444 1461
1445 // Send http request to the same origin but with diffrent scheme, should not 1462 // Send http request to the same origin but with diffrent scheme, should not
1446 // use QUIC. 1463 // use QUIC.
1447 request_.url = GURL("http://mail.example.org:443"); 1464 request_.url = GURL("http://mail.example.org:443");
1448 SendRequestAndExpectHttpResponse("hello world"); 1465 SendRequestAndExpectHttpResponse("hello world");
1449 } 1466 }
1450 1467
1468 TEST_P(QuicNetworkTransactionTest,
1469 StoreMutuallySupportedVersionsWhenProcessAltSvc) {
1470 std::string advertised_versions_list_str =
1471 GenerateQuicVersionsListForAltSvcHeader(AllSupportedVersions());
1472 std::string altsvc_header =
1473 base::StringPrintf("Alt-Svc: quic=\":443\"; v=\"%s\"\r\n\r\n",
1474 advertised_versions_list_str.c_str());
1475 MockRead http_reads[] = {
1476 MockRead("HTTP/1.1 200 OK\r\n"), MockRead(altsvc_header.c_str()),
1477 MockRead("hello world"),
1478 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ),
1479 MockRead(ASYNC, OK)};
1480
1481 StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), nullptr,
1482 0);
1483 socket_factory_.AddSocketDataProvider(&http_data);
1484 socket_factory_.AddSSLSocketDataProvider(&ssl_data_);
1485
1486 MockQuicData mock_quic_data;
1487 QuicStreamOffset header_stream_offset = 0;
1488 mock_quic_data.AddWrite(
1489 ConstructInitialSettingsPacket(1, &header_stream_offset));
1490 mock_quic_data.AddWrite(ConstructClientRequestHeadersPacket(
1491 2, GetNthClientInitiatedStreamId(0), true, true,
1492 GetRequestHeaders("GET", "https", "/"), &header_stream_offset));
1493 mock_quic_data.AddRead(ConstructServerResponseHeadersPacket(
1494 1, GetNthClientInitiatedStreamId(0), false, false,
1495 GetResponseHeaders("200 OK")));
1496 mock_quic_data.AddRead(ConstructServerDataPacket(
1497 2, GetNthClientInitiatedStreamId(0), false, true, 0, "hello!"));
1498 mock_quic_data.AddWrite(ConstructClientAckPacket(3, 2, 1, 1));
1499 mock_quic_data.AddRead(ASYNC, ERR_IO_PENDING); // No more data to read
1500 mock_quic_data.AddRead(ASYNC, 0); // EOF
1501
1502 mock_quic_data.AddSocketDataToFactory(&socket_factory_);
1503
1504 AddHangingNonAlternateProtocolSocketData();
1505
1506 // Generate a list of QUIC versions suppored by netstack.
1507 QuicVersionVector current_supported_versions = SupportedVersions(version_);
1508 if (version_ != QUIC_VERSION_40) {
1509 current_supported_versions.push_back(QUIC_VERSION_40);
1510 } else {
1511 current_supported_versions.push_back(QUIC_VERSION_37);
1512 }
1513
1514 CreateSession(current_supported_versions);
1515
1516 SendRequestAndExpectHttpResponse("hello world");
1517 SendRequestAndExpectQuicResponse("hello!");
1518
1519 // Check alternative service is set with only mutually supported versions.
1520 const url::SchemeHostPort https_server(request_.url);
1521 const AlternativeServiceInfoVector alt_svc_info_vector =
1522 session_->http_server_properties()->GetAlternativeServiceInfos(
1523 https_server);
1524 EXPECT_EQ(1u, alt_svc_info_vector.size());
1525 EXPECT_EQ(kProtoQUIC, alt_svc_info_vector[0].alternative_service().protocol);
1526 EXPECT_EQ(2u, alt_svc_info_vector[0].advertised_versions().size());
1527 // Advertised versions will be lised in a sorted order.
1528 std::sort(current_supported_versions.begin(),
1529 current_supported_versions.end());
1530 EXPECT_EQ(current_supported_versions[0],
1531 alt_svc_info_vector[0].advertised_versions()[0]);
1532 EXPECT_EQ(current_supported_versions[1],
1533 alt_svc_info_vector[0].advertised_versions()[1]);
1534 }
1535
1451 TEST_P(QuicNetworkTransactionTest, UseAlternativeServiceAllSupportedVersion) { 1536 TEST_P(QuicNetworkTransactionTest, UseAlternativeServiceAllSupportedVersion) {
1452 std::string altsvc_header = 1537 std::string altsvc_header =
1453 base::StringPrintf("Alt-Svc: quic=\":443\"; v=\"%u\"\r\n\r\n", version_); 1538 base::StringPrintf("Alt-Svc: quic=\":443\"; v=\"%u\"\r\n\r\n", version_);
1454 MockRead http_reads[] = { 1539 MockRead http_reads[] = {
1455 MockRead("HTTP/1.1 200 OK\r\n"), MockRead(altsvc_header.c_str()), 1540 MockRead("HTTP/1.1 200 OK\r\n"), MockRead(altsvc_header.c_str()),
1456 MockRead("hello world"), 1541 MockRead("hello world"),
1457 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), 1542 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ),
1458 MockRead(ASYNC, OK)}; 1543 MockRead(ASYNC, OK)};
1459 1544
1460 StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), nullptr, 1545 StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), nullptr,
(...skipping 1309 matching lines...) Expand 10 before | Expand all | Expand 10 after
2770 mock_quic_data2.AddWrite(ConstructClientAckPacket(3, 2, 1, 1)); 2855 mock_quic_data2.AddWrite(ConstructClientAckPacket(3, 2, 1, 1));
2771 mock_quic_data2.AddRead(ASYNC, ERR_IO_PENDING); // No more data to read 2856 mock_quic_data2.AddRead(ASYNC, ERR_IO_PENDING); // No more data to read
2772 mock_quic_data2.AddRead(ASYNC, 0); // EOF 2857 mock_quic_data2.AddRead(ASYNC, 0); // EOF
2773 2858
2774 mock_quic_data2.AddSocketDataToFactory(&socket_factory_); 2859 mock_quic_data2.AddSocketDataToFactory(&socket_factory_);
2775 2860
2776 CreateSession(); 2861 CreateSession();
2777 2862
2778 // Set up alternative service for |origin1|. 2863 // Set up alternative service for |origin1|.
2779 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); 2864 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1);
2780 http_server_properties_.SetAlternativeService( 2865 http_server_properties_.SetQuicAlternativeService(
2781 url::SchemeHostPort(origin1), 2866 url::SchemeHostPort(origin1),
2782 AlternativeService(kProtoQUIC, "mail.example.com", 443), expiration); 2867 AlternativeService(kProtoQUIC, "mail.example.com", 443), expiration,
2868 HttpNetworkSession::Params().quic_supported_versions);
2783 2869
2784 // Set up alternative service for |origin2|. 2870 // Set up alternative service for |origin2|.
2785 AlternativeServiceInfoVector alternative_services; 2871 AlternativeServiceInfoVector alternative_services;
2786 http_server_properties_.SetAlternativeService( 2872 http_server_properties_.SetQuicAlternativeService(
2787 url::SchemeHostPort(origin2), 2873 url::SchemeHostPort(origin2),
2788 AlternativeService(kProtoQUIC, "www.example.com", 443), expiration); 2874 AlternativeService(kProtoQUIC, "www.example.com", 443), expiration,
2875 HttpNetworkSession::Params().quic_supported_versions);
2789 // First request opens connection to |destination1| 2876 // First request opens connection to |destination1|
2790 // with QuicServerId.host() == origin1.host(). 2877 // with QuicServerId.host() == origin1.host().
2791 SendRequestAndExpectQuicResponse("hello!"); 2878 SendRequestAndExpectQuicResponse("hello!");
2792 2879
2793 // Second request pools to existing connection with same destination, 2880 // Second request pools to existing connection with same destination,
2794 // because certificate matches, even though QuicServerId is different. 2881 // because certificate matches, even though QuicServerId is different.
2795 // After it is reset, it will fail back to QUIC and mark QUIC as broken. 2882 // After it is reset, it will fail back to QUIC and mark QUIC as broken.
2796 request_.url = origin2; 2883 request_.url = origin2;
2797 SendRequestAndExpectHttpResponse("hello world"); 2884 SendRequestAndExpectHttpResponse("hello world");
2798 2885
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
3001 3088
3002 CreateSession(); 3089 CreateSession();
3003 3090
3004 const char destination1[] = "first.example.com"; 3091 const char destination1[] = "first.example.com";
3005 const char destination2[] = "second.example.com"; 3092 const char destination2[] = "second.example.com";
3006 3093
3007 // Set up alternative service entry to destination1. 3094 // Set up alternative service entry to destination1.
3008 url::SchemeHostPort server(request_.url); 3095 url::SchemeHostPort server(request_.url);
3009 AlternativeService alternative_service(kProtoQUIC, destination1, 443); 3096 AlternativeService alternative_service(kProtoQUIC, destination1, 443);
3010 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); 3097 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1);
3011 http_server_properties_.SetAlternativeService(server, alternative_service, 3098 http_server_properties_.SetQuicAlternativeService(
3012 expiration); 3099 server, alternative_service, expiration,
3100 HttpNetworkSession::Params().quic_supported_versions);
3013 // First request opens connection to |destination1| 3101 // First request opens connection to |destination1|
3014 // with QuicServerId.host() == kDefaultServerHostName. 3102 // with QuicServerId.host() == kDefaultServerHostName.
3015 SendRequestAndExpectQuicResponse("hello!"); 3103 SendRequestAndExpectQuicResponse("hello!");
3016 3104
3017 // Set up alternative service entry to a different destination. 3105 // Set up alternative service entry to a different destination.
3018 alternative_service = AlternativeService(kProtoQUIC, destination2, 443); 3106 alternative_service = AlternativeService(kProtoQUIC, destination2, 443);
3019 http_server_properties_.SetAlternativeService(server, alternative_service, 3107 http_server_properties_.SetQuicAlternativeService(
3020 expiration); 3108 server, alternative_service, expiration,
3109 HttpNetworkSession::Params().quic_supported_versions);
3021 // Second request pools to existing connection with same QuicServerId, 3110 // Second request pools to existing connection with same QuicServerId,
3022 // even though alternative service destination is different. 3111 // even though alternative service destination is different.
3023 SendRequestAndExpectQuicResponse("hello!"); 3112 SendRequestAndExpectQuicResponse("hello!");
3024 } 3113 }
3025 3114
3026 // Pool to existing session with matching destination and matching certificate 3115 // Pool to existing session with matching destination and matching certificate
3027 // even if origin is different, and even if the alternative service with 3116 // even if origin is different, and even if the alternative service with
3028 // matching destination is not the first one on the list. 3117 // matching destination is not the first one on the list.
3029 TEST_P(QuicNetworkTransactionTest, PoolByDestination) { 3118 TEST_P(QuicNetworkTransactionTest, PoolByDestination) {
3030 GURL origin1 = request_.url; 3119 GURL origin1 = request_.url;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
3073 AddHangingNonAlternateProtocolSocketData(); 3162 AddHangingNonAlternateProtocolSocketData();
3074 3163
3075 CreateSession(); 3164 CreateSession();
3076 3165
3077 const char destination1[] = "first.example.com"; 3166 const char destination1[] = "first.example.com";
3078 const char destination2[] = "second.example.com"; 3167 const char destination2[] = "second.example.com";
3079 3168
3080 // Set up alternative service for |origin1|. 3169 // Set up alternative service for |origin1|.
3081 AlternativeService alternative_service1(kProtoQUIC, destination1, 443); 3170 AlternativeService alternative_service1(kProtoQUIC, destination1, 443);
3082 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); 3171 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1);
3083 http_server_properties_.SetAlternativeService( 3172 http_server_properties_.SetQuicAlternativeService(
3084 url::SchemeHostPort(origin1), alternative_service1, expiration); 3173 url::SchemeHostPort(origin1), alternative_service1, expiration,
3174 HttpNetworkSession::Params().quic_supported_versions);
3085 3175
3086 // Set up multiple alternative service entries for |origin2|, 3176 // Set up multiple alternative service entries for |origin2|,
3087 // the first one with a different destination as for |origin1|, 3177 // the first one with a different destination as for |origin1|,
3088 // the second one with the same. The second one should be used, 3178 // the second one with the same. The second one should be used,
3089 // because the request can be pooled to that one. 3179 // because the request can be pooled to that one.
3090 AlternativeService alternative_service2(kProtoQUIC, destination2, 443); 3180 AlternativeService alternative_service2(kProtoQUIC, destination2, 443);
3091 AlternativeServiceInfoVector alternative_services; 3181 AlternativeServiceInfoVector alternative_services;
3092 alternative_services.push_back( 3182 alternative_services.push_back(
3093 AlternativeServiceInfo(alternative_service2, expiration)); 3183 AlternativeServiceInfo::CreateQuicAlternativeServiceInfo(
3184 alternative_service2, expiration,
3185 session_->params().quic_supported_versions));
3094 alternative_services.push_back( 3186 alternative_services.push_back(
3095 AlternativeServiceInfo(alternative_service1, expiration)); 3187 AlternativeServiceInfo::CreateQuicAlternativeServiceInfo(
3188 alternative_service1, expiration,
3189 session_->params().quic_supported_versions));
3096 http_server_properties_.SetAlternativeServices(url::SchemeHostPort(origin2), 3190 http_server_properties_.SetAlternativeServices(url::SchemeHostPort(origin2),
3097 alternative_services); 3191 alternative_services);
3098 // First request opens connection to |destination1| 3192 // First request opens connection to |destination1|
3099 // with QuicServerId.host() == origin1.host(). 3193 // with QuicServerId.host() == origin1.host().
3100 SendRequestAndExpectQuicResponse("hello!"); 3194 SendRequestAndExpectQuicResponse("hello!");
3101 3195
3102 // Second request pools to existing connection with same destination, 3196 // Second request pools to existing connection with same destination,
3103 // because certificate matches, even though QuicServerId is different. 3197 // because certificate matches, even though QuicServerId is different.
3104 request_.url = origin2; 3198 request_.url = origin2;
3105 3199
(...skipping 1540 matching lines...) Expand 10 before | Expand all | Expand 10 after
4646 void TearDown() override { 4740 void TearDown() override {
4647 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); 4741 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests();
4648 // Empty the current queue. 4742 // Empty the current queue.
4649 base::RunLoop().RunUntilIdle(); 4743 base::RunLoop().RunUntilIdle();
4650 PlatformTest::TearDown(); 4744 PlatformTest::TearDown();
4651 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); 4745 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests();
4652 base::RunLoop().RunUntilIdle(); 4746 base::RunLoop().RunUntilIdle();
4653 session_.reset(); 4747 session_.reset();
4654 } 4748 }
4655 4749
4656 void SetAlternativeService(const std::string& origin) { 4750 void SetQuicAlternativeService(const std::string& origin) {
4657 HostPortPair destination; 4751 HostPortPair destination;
4658 switch (destination_type_) { 4752 switch (destination_type_) {
4659 case SAME_AS_FIRST: 4753 case SAME_AS_FIRST:
4660 destination = HostPortPair(origin1_, 443); 4754 destination = HostPortPair(origin1_, 443);
4661 break; 4755 break;
4662 case SAME_AS_SECOND: 4756 case SAME_AS_SECOND:
4663 destination = HostPortPair(origin2_, 443); 4757 destination = HostPortPair(origin2_, 443);
4664 break; 4758 break;
4665 case DIFFERENT: 4759 case DIFFERENT:
4666 destination = HostPortPair(kDifferentHostname, 443); 4760 destination = HostPortPair(kDifferentHostname, 443);
4667 break; 4761 break;
4668 } 4762 }
4669 AlternativeService alternative_service(kProtoQUIC, destination); 4763 AlternativeService alternative_service(kProtoQUIC, destination);
4670 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); 4764 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1);
4671 http_server_properties_.SetAlternativeService( 4765 http_server_properties_.SetQuicAlternativeService(
4672 url::SchemeHostPort("https", origin, 443), alternative_service, 4766 url::SchemeHostPort("https", origin, 443), alternative_service,
4673 expiration); 4767 expiration, session_->params().quic_supported_versions);
4674 } 4768 }
4675 4769
4676 std::unique_ptr<QuicEncryptedPacket> ConstructClientRequestHeadersPacket( 4770 std::unique_ptr<QuicEncryptedPacket> ConstructClientRequestHeadersPacket(
4677 QuicPacketNumber packet_number, 4771 QuicPacketNumber packet_number,
4678 QuicStreamId stream_id, 4772 QuicStreamId stream_id,
4679 bool should_include_version, 4773 bool should_include_version,
4680 QuicStreamOffset* offset, 4774 QuicStreamOffset* offset,
4681 QuicTestPacketMaker* maker) { 4775 QuicTestPacketMaker* maker) {
4682 SpdyPriority priority = 4776 SpdyPriority priority =
4683 ConvertRequestPriorityToQuicPriority(DEFAULT_PRIORITY); 4777 ConvertRequestPriorityToQuicPriority(DEFAULT_PRIORITY);
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
4834 if (destination_type_ == DIFFERENT) 4928 if (destination_type_ == DIFFERENT)
4835 return; 4929 return;
4836 4930
4837 GURL url("https://mail.example.com/"); 4931 GURL url("https://mail.example.com/");
4838 origin1_ = url.host(); 4932 origin1_ = url.host();
4839 4933
4840 // Not used for requests, but this provides a test case where the certificate 4934 // Not used for requests, but this provides a test case where the certificate
4841 // is valid for the hostname of the alternative service. 4935 // is valid for the hostname of the alternative service.
4842 origin2_ = "mail.example.org"; 4936 origin2_ = "mail.example.org";
4843 4937
4844 SetAlternativeService(origin1_); 4938 SetQuicAlternativeService(origin1_);
4845 4939
4846 scoped_refptr<X509Certificate> cert( 4940 scoped_refptr<X509Certificate> cert(
4847 ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem")); 4941 ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"));
4848 ASSERT_FALSE(cert->VerifyNameMatch(origin1_, false)); 4942 ASSERT_FALSE(cert->VerifyNameMatch(origin1_, false));
4849 ASSERT_TRUE(cert->VerifyNameMatch(origin2_, false)); 4943 ASSERT_TRUE(cert->VerifyNameMatch(origin2_, false));
4850 4944
4851 ProofVerifyDetailsChromium verify_details; 4945 ProofVerifyDetailsChromium verify_details;
4852 verify_details.cert_verify_result.verified_cert = cert; 4946 verify_details.cert_verify_result.verified_cert = cert;
4853 verify_details.cert_verify_result.is_issued_by_known_root = true; 4947 verify_details.cert_verify_result.is_issued_by_known_root = true;
4854 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); 4948 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details);
(...skipping 17 matching lines...) Expand all
4872 EXPECT_TRUE(AllDataConsumed()); 4966 EXPECT_TRUE(AllDataConsumed());
4873 } 4967 }
4874 4968
4875 // First request opens QUIC session to alternative service. Second request 4969 // First request opens QUIC session to alternative service. Second request
4876 // pools to it, because destination matches and certificate is valid, even 4970 // pools to it, because destination matches and certificate is valid, even
4877 // though QuicServerId is different. 4971 // though QuicServerId is different.
4878 TEST_P(QuicNetworkTransactionWithDestinationTest, PoolIfCertificateValid) { 4972 TEST_P(QuicNetworkTransactionWithDestinationTest, PoolIfCertificateValid) {
4879 origin1_ = "mail.example.org"; 4973 origin1_ = "mail.example.org";
4880 origin2_ = "news.example.org"; 4974 origin2_ = "news.example.org";
4881 4975
4882 SetAlternativeService(origin1_); 4976 SetQuicAlternativeService(origin1_);
4883 SetAlternativeService(origin2_); 4977 SetQuicAlternativeService(origin2_);
4884 4978
4885 scoped_refptr<X509Certificate> cert( 4979 scoped_refptr<X509Certificate> cert(
4886 ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem")); 4980 ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"));
4887 ASSERT_TRUE(cert->VerifyNameMatch(origin1_, false)); 4981 ASSERT_TRUE(cert->VerifyNameMatch(origin1_, false));
4888 ASSERT_TRUE(cert->VerifyNameMatch(origin2_, false)); 4982 ASSERT_TRUE(cert->VerifyNameMatch(origin2_, false));
4889 ASSERT_FALSE(cert->VerifyNameMatch(kDifferentHostname, false)); 4983 ASSERT_FALSE(cert->VerifyNameMatch(kDifferentHostname, false));
4890 4984
4891 ProofVerifyDetailsChromium verify_details; 4985 ProofVerifyDetailsChromium verify_details;
4892 verify_details.cert_verify_result.verified_cert = cert; 4986 verify_details.cert_verify_result.verified_cert = cert;
4893 verify_details.cert_verify_result.is_issued_by_known_root = true; 4987 verify_details.cert_verify_result.is_issued_by_known_root = true;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
4944 5038
4945 // First request opens QUIC session to alternative service. Second request does 5039 // First request opens QUIC session to alternative service. Second request does
4946 // not pool to it, even though destination matches, because certificate is not 5040 // not pool to it, even though destination matches, because certificate is not
4947 // valid. Instead, a new QUIC session is opened to the same destination with a 5041 // valid. Instead, a new QUIC session is opened to the same destination with a
4948 // different QuicServerId. 5042 // different QuicServerId.
4949 TEST_P(QuicNetworkTransactionWithDestinationTest, 5043 TEST_P(QuicNetworkTransactionWithDestinationTest,
4950 DoNotPoolIfCertificateInvalid) { 5044 DoNotPoolIfCertificateInvalid) {
4951 origin1_ = "news.example.org"; 5045 origin1_ = "news.example.org";
4952 origin2_ = "mail.example.com"; 5046 origin2_ = "mail.example.com";
4953 5047
4954 SetAlternativeService(origin1_); 5048 SetQuicAlternativeService(origin1_);
4955 SetAlternativeService(origin2_); 5049 SetQuicAlternativeService(origin2_);
4956 5050
4957 scoped_refptr<X509Certificate> cert1( 5051 scoped_refptr<X509Certificate> cert1(
4958 ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem")); 5052 ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"));
4959 ASSERT_TRUE(cert1->VerifyNameMatch(origin1_, false)); 5053 ASSERT_TRUE(cert1->VerifyNameMatch(origin1_, false));
4960 ASSERT_FALSE(cert1->VerifyNameMatch(origin2_, false)); 5054 ASSERT_FALSE(cert1->VerifyNameMatch(origin2_, false));
4961 ASSERT_FALSE(cert1->VerifyNameMatch(kDifferentHostname, false)); 5055 ASSERT_FALSE(cert1->VerifyNameMatch(kDifferentHostname, false));
4962 5056
4963 scoped_refptr<X509Certificate> cert2( 5057 scoped_refptr<X509Certificate> cert2(
4964 ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem")); 5058 ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"));
4965 ASSERT_TRUE(cert2->VerifyNameMatch(origin2_, false)); 5059 ASSERT_TRUE(cert2->VerifyNameMatch(origin2_, false));
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
5098 5192
5099 request_.url = GURL("https://mail.example.org/pushed.jpg"); 5193 request_.url = GURL("https://mail.example.org/pushed.jpg");
5100 ChunkedUploadDataStream upload_data(0); 5194 ChunkedUploadDataStream upload_data(0);
5101 upload_data.AppendData("1", 1, true); 5195 upload_data.AppendData("1", 1, true);
5102 request_.upload_data_stream = &upload_data; 5196 request_.upload_data_stream = &upload_data;
5103 SendRequestAndExpectQuicResponse("and hello!"); 5197 SendRequestAndExpectQuicResponse("and hello!");
5104 } 5198 }
5105 5199
5106 } // namespace test 5200 } // namespace test
5107 } // namespace net 5201 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_stream_factory_impl_unittest.cc ('k') | net/quic/chromium/quic_stream_factory_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698