src/net/third_party/quiche/src/quic/core/http/quic_spdy_client_session_test.cc
// A packet with invalid framing should cause a connection to be closed.
A packet with invalid framing should cause a connection to be closed.
A packet with invalid framing should cause a connection to be closed .
TEST_P(QuicSpdyClientSessionTest, InvalidFramedPacketReceived) {
  const ParsedQuicVersion version = GetParam();
  if (version.handshake_protocol == PROTOCOL_TLS1_3) {
    return;
  }
  QuicSocketAddress server_address(TestPeerIPAddress(), kTestPort);
  QuicSocketAddress client_address(TestPeerIPAddress(), kTestPort);
  if (version.KnowsWhichDecrypterToUse()) {
    connection_->InstallDecrypter(
        ENCRYPTION_FORWARD_SECURE,
        std::make_unique<NullDecrypter>(Perspective::IS_CLIENT));
  } else {
    connection_->SetDecrypter(
        ENCRYPTION_FORWARD_SECURE,
        std::make_unique<NullDecrypter>(Perspective::IS_CLIENT));
  }
  EXPECT_CALL(*connection_, ProcessUdpPacket(server_address, client_address, _))
      .WillRepeatedly(Invoke(static_cast<MockQuicConnection*>(connection_),
                             &MockQuicConnection::ReallyProcessUdpPacket));
  EXPECT_CALL(*connection_, OnError(_)).Times(1);
  QuicConnectionId destination_connection_id =
      session_->connection()->connection_id();
  QuicConnectionId source_connection_id = EmptyQuicConnectionId();
  QuicFramerPeer::SetLastSerializedServerConnectionId(
      QuicConnectionPeer::GetFramer(connection_), destination_connection_id);
  bool version_flag = false;
  QuicConnectionIdIncluded scid_included = CONNECTION_ID_ABSENT;
  if (VersionHasIetfInvariantHeader(version.transport_version)) {
    version_flag = true;
    source_connection_id = destination_connection_id;
    scid_included = CONNECTION_ID_PRESENT;
  }
  std::unique_ptr<QuicEncryptedPacket> packet(ConstructMisFramedEncryptedPacket(
      destination_connection_id, source_connection_id, version_flag, false, 100,
      "data", CONNECTION_ID_ABSENT, scid_included, PACKET_4BYTE_PACKET_NUMBER,
      version, Perspective::IS_SERVER));
  std::unique_ptr<QuicReceivedPacket> received(
      ConstructReceivedPacket(*packet, QuicTime::Zero()));
  EXPECT_CALL(*connection_, CloseConnection(_, _, _)).Times(1);
  session_->ProcessUdpPacket(client_address, server_address, *received);
}
TEST_P ( QuicSpdyClientSessionTest , InvalidFramedPacketReceived ) { const ParsedQuicVersion version = GetParam ( ) ; if ( version . handshake_protocol == PROTOCOL_TLS1_3 ) { return ; } QuicSocketAddress server_address ( TestPeerIPAddress ( ) , kTestPort ) ; QuicSocketAddress client_address ( TestPeerIPAddress ( ) , kTestPort ) ; if ( version . KnowsWhichDecrypterToUse ( ) ) { connection_ -> InstallDecrypter ( ENCRYPTION_FORWARD_SECURE , std :: make_unique < NullDecrypter > ( Perspective :: IS_CLIENT ) ) ; } else { connection_ -> SetDecrypter ( ENCRYPTION_FORWARD_SECURE , std :: make_unique < NullDecrypter > ( Perspective :: IS_CLIENT ) ) ; } EXPECT_CALL ( * connection_ , ProcessUdpPacket ( server_address , client_address , _ ) ) . WillRepeatedly ( Invoke ( static_cast < MockQuicConnection * > ( connection_ ) , & MockQuicConnection :: ReallyProcessUdpPacket ) ) ; EXPECT_CALL ( * connection_ , OnError ( _ ) ) . Times ( 1 ) ; QuicConnectionId destination_connection_id = session_ -> connection ( ) -> connection_id ( ) ; QuicConnectionId source_connection_id = EmptyQuicConnectionId ( ) ; QuicFramerPeer :: SetLastSerializedServerConnectionId ( QuicConnectionPeer :: GetFramer ( connection_ ) , destination_connection_id ) ; bool version_flag = false ; QuicConnectionIdIncluded scid_included = CONNECTION_ID_ABSENT ; if ( VersionHasIetfInvariantHeader ( version . transport_version ) ) { version_flag = true ; source_connection_id = destination_connection_id ; scid_included = CONNECTION_ID_PRESENT ; } std :: unique_ptr < QuicEncryptedPacket > packet ( ConstructMisFramedEncryptedPacket ( destination_connection_id , source_connection_id , version_flag , false , 100 , " " , CONNECTION_ID_ABSENT , scid_included , PACKET_4BYTE_PACKET_NUMBER , version , Perspective :: IS_SERVER ) ) ; std :: unique_ptr < QuicReceivedPacket > received ( ConstructReceivedPacket ( * packet , QuicTime :: Zero ( ) ) ) ; EXPECT_CALL ( * connection_ , CloseConnection ( _ , _ , _ ) ) . Times ( 1 ) ; session_ -> ProcessUdpPacket ( client_address , server_address , * received ) ; }
A packet with invalid framing should cause a connection to be closed.
A packet with invalid framing should cause a connection to be closed .
// TODO(nharper, b/112643533): Figure out why this test fails when TLS is // enabled and fix it. // Verify that a decryptable packet with bad frames does close the connection.