src/net/quic/quic_network_transaction_unittest.cc
// First request opens QUIC session to alternative service.  Second request does
// not pool to it, even though destination matches, because certificate is not
// valid.  Instead, a new QUIC session is opened to the same destination with a
// different quic::QuicServerId.
First request opens QUIC session to alternative service.  Second request does
not pool to it, even though destination matches, because certificate is not
valid.  Instead, a new QUIC session is opened to the same destination with a
different quic::QuicServerId.
First request opens QUIC session to alternative service . Second request does not pool to it even though destination matches because certificate is not valid . Instead a new QUIC session is opened to the same destination with a different quic :: QuicServerId .
TEST_P(QuicNetworkTransactionWithDestinationTest,
       DoNotPoolIfCertificateInvalid) {
  origin1_ = "news.example.org";
  origin2_ = "mail.example.com";
  SetQuicAlternativeService(origin1_);
  SetQuicAlternativeService(origin2_);
  scoped_refptr<X509Certificate> cert1(
      ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"));
  ASSERT_TRUE(cert1->VerifyNameMatch(origin1_));
  ASSERT_FALSE(cert1->VerifyNameMatch(origin2_));
  ASSERT_FALSE(cert1->VerifyNameMatch(kDifferentHostname));
  scoped_refptr<X509Certificate> cert2(
      ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"));
  ASSERT_TRUE(cert2->VerifyNameMatch(origin2_));
  ASSERT_FALSE(cert2->VerifyNameMatch(kDifferentHostname));
  ProofVerifyDetailsChromium verify_details1;
  verify_details1.cert_verify_result.verified_cert = cert1;
  verify_details1.cert_verify_result.is_issued_by_known_root = true;
  crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details1);
  ProofVerifyDetailsChromium verify_details2;
  verify_details2.cert_verify_result.verified_cert = cert2;
  verify_details2.cert_verify_result.is_issued_by_known_root = true;
  crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details2);
  QuicTestPacketMaker client_maker1(
      version_,
      quic::QuicUtils::CreateRandomConnectionId(context_.random_generator()),
      context_.clock(), origin1_, quic::Perspective::IS_CLIENT,
      client_headers_include_h2_stream_dependency_);
  QuicTestPacketMaker server_maker1(
      version_,
      quic::QuicUtils::CreateRandomConnectionId(context_.random_generator()),
      context_.clock(), origin1_, quic::Perspective::IS_SERVER, false);
  MockQuicData mock_quic_data1(version_);
  int packet_num = 1;
  if (VersionUsesHttp3(version_.transport_version)) {
    mock_quic_data1.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket(
                                              packet_num++, &client_maker1));
  }
  mock_quic_data1.AddWrite(
      SYNCHRONOUS,
      ConstructClientRequestHeadersPacket(
          packet_num++, GetNthClientInitiatedBidirectionalStreamId(0), true,
          &client_maker1));
  mock_quic_data1.AddRead(
      ASYNC,
      ConstructServerResponseHeadersPacket(
          1, GetNthClientInitiatedBidirectionalStreamId(0), &server_maker1));
  mock_quic_data1.AddRead(
      ASYNC,
      ConstructServerDataPacket(
          2, GetNthClientInitiatedBidirectionalStreamId(0), &server_maker1));
  mock_quic_data1.AddWrite(
      SYNCHRONOUS,
      ConstructClientAckPacket(packet_num++, 2, 1, 1, &client_maker1));
  mock_quic_data1.AddRead(ASYNC, ERR_IO_PENDING);  
  mock_quic_data1.AddRead(ASYNC, 0);               
  mock_quic_data1.AddSocketDataToFactory(&socket_factory_);
  QuicTestPacketMaker client_maker2(
      version_,
      quic::QuicUtils::CreateRandomConnectionId(context_.random_generator()),
      context_.clock(), origin2_, quic::Perspective::IS_CLIENT,
      client_headers_include_h2_stream_dependency_);
  QuicTestPacketMaker server_maker2(
      version_,
      quic::QuicUtils::CreateRandomConnectionId(context_.random_generator()),
      context_.clock(), origin2_, quic::Perspective::IS_SERVER, false);
  MockQuicData mock_quic_data2(version_);
  int packet_num2 = 1;
  if (VersionUsesHttp3(version_.transport_version)) {
    mock_quic_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket(
                                              packet_num2++, &client_maker2));
  }
  mock_quic_data2.AddWrite(
      SYNCHRONOUS,
      ConstructClientRequestHeadersPacket(
          packet_num2++, GetNthClientInitiatedBidirectionalStreamId(0), true,
          &client_maker2));
  mock_quic_data2.AddRead(
      ASYNC,
      ConstructServerResponseHeadersPacket(
          1, GetNthClientInitiatedBidirectionalStreamId(0), &server_maker2));
  mock_quic_data2.AddRead(
      ASYNC,
      ConstructServerDataPacket(
          2, GetNthClientInitiatedBidirectionalStreamId(0), &server_maker2));
  mock_quic_data2.AddWrite(
      SYNCHRONOUS,
      ConstructClientAckPacket(packet_num2++, 2, 1, 1, &client_maker2));
  mock_quic_data2.AddRead(ASYNC, ERR_IO_PENDING);  
  mock_quic_data2.AddRead(ASYNC, 0);               
  mock_quic_data2.AddSocketDataToFactory(&socket_factory_);
  SendRequestAndExpectQuicResponse(origin1_);
  SendRequestAndExpectQuicResponse(origin2_);
  EXPECT_TRUE(AllDataConsumed());
}
TEST_P ( QuicNetworkTransactionWithDestinationTest , DoNotPoolIfCertificateInvalid ) { origin1_ = " " ; origin2_ = " " ; SetQuicAlternativeService ( origin1_ ) ; SetQuicAlternativeService ( origin2_ ) ; scoped_refptr < X509Certificate > cert1 ( ImportCertFromFile ( GetTestCertsDirectory ( ) , " " ) ) ; ASSERT_TRUE ( cert1 -> VerifyNameMatch ( origin1_ ) ) ; ASSERT_FALSE ( cert1 -> VerifyNameMatch ( origin2_ ) ) ; ASSERT_FALSE ( cert1 -> VerifyNameMatch ( kDifferentHostname ) ) ; scoped_refptr < X509Certificate > cert2 ( ImportCertFromFile ( GetTestCertsDirectory ( ) , " " ) ) ; ASSERT_TRUE ( cert2 -> VerifyNameMatch ( origin2_ ) ) ; ASSERT_FALSE ( cert2 -> VerifyNameMatch ( kDifferentHostname ) ) ; ProofVerifyDetailsChromium verify_details1 ; verify_details1 . cert_verify_result . verified_cert = cert1 ; verify_details1 . cert_verify_result . is_issued_by_known_root = true ; crypto_client_stream_factory_ . AddProofVerifyDetails ( & verify_details1 ) ; ProofVerifyDetailsChromium verify_details2 ; verify_details2 . cert_verify_result . verified_cert = cert2 ; verify_details2 . cert_verify_result . is_issued_by_known_root = true ; crypto_client_stream_factory_ . AddProofVerifyDetails ( & verify_details2 ) ; QuicTestPacketMaker client_maker1 ( version_ , quic :: QuicUtils :: CreateRandomConnectionId ( context_ . random_generator ( ) ) , context_ . clock ( ) , origin1_ , quic :: Perspective :: IS_CLIENT , client_headers_include_h2_stream_dependency_ ) ; QuicTestPacketMaker server_maker1 ( version_ , quic :: QuicUtils :: CreateRandomConnectionId ( context_ . random_generator ( ) ) , context_ . clock ( ) , origin1_ , quic :: Perspective :: IS_SERVER , false ) ; MockQuicData mock_quic_data1 ( version_ ) ; int packet_num = 1 ; if ( VersionUsesHttp3 ( version_ . transport_version ) ) { mock_quic_data1 . AddWrite ( SYNCHRONOUS , ConstructInitialSettingsPacket ( packet_num ++ , & client_maker1 ) ) ; } mock_quic_data1 . AddWrite ( SYNCHRONOUS , ConstructClientRequestHeadersPacket ( packet_num ++ , GetNthClientInitiatedBidirectionalStreamId ( 0 ) , true , & client_maker1 ) ) ; mock_quic_data1 . AddRead ( ASYNC , ConstructServerResponseHeadersPacket ( 1 , GetNthClientInitiatedBidirectionalStreamId ( 0 ) , & server_maker1 ) ) ; mock_quic_data1 . AddRead ( ASYNC , ConstructServerDataPacket ( 2 , GetNthClientInitiatedBidirectionalStreamId ( 0 ) , & server_maker1 ) ) ; mock_quic_data1 . AddWrite ( SYNCHRONOUS , ConstructClientAckPacket ( packet_num ++ , 2 , 1 , 1 , & client_maker1 ) ) ; mock_quic_data1 . AddRead ( ASYNC , ERR_IO_PENDING ) ; mock_quic_data1 . AddRead ( ASYNC , 0 ) ; mock_quic_data1 . AddSocketDataToFactory ( & socket_factory_ ) ; QuicTestPacketMaker client_maker2 ( version_ , quic :: QuicUtils :: CreateRandomConnectionId ( context_ . random_generator ( ) ) , context_ . clock ( ) , origin2_ , quic :: Perspective :: IS_CLIENT , client_headers_include_h2_stream_dependency_ ) ; QuicTestPacketMaker server_maker2 ( version_ , quic :: QuicUtils :: CreateRandomConnectionId ( context_ . random_generator ( ) ) , context_ . clock ( ) , origin2_ , quic :: Perspective :: IS_SERVER , false ) ; MockQuicData mock_quic_data2 ( version_ ) ; int packet_num2 = 1 ; if ( VersionUsesHttp3 ( version_ . transport_version ) ) { mock_quic_data2 . AddWrite ( SYNCHRONOUS , ConstructInitialSettingsPacket ( packet_num2 ++ , & client_maker2 ) ) ; } mock_quic_data2 . AddWrite ( SYNCHRONOUS , ConstructClientRequestHeadersPacket ( packet_num2 ++ , GetNthClientInitiatedBidirectionalStreamId ( 0 ) , true , & client_maker2 ) ) ; mock_quic_data2 . AddRead ( ASYNC , ConstructServerResponseHeadersPacket ( 1 , GetNthClientInitiatedBidirectionalStreamId ( 0 ) , & server_maker2 ) ) ; mock_quic_data2 . AddRead ( ASYNC , ConstructServerDataPacket ( 2 , GetNthClientInitiatedBidirectionalStreamId ( 0 ) , & server_maker2 ) ) ; mock_quic_data2 . AddWrite ( SYNCHRONOUS , ConstructClientAckPacket ( packet_num2 ++ , 2 , 1 , 1 , & client_maker2 ) ) ; mock_quic_data2 . AddRead ( ASYNC , ERR_IO_PENDING ) ; mock_quic_data2 . AddRead ( ASYNC , 0 ) ; mock_quic_data2 . AddSocketDataToFactory ( & socket_factory_ ) ; SendRequestAndExpectQuicResponse ( origin1_ ) ; SendRequestAndExpectQuicResponse ( origin2_ ) ; EXPECT_TRUE ( AllDataConsumed ( ) ) ; }
First request opens QUIC session to alternative service.
First request opens QUIC session to alternative service .
// No more data to read // EOF // No more data to read // EOF