src/net/third_party/quiche/src/quic/core/quic_dispatcher_test.cc
// Makes sure TestConnectionId(1) creates a new connection and
// TestConnectionIdNineBytesLong(2) gets replaced.
Makes sure TestConnectionId(1) creates a new connection and
TestConnectionIdNineBytesLong(2) gets replaced.
Makes sure TestConnectionId ( 1 ) creates a new connection and TestConnectionIdNineBytesLong ( 2 ) gets replaced .
TEST_P(QuicDispatcherTestAllVersions, MixGoodAndBadConnectionIdLengthPackets) {
  if (!version_.AllowsVariableLengthConnectionIds()) {
    return;
  }
  QuicSocketAddress client_address(QuicIpAddress::Loopback4(), 1);
  QuicConnectionId bad_connection_id = TestConnectionIdNineBytesLong(2);
  QuicConnectionId fixed_connection_id =
      QuicUtils::CreateReplacementConnectionId(bad_connection_id);
  EXPECT_CALL(*dispatcher_,
              CreateQuicSession(TestConnectionId(1), client_address,
                                Eq(ExpectedAlpn()), _))
      .WillOnce(Return(ByMove(CreateSession(
          dispatcher_.get(), config_, TestConnectionId(1), client_address,
          &mock_helper_, &mock_alarm_factory_, &crypto_config_,
          QuicDispatcherPeer::GetCache(dispatcher_.get()), &session1_))));
  EXPECT_CALL(*reinterpret_cast<MockQuicConnection*>(session1_->connection()),
              ProcessUdpPacket(_, _, _))
      .WillOnce(WithArg<2>(Invoke([this](const QuicEncryptedPacket& packet) {
        ValidatePacket(TestConnectionId(1), packet);
      })));
  EXPECT_CALL(*dispatcher_,
              ShouldCreateOrBufferPacketForConnection(
                  ReceivedPacketInfoConnectionIdEquals(TestConnectionId(1))));
  ProcessPacket(client_address, TestConnectionId(1), true, SerializeCHLO());
  EXPECT_CALL(*dispatcher_,
              CreateQuicSession(fixed_connection_id, client_address,
                                Eq(ExpectedAlpn()), _))
      .WillOnce(Return(ByMove(CreateSession(
          dispatcher_.get(), config_, fixed_connection_id, client_address,
          &mock_helper_, &mock_alarm_factory_, &crypto_config_,
          QuicDispatcherPeer::GetCache(dispatcher_.get()), &session2_))));
  EXPECT_CALL(*reinterpret_cast<MockQuicConnection*>(session2_->connection()),
              ProcessUdpPacket(_, _, _))
      .WillOnce(WithArg<2>(
          Invoke([this, bad_connection_id](const QuicEncryptedPacket& packet) {
            ValidatePacket(bad_connection_id, packet);
          })));
  EXPECT_CALL(*dispatcher_,
              ShouldCreateOrBufferPacketForConnection(
                  ReceivedPacketInfoConnectionIdEquals(bad_connection_id)));
  ProcessPacket(client_address, bad_connection_id, true, SerializeCHLO());
  EXPECT_CALL(*reinterpret_cast<MockQuicConnection*>(session1_->connection()),
              ProcessUdpPacket(_, _, _))
      .Times(1)
      .WillOnce(WithArg<2>(Invoke([this](const QuicEncryptedPacket& packet) {
        ValidatePacket(TestConnectionId(1), packet);
      })));
  ProcessPacket(client_address, TestConnectionId(1), false, "data");
}
TEST_P ( QuicDispatcherTestAllVersions , MixGoodAndBadConnectionIdLengthPackets ) { if ( ! version_ . AllowsVariableLengthConnectionIds ( ) ) { return ; } QuicSocketAddress client_address ( QuicIpAddress :: Loopback4 ( ) , 1 ) ; QuicConnectionId bad_connection_id = TestConnectionIdNineBytesLong ( 2 ) ; QuicConnectionId fixed_connection_id = QuicUtils :: CreateReplacementConnectionId ( bad_connection_id ) ; EXPECT_CALL ( * dispatcher_ , CreateQuicSession ( TestConnectionId ( 1 ) , client_address , Eq ( ExpectedAlpn ( ) ) , _ ) ) . WillOnce ( Return ( ByMove ( CreateSession ( dispatcher_ . get ( ) , config_ , TestConnectionId ( 1 ) , client_address , & mock_helper_ , & mock_alarm_factory_ , & crypto_config_ , QuicDispatcherPeer :: GetCache ( dispatcher_ . get ( ) ) , & session1_ ) ) ) ) ; EXPECT_CALL ( * reinterpret_cast < MockQuicConnection * > ( session1_ -> connection ( ) ) , ProcessUdpPacket ( _ , _ , _ ) ) . WillOnce ( WithArg < 2 > ( Invoke ( [ this ] ( const QuicEncryptedPacket & packet ) { ValidatePacket ( TestConnectionId ( 1 ) , packet ) ; } ) ) ) ; EXPECT_CALL ( * dispatcher_ , ShouldCreateOrBufferPacketForConnection ( ReceivedPacketInfoConnectionIdEquals ( TestConnectionId ( 1 ) ) ) ) ; ProcessPacket ( client_address , TestConnectionId ( 1 ) , true , SerializeCHLO ( ) ) ; EXPECT_CALL ( * dispatcher_ , CreateQuicSession ( fixed_connection_id , client_address , Eq ( ExpectedAlpn ( ) ) , _ ) ) . WillOnce ( Return ( ByMove ( CreateSession ( dispatcher_ . get ( ) , config_ , fixed_connection_id , client_address , & mock_helper_ , & mock_alarm_factory_ , & crypto_config_ , QuicDispatcherPeer :: GetCache ( dispatcher_ . get ( ) ) , & session2_ ) ) ) ) ; EXPECT_CALL ( * reinterpret_cast < MockQuicConnection * > ( session2_ -> connection ( ) ) , ProcessUdpPacket ( _ , _ , _ ) ) . WillOnce ( WithArg < 2 > ( Invoke ( [ this , bad_connection_id ] ( const QuicEncryptedPacket & packet ) { ValidatePacket ( bad_connection_id , packet ) ; } ) ) ) ; EXPECT_CALL ( * dispatcher_ , ShouldCreateOrBufferPacketForConnection ( ReceivedPacketInfoConnectionIdEquals ( bad_connection_id ) ) ) ; ProcessPacket ( client_address , bad_connection_id , true , SerializeCHLO ( ) ) ; EXPECT_CALL ( * reinterpret_cast < MockQuicConnection * > ( session1_ -> connection ( ) ) , ProcessUdpPacket ( _ , _ , _ ) ) . Times ( 1 ) . WillOnce ( WithArg < 2 > ( Invoke ( [ this ] ( const QuicEncryptedPacket & packet ) { ValidatePacket ( TestConnectionId ( 1 ) , packet ) ; } ) ) ) ; ProcessPacket ( client_address , TestConnectionId ( 1 ) , false , " " ) ; }
Makes sure TestConnectionId(1) creates a new connection and
TestConnectionIdNineBytesLong(2) gets replaced.
Makes sure TestConnectionId ( 1 ) creates a new connection and TestConnectionIdNineBytesLong ( 2 ) gets replaced .