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

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 cronet/grpc Created 3 years, 6 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 1316 matching lines...) Expand 10 before | Expand all | Expand 10 after
2777 2862
2778 CreateSession(); 2863 CreateSession();
2779 2864
2780 const char destination1[] = "first.example.com"; 2865 const char destination1[] = "first.example.com";
2781 const char destination2[] = "second.example.com"; 2866 const char destination2[] = "second.example.com";
2782 2867
2783 // Set up alternative service entry to destination1. 2868 // Set up alternative service entry to destination1.
2784 url::SchemeHostPort server(request_.url); 2869 url::SchemeHostPort server(request_.url);
2785 AlternativeService alternative_service(kProtoQUIC, destination1, 443); 2870 AlternativeService alternative_service(kProtoQUIC, destination1, 443);
2786 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); 2871 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1);
2787 http_server_properties_.SetAlternativeService(server, alternative_service, 2872 http_server_properties_.SetQuicAlternativeService(
2788 expiration); 2873 server, alternative_service, expiration,
2874 HttpNetworkSession::Params().quic_supported_versions);
2789 // First request opens connection to |destination1| 2875 // First request opens connection to |destination1|
2790 // with QuicServerId.host() == kDefaultServerHostName. 2876 // with QuicServerId.host() == kDefaultServerHostName.
2791 SendRequestAndExpectQuicResponse("hello!"); 2877 SendRequestAndExpectQuicResponse("hello!");
2792 2878
2793 // Set up alternative service entry to a different destination. 2879 // Set up alternative service entry to a different destination.
2794 alternative_service = AlternativeService(kProtoQUIC, destination2, 443); 2880 alternative_service = AlternativeService(kProtoQUIC, destination2, 443);
2795 http_server_properties_.SetAlternativeService(server, alternative_service, 2881 http_server_properties_.SetQuicAlternativeService(
2796 expiration); 2882 server, alternative_service, expiration,
2883 HttpNetworkSession::Params().quic_supported_versions);
2797 // Second request pools to existing connection with same QuicServerId, 2884 // Second request pools to existing connection with same QuicServerId,
2798 // even though alternative service destination is different. 2885 // even though alternative service destination is different.
2799 SendRequestAndExpectQuicResponse("hello!"); 2886 SendRequestAndExpectQuicResponse("hello!");
2800 } 2887 }
2801 2888
2802 // Pool to existing session with matching destination and matching certificate 2889 // Pool to existing session with matching destination and matching certificate
2803 // even if origin is different, and even if the alternative service with 2890 // even if origin is different, and even if the alternative service with
2804 // matching destination is not the first one on the list. 2891 // matching destination is not the first one on the list.
2805 TEST_P(QuicNetworkTransactionTest, PoolByDestination) { 2892 TEST_P(QuicNetworkTransactionTest, PoolByDestination) {
2806 GURL origin1 = request_.url; 2893 GURL origin1 = request_.url;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
2849 AddHangingNonAlternateProtocolSocketData(); 2936 AddHangingNonAlternateProtocolSocketData();
2850 2937
2851 CreateSession(); 2938 CreateSession();
2852 2939
2853 const char destination1[] = "first.example.com"; 2940 const char destination1[] = "first.example.com";
2854 const char destination2[] = "second.example.com"; 2941 const char destination2[] = "second.example.com";
2855 2942
2856 // Set up alternative service for |origin1|. 2943 // Set up alternative service for |origin1|.
2857 AlternativeService alternative_service1(kProtoQUIC, destination1, 443); 2944 AlternativeService alternative_service1(kProtoQUIC, destination1, 443);
2858 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); 2945 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1);
2859 http_server_properties_.SetAlternativeService( 2946 http_server_properties_.SetQuicAlternativeService(
2860 url::SchemeHostPort(origin1), alternative_service1, expiration); 2947 url::SchemeHostPort(origin1), alternative_service1, expiration,
2948 HttpNetworkSession::Params().quic_supported_versions);
2861 2949
2862 // Set up multiple alternative service entries for |origin2|, 2950 // Set up multiple alternative service entries for |origin2|,
2863 // the first one with a different destination as for |origin1|, 2951 // the first one with a different destination as for |origin1|,
2864 // the second one with the same. The second one should be used, 2952 // the second one with the same. The second one should be used,
2865 // because the request can be pooled to that one. 2953 // because the request can be pooled to that one.
2866 AlternativeService alternative_service2(kProtoQUIC, destination2, 443); 2954 AlternativeService alternative_service2(kProtoQUIC, destination2, 443);
2867 AlternativeServiceInfoVector alternative_services; 2955 AlternativeServiceInfoVector alternative_services;
2868 alternative_services.push_back( 2956 alternative_services.push_back(
2869 AlternativeServiceInfo(alternative_service2, expiration)); 2957 AlternativeServiceInfo::CreateQuicAlternativeServiceInfo(
2958 alternative_service2, expiration,
2959 session_->params().quic_supported_versions));
2870 alternative_services.push_back( 2960 alternative_services.push_back(
2871 AlternativeServiceInfo(alternative_service1, expiration)); 2961 AlternativeServiceInfo::CreateQuicAlternativeServiceInfo(
2962 alternative_service1, expiration,
2963 session_->params().quic_supported_versions));
2872 http_server_properties_.SetAlternativeServices(url::SchemeHostPort(origin2), 2964 http_server_properties_.SetAlternativeServices(url::SchemeHostPort(origin2),
2873 alternative_services); 2965 alternative_services);
2874 // First request opens connection to |destination1| 2966 // First request opens connection to |destination1|
2875 // with QuicServerId.host() == origin1.host(). 2967 // with QuicServerId.host() == origin1.host().
2876 SendRequestAndExpectQuicResponse("hello!"); 2968 SendRequestAndExpectQuicResponse("hello!");
2877 2969
2878 // Second request pools to existing connection with same destination, 2970 // Second request pools to existing connection with same destination,
2879 // because certificate matches, even though QuicServerId is different. 2971 // because certificate matches, even though QuicServerId is different.
2880 request_.url = origin2; 2972 request_.url = origin2;
2881 2973
(...skipping 1469 matching lines...) Expand 10 before | Expand all | Expand 10 after
4351 void TearDown() override { 4443 void TearDown() override {
4352 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); 4444 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests();
4353 // Empty the current queue. 4445 // Empty the current queue.
4354 base::RunLoop().RunUntilIdle(); 4446 base::RunLoop().RunUntilIdle();
4355 PlatformTest::TearDown(); 4447 PlatformTest::TearDown();
4356 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); 4448 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests();
4357 base::RunLoop().RunUntilIdle(); 4449 base::RunLoop().RunUntilIdle();
4358 session_.reset(); 4450 session_.reset();
4359 } 4451 }
4360 4452
4361 void SetAlternativeService(const std::string& origin) { 4453 void SetQuicAlternativeService(const std::string& origin) {
4362 HostPortPair destination; 4454 HostPortPair destination;
4363 switch (destination_type_) { 4455 switch (destination_type_) {
4364 case SAME_AS_FIRST: 4456 case SAME_AS_FIRST:
4365 destination = HostPortPair(origin1_, 443); 4457 destination = HostPortPair(origin1_, 443);
4366 break; 4458 break;
4367 case SAME_AS_SECOND: 4459 case SAME_AS_SECOND:
4368 destination = HostPortPair(origin2_, 443); 4460 destination = HostPortPair(origin2_, 443);
4369 break; 4461 break;
4370 case DIFFERENT: 4462 case DIFFERENT:
4371 destination = HostPortPair(kDifferentHostname, 443); 4463 destination = HostPortPair(kDifferentHostname, 443);
4372 break; 4464 break;
4373 } 4465 }
4374 AlternativeService alternative_service(kProtoQUIC, destination); 4466 AlternativeService alternative_service(kProtoQUIC, destination);
4375 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); 4467 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1);
4376 http_server_properties_.SetAlternativeService( 4468 http_server_properties_.SetQuicAlternativeService(
4377 url::SchemeHostPort("https", origin, 443), alternative_service, 4469 url::SchemeHostPort("https", origin, 443), alternative_service,
4378 expiration); 4470 expiration, session_->params().quic_supported_versions);
4379 } 4471 }
4380 4472
4381 std::unique_ptr<QuicEncryptedPacket> ConstructClientRequestHeadersPacket( 4473 std::unique_ptr<QuicEncryptedPacket> ConstructClientRequestHeadersPacket(
4382 QuicPacketNumber packet_number, 4474 QuicPacketNumber packet_number,
4383 QuicStreamId stream_id, 4475 QuicStreamId stream_id,
4384 bool should_include_version, 4476 bool should_include_version,
4385 QuicStreamOffset* offset, 4477 QuicStreamOffset* offset,
4386 QuicTestPacketMaker* maker) { 4478 QuicTestPacketMaker* maker) {
4387 SpdyPriority priority = 4479 SpdyPriority priority =
4388 ConvertRequestPriorityToQuicPriority(DEFAULT_PRIORITY); 4480 ConvertRequestPriorityToQuicPriority(DEFAULT_PRIORITY);
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
4539 if (destination_type_ == DIFFERENT) 4631 if (destination_type_ == DIFFERENT)
4540 return; 4632 return;
4541 4633
4542 GURL url("https://mail.example.com/"); 4634 GURL url("https://mail.example.com/");
4543 origin1_ = url.host(); 4635 origin1_ = url.host();
4544 4636
4545 // Not used for requests, but this provides a test case where the certificate 4637 // Not used for requests, but this provides a test case where the certificate
4546 // is valid for the hostname of the alternative service. 4638 // is valid for the hostname of the alternative service.
4547 origin2_ = "mail.example.org"; 4639 origin2_ = "mail.example.org";
4548 4640
4549 SetAlternativeService(origin1_); 4641 SetQuicAlternativeService(origin1_);
4550 4642
4551 scoped_refptr<X509Certificate> cert( 4643 scoped_refptr<X509Certificate> cert(
4552 ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem")); 4644 ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"));
4553 ASSERT_FALSE(cert->VerifyNameMatch(origin1_, false)); 4645 ASSERT_FALSE(cert->VerifyNameMatch(origin1_, false));
4554 ASSERT_TRUE(cert->VerifyNameMatch(origin2_, false)); 4646 ASSERT_TRUE(cert->VerifyNameMatch(origin2_, false));
4555 4647
4556 ProofVerifyDetailsChromium verify_details; 4648 ProofVerifyDetailsChromium verify_details;
4557 verify_details.cert_verify_result.verified_cert = cert; 4649 verify_details.cert_verify_result.verified_cert = cert;
4558 verify_details.cert_verify_result.is_issued_by_known_root = true; 4650 verify_details.cert_verify_result.is_issued_by_known_root = true;
4559 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); 4651 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details);
(...skipping 17 matching lines...) Expand all
4577 EXPECT_TRUE(AllDataConsumed()); 4669 EXPECT_TRUE(AllDataConsumed());
4578 } 4670 }
4579 4671
4580 // First request opens QUIC session to alternative service. Second request 4672 // First request opens QUIC session to alternative service. Second request
4581 // pools to it, because destination matches and certificate is valid, even 4673 // pools to it, because destination matches and certificate is valid, even
4582 // though QuicServerId is different. 4674 // though QuicServerId is different.
4583 TEST_P(QuicNetworkTransactionWithDestinationTest, PoolIfCertificateValid) { 4675 TEST_P(QuicNetworkTransactionWithDestinationTest, PoolIfCertificateValid) {
4584 origin1_ = "mail.example.org"; 4676 origin1_ = "mail.example.org";
4585 origin2_ = "news.example.org"; 4677 origin2_ = "news.example.org";
4586 4678
4587 SetAlternativeService(origin1_); 4679 SetQuicAlternativeService(origin1_);
4588 SetAlternativeService(origin2_); 4680 SetQuicAlternativeService(origin2_);
4589 4681
4590 scoped_refptr<X509Certificate> cert( 4682 scoped_refptr<X509Certificate> cert(
4591 ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem")); 4683 ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"));
4592 ASSERT_TRUE(cert->VerifyNameMatch(origin1_, false)); 4684 ASSERT_TRUE(cert->VerifyNameMatch(origin1_, false));
4593 ASSERT_TRUE(cert->VerifyNameMatch(origin2_, false)); 4685 ASSERT_TRUE(cert->VerifyNameMatch(origin2_, false));
4594 ASSERT_FALSE(cert->VerifyNameMatch(kDifferentHostname, false)); 4686 ASSERT_FALSE(cert->VerifyNameMatch(kDifferentHostname, false));
4595 4687
4596 ProofVerifyDetailsChromium verify_details; 4688 ProofVerifyDetailsChromium verify_details;
4597 verify_details.cert_verify_result.verified_cert = cert; 4689 verify_details.cert_verify_result.verified_cert = cert;
4598 verify_details.cert_verify_result.is_issued_by_known_root = true; 4690 verify_details.cert_verify_result.is_issued_by_known_root = true;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
4649 4741
4650 // First request opens QUIC session to alternative service. Second request does 4742 // First request opens QUIC session to alternative service. Second request does
4651 // not pool to it, even though destination matches, because certificate is not 4743 // not pool to it, even though destination matches, because certificate is not
4652 // valid. Instead, a new QUIC session is opened to the same destination with a 4744 // valid. Instead, a new QUIC session is opened to the same destination with a
4653 // different QuicServerId. 4745 // different QuicServerId.
4654 TEST_P(QuicNetworkTransactionWithDestinationTest, 4746 TEST_P(QuicNetworkTransactionWithDestinationTest,
4655 DoNotPoolIfCertificateInvalid) { 4747 DoNotPoolIfCertificateInvalid) {
4656 origin1_ = "news.example.org"; 4748 origin1_ = "news.example.org";
4657 origin2_ = "mail.example.com"; 4749 origin2_ = "mail.example.com";
4658 4750
4659 SetAlternativeService(origin1_); 4751 SetQuicAlternativeService(origin1_);
4660 SetAlternativeService(origin2_); 4752 SetQuicAlternativeService(origin2_);
4661 4753
4662 scoped_refptr<X509Certificate> cert1( 4754 scoped_refptr<X509Certificate> cert1(
4663 ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem")); 4755 ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"));
4664 ASSERT_TRUE(cert1->VerifyNameMatch(origin1_, false)); 4756 ASSERT_TRUE(cert1->VerifyNameMatch(origin1_, false));
4665 ASSERT_FALSE(cert1->VerifyNameMatch(origin2_, false)); 4757 ASSERT_FALSE(cert1->VerifyNameMatch(origin2_, false));
4666 ASSERT_FALSE(cert1->VerifyNameMatch(kDifferentHostname, false)); 4758 ASSERT_FALSE(cert1->VerifyNameMatch(kDifferentHostname, false));
4667 4759
4668 scoped_refptr<X509Certificate> cert2( 4760 scoped_refptr<X509Certificate> cert2(
4669 ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem")); 4761 ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"));
4670 ASSERT_TRUE(cert2->VerifyNameMatch(origin2_, false)); 4762 ASSERT_TRUE(cert2->VerifyNameMatch(origin2_, false));
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
4803 4895
4804 request_.url = GURL("https://mail.example.org/pushed.jpg"); 4896 request_.url = GURL("https://mail.example.org/pushed.jpg");
4805 ChunkedUploadDataStream upload_data(0); 4897 ChunkedUploadDataStream upload_data(0);
4806 upload_data.AppendData("1", 1, true); 4898 upload_data.AppendData("1", 1, true);
4807 request_.upload_data_stream = &upload_data; 4899 request_.upload_data_stream = &upload_data;
4808 SendRequestAndExpectQuicResponse("and hello!"); 4900 SendRequestAndExpectQuicResponse("and hello!");
4809 } 4901 }
4810 4902
4811 } // namespace test 4903 } // namespace test
4812 } // namespace net 4904 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698