src/net/quic/quic_network_transaction_unittest.cc
// Multiple origins have listed the same alternative services. When there's a
// existing QUIC session opened by a request to other origin,
// if the cert is valid, should select this QUIC session to make the request
// if this is also the first existing QUIC session.
Multiple origins have listed the same alternative services. When there's a
existing QUIC session opened by a request to other origin,
if the cert is valid, should select this QUIC session to make the request
if this is also the first existing QUIC session.
Multiple origins have listed the same alternative services . When there ' s a existing QUIC session opened by a request to other origin if the cert is valid should select this QUIC session to make the request if this is also the first existing QUIC session .
TEST_P(QuicNetworkTransactionTest,
       UseSharedExistingAlternativeServiceForQuicWithValidCert) {
  context_.params()->allow_remote_alt_svc = true;
  MockRead http_reads[] = {
      MockRead("HTTP/1.1 200 OK\r\n"),
      MockRead("Alt-Svc: quic=\":443\"\r\n\r\n"),
      MockRead("hello world from www.example.org"),
      MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ),
      MockRead(ASYNC, OK)};
  StaticSocketDataProvider http_data(http_reads, base::span<MockWrite>());
  socket_factory_.AddSocketDataProvider(&http_data);
  AddCertificate(&ssl_data_);
  socket_factory_.AddSSLSocketDataProvider(&ssl_data_);
  MockRead http_reads2[] = {
      MockRead("HTTP/1.1 200 OK\r\n"),
      MockRead("Alt-Svc: quic=\":444\", quic=\"www.example.org:443\"\r\n\r\n"),
      MockRead("hello world from mail.example.org"),
      MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ),
      MockRead(ASYNC, OK)};
  StaticSocketDataProvider http_data2(http_reads2, base::span<MockWrite>());
  socket_factory_.AddSocketDataProvider(&http_data2);
  socket_factory_.AddSSLSocketDataProvider(&ssl_data_);
  QuicTestPacketMaker client_maker(
      version_,
      quic::QuicUtils::CreateRandomConnectionId(context_.random_generator()),
      context_.clock(), "mail.example.org", quic::Perspective::IS_CLIENT,
      client_headers_include_h2_stream_dependency_);
  server_maker_.set_hostname("www.example.org");
  client_maker_->set_hostname("www.example.org");
  MockQuicData mock_quic_data(version_);
  int packet_num = 1;
  if (VersionUsesHttp3(version_.transport_version)) {
    mock_quic_data.AddWrite(SYNCHRONOUS,
                            ConstructInitialSettingsPacket(packet_num++));
  }
  mock_quic_data.AddWrite(
      SYNCHRONOUS,
      ConstructClientRequestHeadersPacket(
          packet_num++, GetNthClientInitiatedBidirectionalStreamId(0), true,
          true, GetRequestHeaders("GET", "https", "/")));
  mock_quic_data.AddRead(
      ASYNC, ConstructServerResponseHeadersPacket(
                 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false,
                 GetResponseHeaders("200 OK")));
  std::string header = ConstructDataHeader(21);
  mock_quic_data.AddRead(
      ASYNC, ConstructServerDataPacket(
                 2, GetNthClientInitiatedBidirectionalStreamId(0), false, true,
                 header + "hello from mail QUIC!"));
  mock_quic_data.AddWrite(SYNCHRONOUS,
                          ConstructClientAckPacket(packet_num++, 2, 1, 1));
  mock_quic_data.AddWrite(
      SYNCHRONOUS,
      ConstructClientRequestHeadersPacket(
          packet_num++, GetNthClientInitiatedBidirectionalStreamId(1), false,
          true, GetRequestHeaders("GET", "https", "/", &client_maker),
          GetNthClientInitiatedBidirectionalStreamId(0)));
  mock_quic_data.AddRead(
      ASYNC, ConstructServerResponseHeadersPacket(
                 3, GetNthClientInitiatedBidirectionalStreamId(1), false, false,
                 GetResponseHeaders("200 OK")));
  mock_quic_data.AddRead(
      ASYNC, ConstructServerDataPacket(
                 4, GetNthClientInitiatedBidirectionalStreamId(1), false, true,
                 header + "hello from mail QUIC!"));
  mock_quic_data.AddWrite(
      SYNCHRONOUS,
      ConstructClientAckAndConnectionClosePacket(packet_num++, 4, 3, 1));
  mock_quic_data.AddRead(ASYNC, ERR_IO_PENDING);  
  mock_quic_data.AddRead(ASYNC, 0);               
  mock_quic_data.AddSocketDataToFactory(&socket_factory_);
  AddHangingNonAlternateProtocolSocketData();
  CreateSession();
  QuicStreamFactoryPeer::SetAlarmFactory(
      session_->quic_stream_factory(),
      std::make_unique<QuicChromiumAlarmFactory>(quic_task_runner_.get(),
                                                 context_.clock()));
  request_.url = GURL("https://www.example.org/");
  SendRequestAndExpectHttpResponse("hello world from www.example.org");
  request_.url = GURL("https://mail.example.org/");
  SendRequestAndExpectHttpResponse("hello world from mail.example.org");
  request_.url = GURL("https://www.example.org/");
  SendRequestAndExpectQuicResponse("hello from mail QUIC!");
  request_.url = GURL("https://mail.example.org/");
  SendRequestAndExpectQuicResponse("hello from mail QUIC!");
}
TEST_P ( QuicNetworkTransactionTest , UseSharedExistingAlternativeServiceForQuicWithValidCert ) { context_ . params ( ) -> allow_remote_alt_svc = true ; MockRead http_reads [ ] = { MockRead ( " \r \n " ) , MockRead ( " \" \" \r \n \r \n " ) , MockRead ( " " ) , MockRead ( SYNCHRONOUS , ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ ) , MockRead ( ASYNC , OK ) } ; StaticSocketDataProvider http_data ( http_reads , base :: span < MockWrite > ( ) ) ; socket_factory_ . AddSocketDataProvider ( & http_data ) ; AddCertificate ( & ssl_data_ ) ; socket_factory_ . AddSSLSocketDataProvider ( & ssl_data_ ) ; MockRead http_reads2 [ ] = { MockRead ( " \r \n " ) , MockRead ( " \" \" \" \" \r \n \r \n " ) , MockRead ( " " ) , MockRead ( SYNCHRONOUS , ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ ) , MockRead ( ASYNC , OK ) } ; StaticSocketDataProvider http_data2 ( http_reads2 , base :: span < MockWrite > ( ) ) ; socket_factory_ . AddSocketDataProvider ( & http_data2 ) ; socket_factory_ . AddSSLSocketDataProvider ( & ssl_data_ ) ; QuicTestPacketMaker client_maker ( version_ , quic :: QuicUtils :: CreateRandomConnectionId ( context_ . random_generator ( ) ) , context_ . clock ( ) , " " , quic :: Perspective :: IS_CLIENT , client_headers_include_h2_stream_dependency_ ) ; server_maker_ . set_hostname ( " " ) ; client_maker_ -> set_hostname ( " " ) ; MockQuicData mock_quic_data ( version_ ) ; int packet_num = 1 ; if ( VersionUsesHttp3 ( version_ . transport_version ) ) { mock_quic_data . AddWrite ( SYNCHRONOUS , ConstructInitialSettingsPacket ( packet_num ++ ) ) ; } mock_quic_data . AddWrite ( SYNCHRONOUS , ConstructClientRequestHeadersPacket ( packet_num ++ , GetNthClientInitiatedBidirectionalStreamId ( 0 ) , true , true , GetRequestHeaders ( " " , " " , " " ) ) ) ; mock_quic_data . AddRead ( ASYNC , ConstructServerResponseHeadersPacket ( 1 , GetNthClientInitiatedBidirectionalStreamId ( 0 ) , false , false , GetResponseHeaders ( " " ) ) ) ; std :: string header = ConstructDataHeader ( 21 ) ; mock_quic_data . AddRead ( ASYNC , ConstructServerDataPacket ( 2 , GetNthClientInitiatedBidirectionalStreamId ( 0 ) , false , true , header + " " ) ) ; mock_quic_data . AddWrite ( SYNCHRONOUS , ConstructClientAckPacket ( packet_num ++ , 2 , 1 , 1 ) ) ; mock_quic_data . AddWrite ( SYNCHRONOUS , ConstructClientRequestHeadersPacket ( packet_num ++ , GetNthClientInitiatedBidirectionalStreamId ( 1 ) , false , true , GetRequestHeaders ( " " , " " , " " , & client_maker ) , GetNthClientInitiatedBidirectionalStreamId ( 0 ) ) ) ; mock_quic_data . AddRead ( ASYNC , ConstructServerResponseHeadersPacket ( 3 , GetNthClientInitiatedBidirectionalStreamId ( 1 ) , false , false , GetResponseHeaders ( " " ) ) ) ; mock_quic_data . AddRead ( ASYNC , ConstructServerDataPacket ( 4 , GetNthClientInitiatedBidirectionalStreamId ( 1 ) , false , true , header + " " ) ) ; mock_quic_data . AddWrite ( SYNCHRONOUS , ConstructClientAckAndConnectionClosePacket ( packet_num ++ , 4 , 3 , 1 ) ) ; mock_quic_data . AddRead ( ASYNC , ERR_IO_PENDING ) ; mock_quic_data . AddRead ( ASYNC , 0 ) ; mock_quic_data . AddSocketDataToFactory ( & socket_factory_ ) ; AddHangingNonAlternateProtocolSocketData ( ) ; CreateSession ( ) ; QuicStreamFactoryPeer :: SetAlarmFactory ( session_ -> quic_stream_factory ( ) , std :: make_unique < QuicChromiumAlarmFactory > ( quic_task_runner_ . get ( ) , context_ . clock ( ) ) ) ; request_ . url = GURL ( " " ) ; SendRequestAndExpectHttpResponse ( " " ) ; request_ . url = GURL ( " " ) ; SendRequestAndExpectHttpResponse ( " " ) ; request_ . url = GURL ( " " ) ; SendRequestAndExpectQuicResponse ( " " ) ; request_ . url = GURL ( " " ) ; SendRequestAndExpectQuicResponse ( " " ) ; }
Multiple origins have listed the same alternative services.
Multiple origins have listed the same alternative services .
// Default cert is valid for *.example.org // HTTP data for request to www.example.org. // HTTP data for request to mail.example.org. // First QUIC request data. // Second QUIC request data. // No more data to read // EOF // Send two HTTP requests, responses set up alt-svc lists for the origins. // Open a QUIC session to mail.example.org:443 when making request // to mail.example.org. // Uses the existing QUIC session when making request to www.example.org.