chromium/net/third_party/quiche/src/quiche/quic/core/quic_dispatcher_test.cc

// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "quiche/quic/core/quic_dispatcher.h"

#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <list>
#include <map>
#include <memory>
#include <optional>
#include <string>
#include <utility>
#include <vector>


#include "absl/base/macros.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/string_view.h"
#include "quiche/quic/core/chlo_extractor.h"
#include "quiche/quic/core/connection_id_generator.h"
#include "quiche/quic/core/crypto/crypto_protocol.h"
#include "quiche/quic/core/crypto/quic_compressed_certs_cache.h"
#include "quiche/quic/core/crypto/quic_crypto_client_config.h"
#include "quiche/quic/core/crypto/quic_crypto_server_config.h"
#include "quiche/quic/core/crypto/quic_random.h"
#include "quiche/quic/core/crypto/transport_parameters.h"
#include "quiche/quic/core/frames/quic_connection_close_frame.h"
#include "quiche/quic/core/http/quic_server_session_base.h"
#include "quiche/quic/core/http/quic_spdy_stream.h"
#include "quiche/quic/core/quic_config.h"
#include "quiche/quic/core/quic_connection.h"
#include "quiche/quic/core/quic_connection_id.h"
#include "quiche/quic/core/quic_constants.h"
#include "quiche/quic/core/quic_crypto_server_stream_base.h"
#include "quiche/quic/core/quic_crypto_stream.h"
#include "quiche/quic/core/quic_error_codes.h"
#include "quiche/quic/core/quic_packet_writer.h"
#include "quiche/quic/core/quic_packet_writer_wrapper.h"
#include "quiche/quic/core/quic_packets.h"
#include "quiche/quic/core/quic_stream.h"
#include "quiche/quic/core/quic_time.h"
#include "quiche/quic/core/quic_time_wait_list_manager.h"
#include "quiche/quic/core/quic_types.h"
#include "quiche/quic/core/quic_utils.h"
#include "quiche/quic/core/quic_version_manager.h"
#include "quiche/quic/core/quic_versions.h"
#include "quiche/quic/platform/api/quic_expect_bug.h"
#include "quiche/quic/platform/api/quic_flags.h"
#include "quiche/quic/platform/api/quic_ip_address.h"
#include "quiche/quic/platform/api/quic_logging.h"
#include "quiche/quic/platform/api/quic_socket_address.h"
#include "quiche/quic/platform/api/quic_test.h"
#include "quiche/quic/test_tools/crypto_test_utils.h"
#include "quiche/quic/test_tools/first_flight.h"
#include "quiche/quic/test_tools/mock_connection_id_generator.h"
#include "quiche/quic/test_tools/mock_quic_time_wait_list_manager.h"
#include "quiche/quic/test_tools/quic_buffered_packet_store_peer.h"
#include "quiche/quic/test_tools/quic_connection_peer.h"
#include "quiche/quic/test_tools/quic_dispatcher_peer.h"
#include "quiche/quic/test_tools/quic_test_utils.h"
#include "quiche/quic/tools/quic_simple_crypto_server_stream_helper.h"
#include "quiche/common/platform/api/quiche_logging.h"
#include "quiche/common/test_tools/quiche_test_utils.h"

_;
AllOf;
ByMove;
ElementsAreArray;
Eq;
Field;
InSequence;
Invoke;
IsEmpty;
NiceMock;
Not;
Ref;
Return;
ReturnRef;
WithArg;
WithoutArgs;

static const size_t kDefaultMaxConnectionsInStore =;
static const size_t kMaxConnectionsWithoutCHLO =;
static const int16_t kMaxNumSessionsToCreate =;

namespace quic {
namespace test {
namespace {

const QuicConnectionId kReturnConnectionId{};

class TestQuicSpdyServerSession : public QuicServerSessionBase {};

class TestDispatcher : public QuicDispatcher {};

// A Connection class which unregisters the session from the dispatcher when
// sending connection close.
// It'd be slightly more realistic to do this from the Session but it would
// involve a lot more mocking.
class MockServerConnection : public MockQuicConnection {};

class QuicDispatcherTestBase : public QuicTestWithParam<ParsedQuicVersion> {};

class QuicDispatcherTestAllVersions : public QuicDispatcherTestBase {};
class QuicDispatcherTestOneVersion : public QuicDispatcherTestBase {};

class QuicDispatcherTestNoVersions : public QuicDispatcherTestBase {};

INSTANTIATE_TEST_SUITE_P();

INSTANTIATE_TEST_SUITE_P();

INSTANTIATE_TEST_SUITE_P();

TEST_P(QuicDispatcherTestAllVersions, TlsClientHelloCreatesSession) {}

TEST_P(QuicDispatcherTestAllVersions,
       TlsClientHelloCreatesSessionWithCorrectConnectionIdGenerator) {}

TEST_P(QuicDispatcherTestAllVersions, VariableServerConnectionIdLength) {}

void QuicDispatcherTestBase::TestTlsMultiPacketClientHello(
    bool add_reordering, bool long_connection_id) {}

TEST_P(QuicDispatcherTestAllVersions, TlsMultiPacketClientHello) {}

TEST_P(QuicDispatcherTestAllVersions, TlsMultiPacketClientHelloWithReordering) {}

TEST_P(QuicDispatcherTestAllVersions, TlsMultiPacketClientHelloWithLongId) {}

TEST_P(QuicDispatcherTestAllVersions,
       TlsMultiPacketClientHelloWithReorderingAndLongId) {}

TEST_P(QuicDispatcherTestAllVersions, ProcessPackets) {}

// Regression test of b/93325907.
TEST_P(QuicDispatcherTestAllVersions, DispatcherDoesNotRejectPacketNumberZero) {}

TEST_P(QuicDispatcherTestOneVersion, StatelessVersionNegotiation) {}

TEST_P(QuicDispatcherTestOneVersion,
       StatelessVersionNegotiationWithVeryLongConnectionId) {}

TEST_P(QuicDispatcherTestOneVersion,
       StatelessVersionNegotiationWithClientConnectionId) {}

TEST_P(QuicDispatcherTestOneVersion, NoVersionNegotiationWithSmallPacket) {}

// Disabling CHLO size validation allows the dispatcher to send version
// negotiation packets in response to a CHLO that is otherwise too small.
TEST_P(QuicDispatcherTestOneVersion,
       VersionNegotiationWithoutChloSizeValidation) {}

TEST_P(QuicDispatcherTestAllVersions, Shutdown) {}

TEST_P(QuicDispatcherTestAllVersions, TimeWaitListManager) {}

TEST_P(QuicDispatcherTestAllVersions, NoVersionPacketToTimeWaitListManager) {}

TEST_P(QuicDispatcherTestAllVersions,
       DonotTimeWaitPacketsWithUnknownConnectionIdAndNoVersion) {}

TEST_P(QuicDispatcherTestOneVersion, DropPacketWithInvalidFlags) {}

TEST_P(QuicDispatcherTestAllVersions, LimitResetsToSameClientAddress) {}

TEST_P(QuicDispatcherTestAllVersions,
       StopSendingResetOnTooManyRecentAddresses) {}

// Makes sure nine-byte connection IDs are replaced by 8-byte ones.
TEST_P(QuicDispatcherTestAllVersions, LongConnectionIdLengthReplaced) {}

// Makes sure TestConnectionId(1) creates a new connection and
// TestConnectionIdNineBytesLong(2) gets replaced.
TEST_P(QuicDispatcherTestAllVersions, MixGoodAndBadConnectionIdLengthPackets) {}

TEST_P(QuicDispatcherTestAllVersions, ProcessPacketWithZeroPort) {}

TEST_P(QuicDispatcherTestAllVersions, ProcessPacketWithBlockedPort) {}

TEST_P(QuicDispatcherTestAllVersions, ProcessPacketWithNonBlockedPort) {}

TEST_P(QuicDispatcherTestAllVersions,
       DropPacketWithKnownVersionAndInvalidShortInitialConnectionId) {}

TEST_P(QuicDispatcherTestAllVersions,
       DropPacketWithKnownVersionAndInvalidInitialConnectionId) {}

void QuicDispatcherTestBase::
    TestVersionNegotiationForUnknownVersionInvalidShortInitialConnectionId(
        const QuicConnectionId& server_connection_id,
        const QuicConnectionId& client_connection_id) {}

TEST_P(QuicDispatcherTestOneVersion,
       VersionNegotiationForUnknownVersionInvalidShortInitialConnectionId) {}

TEST_P(QuicDispatcherTestOneVersion,
       VersionNegotiationForUnknownVersionInvalidShortInitialConnectionId2) {}

TEST_P(QuicDispatcherTestOneVersion,
       VersionNegotiationForUnknownVersionInvalidShortInitialConnectionId3) {}

TEST_P(QuicDispatcherTestOneVersion, VersionsChangeInFlight) {}

TEST_P(QuicDispatcherTestOneVersion,
       RejectDeprecatedVersionDraft28WithVersionNegotiation) {}

TEST_P(QuicDispatcherTestOneVersion,
       RejectDeprecatedVersionDraft27WithVersionNegotiation) {}

TEST_P(QuicDispatcherTestOneVersion,
       RejectDeprecatedVersionDraft25WithVersionNegotiation) {}

TEST_P(QuicDispatcherTestOneVersion,
       RejectDeprecatedVersionT050WithVersionNegotiation) {}

TEST_P(QuicDispatcherTestOneVersion,
       RejectDeprecatedVersionQ049WithVersionNegotiation) {}

TEST_P(QuicDispatcherTestOneVersion,
       RejectDeprecatedVersionQ048WithVersionNegotiation) {}

TEST_P(QuicDispatcherTestOneVersion,
       RejectDeprecatedVersionQ047WithVersionNegotiation) {}

TEST_P(QuicDispatcherTestOneVersion,
       RejectDeprecatedVersionQ045WithVersionNegotiation) {}

TEST_P(QuicDispatcherTestOneVersion,
       RejectDeprecatedVersionQ044WithVersionNegotiation) {}

TEST_P(QuicDispatcherTestOneVersion,
       RejectDeprecatedVersionQ050WithVersionNegotiation) {}

TEST_P(QuicDispatcherTestOneVersion,
       RejectDeprecatedVersionT051WithVersionNegotiation) {}

static_assert;

TEST_P(QuicDispatcherTestOneVersion, VersionNegotiationProbe) {}

// Testing packet writer that saves all packets instead of sending them.
// Useful for tests that need access to sent packets.
class SavingWriter : public QuicPacketWriterWrapper {};

TEST_P(QuicDispatcherTestOneVersion, VersionNegotiationProbeEndToEnd) {}

TEST_P(QuicDispatcherTestOneVersion, AndroidConformanceTest) {}

TEST_P(QuicDispatcherTestOneVersion, AndroidConformanceTestOld) {}

TEST_P(QuicDispatcherTestAllVersions, DoNotProcessSmallPacket) {}

TEST_P(QuicDispatcherTestAllVersions, ProcessSmallCoalescedPacket) {}

TEST_P(QuicDispatcherTestAllVersions, StopAcceptingNewConnections) {}

TEST_P(QuicDispatcherTestAllVersions, StartAcceptingNewConnections) {}

TEST_P(QuicDispatcherTestOneVersion, SelectAlpn) {}

TEST_P(QuicDispatcherTestNoVersions, VersionNegotiationFromReservedVersion) {}

TEST_P(QuicDispatcherTestNoVersions, VersionNegotiationFromRealVersion) {}

// Verify the stopgap test: Packets with truncated connection IDs should be
// dropped.
class QuicDispatcherTestStrayPacketConnectionId
    : public QuicDispatcherTestBase {};

INSTANTIATE_TEST_SUITE_P();

// Packets with truncated connection IDs should be dropped.
TEST_P(QuicDispatcherTestStrayPacketConnectionId,
       StrayPacketTruncatedConnectionId) {}

class BlockingWriter : public QuicPacketWriterWrapper {};

class QuicDispatcherWriteBlockedListTest : public QuicDispatcherTestBase {};

INSTANTIATE_TEST_SUITE_P();

TEST_P(QuicDispatcherWriteBlockedListTest, BasicOnCanWrite) {}

TEST_P(QuicDispatcherWriteBlockedListTest, OnCanWriteOrder) {}

TEST_P(QuicDispatcherWriteBlockedListTest, OnCanWriteRemove) {}

TEST_P(QuicDispatcherWriteBlockedListTest, DoubleAdd) {}

TEST_P(QuicDispatcherWriteBlockedListTest, OnCanWriteHandleBlockConnection1) {}

TEST_P(QuicDispatcherWriteBlockedListTest, OnCanWriteHandleBlockConnection2) {}

TEST_P(QuicDispatcherWriteBlockedListTest,
       OnCanWriteHandleBlockBothConnections) {}

TEST_P(QuicDispatcherWriteBlockedListTest, PerConnectionWriterBlocked) {}

TEST_P(QuicDispatcherWriteBlockedListTest,
       RemoveConnectionFromWriteBlockedListWhenDeletingSessions) {}

class QuicDispatcherSupportMultipleConnectionIdPerConnectionTest
    : public QuicDispatcherTestBase {};

INSTANTIATE_TEST_SUITE_P();

TEST_P(QuicDispatcherSupportMultipleConnectionIdPerConnectionTest,
       FailToAddExistingConnectionId) {}

TEST_P(QuicDispatcherSupportMultipleConnectionIdPerConnectionTest,
       TryAddNewConnectionId) {}

TEST_P(QuicDispatcherSupportMultipleConnectionIdPerConnectionTest,
       TryAddNewConnectionIdWithCollision) {}

TEST_P(QuicDispatcherSupportMultipleConnectionIdPerConnectionTest,
       MismatchedSessionAfterAddingCollidedConnectionId) {}

TEST_P(QuicDispatcherSupportMultipleConnectionIdPerConnectionTest,
       RetireConnectionIdFromSingleConnection) {}

TEST_P(QuicDispatcherSupportMultipleConnectionIdPerConnectionTest,
       RetireConnectionIdFromMultipleConnections) {}

TEST_P(QuicDispatcherSupportMultipleConnectionIdPerConnectionTest,
       TimeWaitListPoplulateCorrectly) {}

class BufferedPacketStoreTest : public QuicDispatcherTestBase {};

INSTANTIATE_TEST_SUITE_P();

TEST_P(BufferedPacketStoreTest, ProcessNonChloPacketBeforeChlo) {}

TEST_P(BufferedPacketStoreTest, ProcessNonChloPacketsUptoLimitAndProcessChlo) {}

TEST_P(BufferedPacketStoreTest,
       ProcessNonChloPacketsForDifferentConnectionsUptoLimit) {}

// Tests that store delivers empty packet list if CHLO arrives firstly.
TEST_P(BufferedPacketStoreTest, DeliverEmptyPackets) {}

// Tests that a retransmitted CHLO arrives after a connection for the
// CHLO has been created.
TEST_P(BufferedPacketStoreTest, ReceiveRetransmittedCHLO) {}

// Tests that expiration of a connection add connection id to time wait list.
TEST_P(BufferedPacketStoreTest, ReceiveCHLOAfterExpiration) {}

TEST_P(BufferedPacketStoreTest, ProcessCHLOsUptoLimitAndBufferTheRest) {}

TEST_P(BufferedPacketStoreTest,
       ProcessCHLOsUptoLimitAndBufferWithDifferentConnectionIdGenerator) {}

// Duplicated CHLO shouldn't be buffered.
TEST_P(BufferedPacketStoreTest, BufferDuplicatedCHLO) {}

TEST_P(BufferedPacketStoreTest, BufferNonChloPacketsUptoLimitWithChloBuffered) {}

// Tests that when dispatcher's packet buffer is full, a CHLO on connection
// which doesn't have buffered CHLO should be buffered.
TEST_P(BufferedPacketStoreTest, ReceiveCHLOForBufferedConnection) {}

// Regression test for b/117874922.
TEST_P(BufferedPacketStoreTest, ProcessBufferedChloWithDifferentVersion) {}

TEST_P(BufferedPacketStoreTest, BufferedChloWithEcn) {}

class DualCIDBufferedPacketStoreTest : public BufferedPacketStoreTest {};

INSTANTIATE_TEST_SUITE_P();

TEST_P(DualCIDBufferedPacketStoreTest, CanLookUpByBothCIDs) {}

TEST_P(DualCIDBufferedPacketStoreTest, DeliverPacketsByOriginalCID) {}

TEST_P(DualCIDBufferedPacketStoreTest, DeliverPacketsByReplacedCID) {}

TEST_P(DualCIDBufferedPacketStoreTest, DiscardPacketsByOriginalCID) {}

TEST_P(DualCIDBufferedPacketStoreTest, DiscardPacketsByReplacedCID) {}

TEST_P(DualCIDBufferedPacketStoreTest, CIDCollision) {}

}  // namespace
}  // namespace test
}  // namespace quic