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

Side by Side Diff: net/http/http_network_transaction_unittest.cc

Issue 2026293002: Disable HTTP/2 Alternative Service for different host. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2743
Patch Set: Created 4 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
« no previous file with comments | « no previous file | net/http/http_stream_factory_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/http/http_network_transaction.h" 5 #include "net/http/http_network_transaction.h"
6 6
7 #include <math.h> // ceil 7 #include <math.h> // ceil
8 #include <stdarg.h> 8 #include <stdarg.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 return GetParam() == kTestCaseHTTP2PriorityDependencies; 320 return GetParam() == kTestCaseHTTP2PriorityDependencies;
321 } 321 }
322 322
323 const char* GetAlternateProtocolFromParam() { 323 const char* GetAlternateProtocolFromParam() {
324 return AlternateProtocolToString( 324 return AlternateProtocolToString(
325 AlternateProtocolFromNextProto(GetProtocol())); 325 AlternateProtocolFromNextProto(GetProtocol()));
326 } 326 }
327 327
328 std::string GetAlternativeServiceHttpHeader() { 328 std::string GetAlternativeServiceHttpHeader() {
329 return std::string("Alt-Svc: ") + GetAlternateProtocolFromParam() + 329 return std::string("Alt-Svc: ") + GetAlternateProtocolFromParam() +
330 "=\"www.example.com:443\"\r\n"; 330 "=\"www.example.org:443\"\r\n";
331 } 331 }
332 332
333 std::string GetAlternateProtocolHttpHeader() { 333 std::string GetAlternateProtocolHttpHeader() {
334 return std::string("Alternate-Protocol: 443:") + 334 return std::string("Alternate-Protocol: 443:") +
335 GetAlternateProtocolFromParam() + "\r\n"; 335 GetAlternateProtocolFromParam() + "\r\n";
336 } 336 }
337 337
338 // Either |write_failure| specifies a write failure or |read_failure| 338 // Either |write_failure| specifies a write failure or |read_failure|
339 // specifies a read failure when using a reused socket. In either case, the 339 // specifies a read failure when using a reused socket. In either case, the
340 // failure should cause the network transaction to resend the request, and the 340 // failure should cause the network transaction to resend the request, and the
(...skipping 9365 matching lines...) Expand 10 before | Expand all | Expand 10 after
9706 9706
9707 std::string response_data; 9707 std::string response_data;
9708 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); 9708 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data));
9709 EXPECT_EQ("hello world", response_data); 9709 EXPECT_EQ("hello world", response_data);
9710 9710
9711 alternative_service_vector = 9711 alternative_service_vector =
9712 http_server_properties.GetAlternativeServices(test_server); 9712 http_server_properties.GetAlternativeServices(test_server);
9713 ASSERT_EQ(1u, alternative_service_vector.size()); 9713 ASSERT_EQ(1u, alternative_service_vector.size());
9714 EXPECT_EQ(AlternateProtocolFromNextProto(GetProtocol()), 9714 EXPECT_EQ(AlternateProtocolFromNextProto(GetProtocol()),
9715 alternative_service_vector[0].protocol); 9715 alternative_service_vector[0].protocol);
9716 EXPECT_EQ("www.example.com", alternative_service_vector[0].host); 9716 EXPECT_EQ("www.example.org", alternative_service_vector[0].host);
9717 EXPECT_EQ(443, alternative_service_vector[0].port); 9717 EXPECT_EQ(443, alternative_service_vector[0].port);
9718 } 9718 }
9719 9719
9720 // HTTP/2 Alternative Services should be disabled if alternative service
9721 // hostname is different from that of origin.
9722 // TODO(bnc): Remove when https://crbug.com/615413 is fixed.
9723 TEST_P(HttpNetworkTransactionTest,
9724 DisableHTTP2AlternativeServicesWithDifferentHost) {
9725 session_deps_.enable_alternative_service_with_different_host = true;
9726
9727 HttpRequestInfo request;
9728 request.method = "GET";
9729 request.url = GURL("http://www.example.org/");
9730 request.load_flags = 0;
9731
9732 MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED);
9733 StaticSocketDataProvider first_data;
9734 first_data.set_connect_data(mock_connect);
9735 session_deps_.socket_factory->AddSocketDataProvider(&first_data);
9736
9737 MockRead data_reads[] = {
9738 MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"),
9739 MockRead(ASYNC, OK),
9740 };
9741 StaticSocketDataProvider second_data(data_reads, arraysize(data_reads), NULL,
9742 0);
9743 session_deps_.socket_factory->AddSocketDataProvider(&second_data);
9744
9745 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
9746
9747 base::WeakPtr<HttpServerProperties> http_server_properties =
9748 session->http_server_properties();
9749 AlternativeService alternative_service(
9750 AlternateProtocolFromNextProto(GetProtocol()), "different.example.org",
9751 444);
9752 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1);
9753 http_server_properties->SetAlternativeService(
9754 url::SchemeHostPort(request.url), alternative_service, expiration);
9755
9756 std::unique_ptr<HttpTransaction> trans(
9757 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
9758 TestCompletionCallback callback;
9759
9760 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
9761 // Alternative service is not used, request fails.
9762 EXPECT_EQ(ERR_CONNECTION_REFUSED, callback.GetResult(rv));
9763 }
9764
9720 TEST_P(HttpNetworkTransactionTest, ClearAlternativeServices) { 9765 TEST_P(HttpNetworkTransactionTest, ClearAlternativeServices) {
9721 session_deps_.parse_alternative_services = true; 9766 session_deps_.parse_alternative_services = true;
9722 session_deps_.enable_alternative_service_with_different_host = false; 9767 session_deps_.enable_alternative_service_with_different_host = false;
9723 9768
9724 // Set an alternative service for origin. 9769 // Set an alternative service for origin.
9725 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 9770 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
9726 HttpServerProperties& http_server_properties = 9771 HttpServerProperties& http_server_properties =
9727 *session->http_server_properties(); 9772 *session->http_server_properties();
9728 url::SchemeHostPort test_server("http", "www.example.org", 80); 9773 url::SchemeHostPort test_server("http", "www.example.org", 80);
9729 AlternativeService alternative_service(QUIC, "", 80); 9774 AlternativeService alternative_service(QUIC, "", 80);
(...skipping 3703 matching lines...) Expand 10 before | Expand all | Expand 10 after
13433 TEST_P(AltSvcCertificateVerificationTest, PoolingInvalid) { 13478 TEST_P(AltSvcCertificateVerificationTest, PoolingInvalid) {
13434 Run(true, false); 13479 Run(true, false);
13435 } 13480 }
13436 13481
13437 // The alternative service host must exhibit a certificate that is valid for the 13482 // The alternative service host must exhibit a certificate that is valid for the
13438 // origin host. Test that this is enforced when opening a new connection. 13483 // origin host. Test that this is enforced when opening a new connection.
13439 TEST_P(AltSvcCertificateVerificationTest, NewConnectionValid) { 13484 TEST_P(AltSvcCertificateVerificationTest, NewConnectionValid) {
13440 Run(false, true); 13485 Run(false, true);
13441 } 13486 }
13442 13487
13443 TEST_P(AltSvcCertificateVerificationTest, NewConnectionInvalid) { 13488 // TODO(bnc): Re-enable when https://crbug.com/615413 is fixed.
13489 TEST_P(AltSvcCertificateVerificationTest, DISABLED_NewConnectionInvalid) {
13444 Run(false, false); 13490 Run(false, false);
13445 } 13491 }
13446 13492
13447 // Alternative service requires HTTP/2 (or SPDY), but HTTP/1.1 is negotiated 13493 // Alternative service requires HTTP/2 (or SPDY), but HTTP/1.1 is negotiated
13448 // with the alternative server. That connection should not be used. 13494 // with the alternative server. That connection should not be used.
13449 TEST_P(HttpNetworkTransactionTest, AlternativeServiceNotOnHttp11) { 13495 TEST_P(HttpNetworkTransactionTest, AlternativeServiceNotOnHttp11) {
13450 url::SchemeHostPort server("https", "origin.example.org", 443); 13496 url::SchemeHostPort server("https", "www.example.org", 443);
13451 HostPortPair alternative("alternative.example.org", 443); 13497 HostPortPair alternative("www.example.org", 444);
13452 13498
13453 // Negotiate HTTP/1.1 with alternative.example.org. 13499 // Negotiate HTTP/1.1 with alternative.
13454 SSLSocketDataProvider ssl(ASYNC, OK); 13500 SSLSocketDataProvider ssl(ASYNC, OK);
13455 ssl.SetNextProto(kProtoHTTP11); 13501 ssl.SetNextProto(kProtoHTTP11);
13456 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); 13502 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
13457 13503
13458 // No data should be read from the alternative, because HTTP/1.1 is 13504 // No data should be read from the alternative, because HTTP/1.1 is
13459 // negotiated. 13505 // negotiated.
13460 StaticSocketDataProvider data; 13506 StaticSocketDataProvider data;
13461 session_deps_.socket_factory->AddSocketDataProvider(&data); 13507 session_deps_.socket_factory->AddSocketDataProvider(&data);
13462 13508
13463 // This test documents that an alternate Job should not be used if HTTP/1.1 is 13509 // This test documents that an alternate Job should not be used if HTTP/1.1 is
(...skipping 12 matching lines...) Expand all
13476 AlternativeService alternative_service( 13522 AlternativeService alternative_service(
13477 AlternateProtocolFromNextProto(GetProtocol()), alternative); 13523 AlternateProtocolFromNextProto(GetProtocol()), alternative);
13478 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); 13524 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1);
13479 http_server_properties->SetAlternativeService(server, alternative_service, 13525 http_server_properties->SetAlternativeService(server, alternative_service,
13480 expiration); 13526 expiration);
13481 13527
13482 std::unique_ptr<HttpTransaction> trans( 13528 std::unique_ptr<HttpTransaction> trans(
13483 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); 13529 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
13484 HttpRequestInfo request; 13530 HttpRequestInfo request;
13485 request.method = "GET"; 13531 request.method = "GET";
13486 request.url = GURL("https://origin.example.org:443"); 13532 request.url = GURL("https://www.example.org:443");
13487 request.load_flags = 0; 13533 request.load_flags = 0;
13488 TestCompletionCallback callback; 13534 TestCompletionCallback callback;
13489 13535
13490 // HTTP/2 (or SPDY) is required for alternative service, if HTTP/1.1 is 13536 // HTTP/2 (or SPDY) is required for alternative service, if HTTP/1.1 is
13491 // negotiated, the alternate Job should fail with ERR_NPN_NEGOTIATION_FAILED. 13537 // negotiated, the alternate Job should fail with ERR_NPN_NEGOTIATION_FAILED.
13492 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); 13538 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
13493 EXPECT_EQ(ERR_NPN_NEGOTIATION_FAILED, callback.GetResult(rv)); 13539 EXPECT_EQ(ERR_NPN_NEGOTIATION_FAILED, callback.GetResult(rv));
13494 } 13540 }
13495 13541
13496 // A request to a server with an alternative service fires two Jobs: one to the 13542 // A request to a server with an alternative service fires two Jobs: one to the
13497 // server, and an alternate one to the alternative server. If the former 13543 // server, and an alternate one to the alternative server. If the former
13498 // succeeds, the request should succeed, even if the latter fails because 13544 // succeeds, the request should succeed, even if the latter fails because
13499 // HTTP/1.1 is negotiated which is insufficient for alternative service. 13545 // HTTP/1.1 is negotiated which is insufficient for alternative service.
13500 TEST_P(HttpNetworkTransactionTest, FailedAlternativeServiceIsNotUserVisible) { 13546 TEST_P(HttpNetworkTransactionTest, FailedAlternativeServiceIsNotUserVisible) {
13501 url::SchemeHostPort server("https", "origin.example.org", 443); 13547 url::SchemeHostPort server("https", "www.example.org", 443);
13502 HostPortPair alternative("alternative.example.org", 443); 13548 HostPortPair alternative("www.example.org", 444);
13503 13549
13504 // Negotiate HTTP/1.1 with alternative. 13550 // Negotiate HTTP/1.1 with alternative.
13505 SSLSocketDataProvider alternative_ssl(ASYNC, OK); 13551 SSLSocketDataProvider alternative_ssl(ASYNC, OK);
13506 alternative_ssl.SetNextProto(kProtoHTTP11); 13552 alternative_ssl.SetNextProto(kProtoHTTP11);
13507 session_deps_.socket_factory->AddSSLSocketDataProvider(&alternative_ssl); 13553 session_deps_.socket_factory->AddSSLSocketDataProvider(&alternative_ssl);
13508 13554
13509 // No data should be read from the alternative, because HTTP/1.1 is 13555 // No data should be read from the alternative, because HTTP/1.1 is
13510 // negotiated. 13556 // negotiated.
13511 StaticSocketDataProvider data; 13557 StaticSocketDataProvider data;
13512 session_deps_.socket_factory->AddSocketDataProvider(&data); 13558 session_deps_.socket_factory->AddSocketDataProvider(&data);
13513 13559
13514 // Negotiate HTTP/1.1 with server. 13560 // Negotiate HTTP/1.1 with server.
13515 SSLSocketDataProvider origin_ssl(ASYNC, OK); 13561 SSLSocketDataProvider origin_ssl(ASYNC, OK);
13516 origin_ssl.SetNextProto(kProtoHTTP11); 13562 origin_ssl.SetNextProto(kProtoHTTP11);
13517 session_deps_.socket_factory->AddSSLSocketDataProvider(&origin_ssl); 13563 session_deps_.socket_factory->AddSSLSocketDataProvider(&origin_ssl);
13518 13564
13519 MockWrite http_writes[] = { 13565 MockWrite http_writes[] = {
13520 MockWrite( 13566 MockWrite("GET / HTTP/1.1\r\n"
13521 "GET / HTTP/1.1\r\n" 13567 "Host: www.example.org\r\n"
13522 "Host: origin.example.org\r\n" 13568 "Connection: keep-alive\r\n\r\n"),
13523 "Connection: keep-alive\r\n\r\n"), 13569 MockWrite("GET /second HTTP/1.1\r\n"
13524 MockWrite( 13570 "Host: www.example.org\r\n"
13525 "GET /second HTTP/1.1\r\n" 13571 "Connection: keep-alive\r\n\r\n"),
13526 "Host: origin.example.org\r\n"
13527 "Connection: keep-alive\r\n\r\n"),
13528 }; 13572 };
13529 13573
13530 MockRead http_reads[] = { 13574 MockRead http_reads[] = {
13531 MockRead("HTTP/1.1 200 OK\r\n"), 13575 MockRead("HTTP/1.1 200 OK\r\n"),
13532 MockRead("Content-Type: text/html\r\n"), 13576 MockRead("Content-Type: text/html\r\n"),
13533 MockRead("Content-Length: 6\r\n\r\n"), 13577 MockRead("Content-Length: 6\r\n\r\n"),
13534 MockRead("foobar"), 13578 MockRead("foobar"),
13535 MockRead("HTTP/1.1 200 OK\r\n"), 13579 MockRead("HTTP/1.1 200 OK\r\n"),
13536 MockRead("Content-Type: text/html\r\n"), 13580 MockRead("Content-Type: text/html\r\n"),
13537 MockRead("Content-Length: 7\r\n\r\n"), 13581 MockRead("Content-Length: 7\r\n\r\n"),
(...skipping 11 matching lines...) Expand all
13549 session->http_server_properties(); 13593 session->http_server_properties();
13550 AlternativeService alternative_service( 13594 AlternativeService alternative_service(
13551 AlternateProtocolFromNextProto(GetProtocol()), alternative); 13595 AlternateProtocolFromNextProto(GetProtocol()), alternative);
13552 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); 13596 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1);
13553 http_server_properties->SetAlternativeService(server, alternative_service, 13597 http_server_properties->SetAlternativeService(server, alternative_service,
13554 expiration); 13598 expiration);
13555 13599
13556 HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); 13600 HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get());
13557 HttpRequestInfo request1; 13601 HttpRequestInfo request1;
13558 request1.method = "GET"; 13602 request1.method = "GET";
13559 request1.url = GURL("https://origin.example.org:443"); 13603 request1.url = GURL("https://www.example.org:443");
13560 request1.load_flags = 0; 13604 request1.load_flags = 0;
13561 TestCompletionCallback callback1; 13605 TestCompletionCallback callback1;
13562 13606
13563 int rv = trans1.Start(&request1, callback1.callback(), BoundNetLog()); 13607 int rv = trans1.Start(&request1, callback1.callback(), BoundNetLog());
13564 rv = callback1.GetResult(rv); 13608 rv = callback1.GetResult(rv);
13565 EXPECT_EQ(OK, rv); 13609 EXPECT_EQ(OK, rv);
13566 13610
13567 const HttpResponseInfo* response1 = trans1.GetResponseInfo(); 13611 const HttpResponseInfo* response1 = trans1.GetResponseInfo();
13568 ASSERT_TRUE(response1 != nullptr); 13612 ASSERT_TRUE(response1 != nullptr);
13569 ASSERT_TRUE(response1->headers.get() != nullptr); 13613 ASSERT_TRUE(response1->headers.get() != nullptr);
13570 EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); 13614 EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine());
13571 13615
13572 std::string response_data1; 13616 std::string response_data1;
13573 ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data1)); 13617 ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data1));
13574 EXPECT_EQ("foobar", response_data1); 13618 EXPECT_EQ("foobar", response_data1);
13575 13619
13576 // Alternative should be marked as broken, because HTTP/1.1 is not sufficient 13620 // Alternative should be marked as broken, because HTTP/1.1 is not sufficient
13577 // for alternative service. 13621 // for alternative service.
13578 EXPECT_TRUE( 13622 EXPECT_TRUE(
13579 http_server_properties->IsAlternativeServiceBroken(alternative_service)); 13623 http_server_properties->IsAlternativeServiceBroken(alternative_service));
13580 13624
13581 // Since |alternative_service| is broken, a second transaction to server 13625 // Since |alternative_service| is broken, a second transaction to server
13582 // should not start an alternate Job. It should pool to existing connection 13626 // should not start an alternate Job. It should pool to existing connection
13583 // to server. 13627 // to server.
13584 HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); 13628 HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get());
13585 HttpRequestInfo request2; 13629 HttpRequestInfo request2;
13586 request2.method = "GET"; 13630 request2.method = "GET";
13587 request2.url = GURL("https://origin.example.org:443/second"); 13631 request2.url = GURL("https://www.example.org:443/second");
13588 request2.load_flags = 0; 13632 request2.load_flags = 0;
13589 TestCompletionCallback callback2; 13633 TestCompletionCallback callback2;
13590 13634
13591 rv = trans2.Start(&request2, callback2.callback(), BoundNetLog()); 13635 rv = trans2.Start(&request2, callback2.callback(), BoundNetLog());
13592 rv = callback2.GetResult(rv); 13636 rv = callback2.GetResult(rv);
13593 EXPECT_EQ(OK, rv); 13637 EXPECT_EQ(OK, rv);
13594 13638
13595 const HttpResponseInfo* response2 = trans2.GetResponseInfo(); 13639 const HttpResponseInfo* response2 = trans2.GetResponseInfo();
13596 ASSERT_TRUE(response2 != nullptr); 13640 ASSERT_TRUE(response2 != nullptr);
13597 ASSERT_TRUE(response2->headers.get() != nullptr); 13641 ASSERT_TRUE(response2->headers.get() != nullptr);
(...skipping 2375 matching lines...) Expand 10 before | Expand all | Expand 10 after
15973 base::MessageLoop::current()->RunUntilIdle(); 16017 base::MessageLoop::current()->RunUntilIdle();
15974 16018
15975 EXPECT_TRUE(trans.GetResponseInfo()->was_fetched_via_spdy); 16019 EXPECT_TRUE(trans.GetResponseInfo()->was_fetched_via_spdy);
15976 HttpRequestHeaders headers; 16020 HttpRequestHeaders headers;
15977 ASSERT_TRUE(trans.GetFullRequestHeaders(&headers)); 16021 ASSERT_TRUE(trans.GetFullRequestHeaders(&headers));
15978 EXPECT_TRUE(headers.HasHeader(HttpRequestHeaders::kTokenBinding)); 16022 EXPECT_TRUE(headers.HasHeader(HttpRequestHeaders::kTokenBinding));
15979 } 16023 }
15980 #endif // !defined(OS_IOS) 16024 #endif // !defined(OS_IOS)
15981 16025
15982 } // namespace net 16026 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | net/http/http_stream_factory_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698