src/net/quic/quic_network_transaction_unittest.cc
// Much like above, but makes sure NetworkIsolationKey is respected.
Much like above, but makes sure NetworkIsolationKey is respected.
Much like above but makes sure NetworkIsolationKey is respected .
TEST_P(QuicNetworkTransactionTest,
       UseAlternativeServiceForQuicWithNetworkIsolationKey) {
  base::test::ScopedFeatureList feature_list;
  feature_list.InitWithFeatures(
      {features::kPartitionHttpServerPropertiesByNetworkIsolationKey,
       features::kPartitionConnectionsByNetworkIsolationKey},
      {});
  http_server_properties_ = std::make_unique<HttpServerProperties>();
  const url::Origin kOrigin1 = url::Origin::Create(GURL("https://foo.test/"));
  const net::NetworkIsolationKey kNetworkIsolationKey1(kOrigin1, kOrigin1);
  const url::Origin kOrigin2 = url::Origin::Create(GURL("https://bar.test/"));
  const net::NetworkIsolationKey kNetworkIsolationKey2(kOrigin2, kOrigin2);
  MockRead http_reads[] = {
      MockRead("HTTP/1.1 200 OK\r\n"), MockRead(kQuicAlternativeServiceHeader),
      MockRead("hello world"),
      MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ),
      MockRead(ASYNC, OK)};
  AddCertificate(&ssl_data_);
  StaticSocketDataProvider http_data1(http_reads, base::span<MockWrite>());
  socket_factory_.AddSocketDataProvider(&http_data1);
  socket_factory_.AddSSLSocketDataProvider(&ssl_data_);
  StaticSocketDataProvider http_data2(http_reads, base::span<MockWrite>());
  socket_factory_.AddSocketDataProvider(&http_data2);
  socket_factory_.AddSSLSocketDataProvider(&ssl_data_);
  StaticSocketDataProvider http_data3(http_reads, base::span<MockWrite>());
  socket_factory_.AddSocketDataProvider(&http_data3);
  socket_factory_.AddSSLSocketDataProvider(&ssl_data_);
  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(6);
  mock_quic_data.AddRead(
      ASYNC, ConstructServerDataPacket(
                 2, GetNthClientInitiatedBidirectionalStreamId(0), false, true,
                 header + "hello!"));
  mock_quic_data.AddWrite(SYNCHRONOUS,
                          ConstructClientAckPacket(packet_num++, 2, 1, 1));
  mock_quic_data.AddRead(ASYNC, ERR_IO_PENDING);  
  mock_quic_data.AddRead(ASYNC, 0);               
  mock_quic_data.AddSocketDataToFactory(&socket_factory_);
  AddHangingNonAlternateProtocolSocketData();
  CreateSession();
  request_.network_isolation_key = NetworkIsolationKey();
  SendRequestAndExpectHttpResponse("hello world");
  request_.network_isolation_key = kNetworkIsolationKey1;
  SendRequestAndExpectHttpResponse("hello world");
  request_.network_isolation_key = kNetworkIsolationKey2;
  SendRequestAndExpectHttpResponse("hello world");
  request_.network_isolation_key = kNetworkIsolationKey1;
  SendRequestAndExpectQuicResponse("hello!");
}
TEST_P ( QuicNetworkTransactionTest , UseAlternativeServiceForQuicWithNetworkIsolationKey ) { base :: test :: ScopedFeatureList feature_list ; feature_list . InitWithFeatures ( { features :: kPartitionHttpServerPropertiesByNetworkIsolationKey , features :: kPartitionConnectionsByNetworkIsolationKey } , { } ) ; http_server_properties_ = std :: make_unique < HttpServerProperties > ( ) ; const url :: Origin kOrigin1 = url :: Origin :: Create ( GURL ( " " ) ) ; const net :: NetworkIsolationKey kNetworkIsolationKey1 ( kOrigin1 , kOrigin1 ) ; const url :: Origin kOrigin2 = url :: Origin :: Create ( GURL ( " " ) ) ; const net :: NetworkIsolationKey kNetworkIsolationKey2 ( kOrigin2 , kOrigin2 ) ; MockRead http_reads [ ] = { MockRead ( " \r \n " ) , MockRead ( kQuicAlternativeServiceHeader ) , MockRead ( " " ) , MockRead ( SYNCHRONOUS , ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ ) , MockRead ( ASYNC , OK ) } ; AddCertificate ( & ssl_data_ ) ; StaticSocketDataProvider http_data1 ( http_reads , base :: span < MockWrite > ( ) ) ; socket_factory_ . AddSocketDataProvider ( & http_data1 ) ; socket_factory_ . AddSSLSocketDataProvider ( & ssl_data_ ) ; StaticSocketDataProvider http_data2 ( http_reads , base :: span < MockWrite > ( ) ) ; socket_factory_ . AddSocketDataProvider ( & http_data2 ) ; socket_factory_ . AddSSLSocketDataProvider ( & ssl_data_ ) ; StaticSocketDataProvider http_data3 ( http_reads , base :: span < MockWrite > ( ) ) ; socket_factory_ . AddSocketDataProvider ( & http_data3 ) ; socket_factory_ . AddSSLSocketDataProvider ( & ssl_data_ ) ; 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 ( 6 ) ; 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 . AddRead ( ASYNC , ERR_IO_PENDING ) ; mock_quic_data . AddRead ( ASYNC , 0 ) ; mock_quic_data . AddSocketDataToFactory ( & socket_factory_ ) ; AddHangingNonAlternateProtocolSocketData ( ) ; CreateSession ( ) ; request_ . network_isolation_key = NetworkIsolationKey ( ) ; SendRequestAndExpectHttpResponse ( " " ) ; request_ . network_isolation_key = kNetworkIsolationKey1 ; SendRequestAndExpectHttpResponse ( " " ) ; request_ . network_isolation_key = kNetworkIsolationKey2 ; SendRequestAndExpectHttpResponse ( " " ) ; request_ . network_isolation_key = kNetworkIsolationKey1 ; SendRequestAndExpectQuicResponse ( " " ) ; }
Much like above, but makes sure NetworkIsolationKey is respected.
Much like above but makes sure NetworkIsolationKey is respected .
// enabled_features // disabled_features // Since HttpServerProperties caches the feature value, have to create a new // one. // Request with empty NetworkIsolationKey. // First request with kNetworkIsolationKey1. // Request with kNetworkIsolationKey2. // Second request with kNetworkIsolationKey1, can finally use QUIC, since // alternative service infrmation has been received in this context before. // No more data to read // EOF // This is first so that the test fails if alternative service info is // written with the right NetworkIsolationKey, but always queried with an // empty one. // Only use QUIC when using a NetworkIsolationKey which has been used when // alternative service information was received.