#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 { … };
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) { … }
TEST_P(QuicDispatcherTestAllVersions, DispatcherDoesNotRejectPacketNumberZero) { … }
TEST_P(QuicDispatcherTestOneVersion, StatelessVersionNegotiation) { … }
TEST_P(QuicDispatcherTestOneVersion,
StatelessVersionNegotiationWithVeryLongConnectionId) { … }
TEST_P(QuicDispatcherTestOneVersion,
StatelessVersionNegotiationWithClientConnectionId) { … }
TEST_P(QuicDispatcherTestOneVersion, NoVersionNegotiationWithSmallPacket) { … }
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) { … }
TEST_P(QuicDispatcherTestAllVersions, LongConnectionIdLengthReplaced) { … }
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) { … }
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) { … }
class QuicDispatcherTestStrayPacketConnectionId
: public QuicDispatcherTestBase { … };
INSTANTIATE_TEST_SUITE_P(…);
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) { … }
TEST_P(BufferedPacketStoreTest, DeliverEmptyPackets) { … }
TEST_P(BufferedPacketStoreTest, ReceiveRetransmittedCHLO) { … }
TEST_P(BufferedPacketStoreTest, ReceiveCHLOAfterExpiration) { … }
TEST_P(BufferedPacketStoreTest, ProcessCHLOsUptoLimitAndBufferTheRest) { … }
TEST_P(BufferedPacketStoreTest,
ProcessCHLOsUptoLimitAndBufferWithDifferentConnectionIdGenerator) { … }
TEST_P(BufferedPacketStoreTest, BufferDuplicatedCHLO) { … }
TEST_P(BufferedPacketStoreTest, BufferNonChloPacketsUptoLimitWithChloBuffered) { … }
TEST_P(BufferedPacketStoreTest, ReceiveCHLOForBufferedConnection) { … }
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) { … }
}
}
}