| Index: net/tools/quic/quic_dispatcher_test.cc
|
| diff --git a/net/tools/quic/quic_dispatcher_test.cc b/net/tools/quic/quic_dispatcher_test.cc
|
| index b70b348a67976f79ef9b57bd6b4a69d1648e4efa..6a382ad9aa8d5cea020191dec63f2a2fb1b755ea 100644
|
| --- a/net/tools/quic/quic_dispatcher_test.cc
|
| +++ b/net/tools/quic/quic_dispatcher_test.cc
|
| @@ -33,8 +33,8 @@ using base::StringPiece;
|
| using net::EpollServer;
|
| using net::test::ConstructEncryptedPacket;
|
| using net::test::CryptoTestUtils;
|
| -using net::test::MockConnection;
|
| -using net::test::MockConnectionHelper;
|
| +using net::test::MockQuicConnection;
|
| +using net::test::MockQuicConnectionHelper;
|
| using net::test::ValueRestore;
|
| using std::string;
|
| using std::vector;
|
| @@ -118,16 +118,16 @@ class TestDispatcher : public QuicDispatcher {
|
| // 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 MockConnection {
|
| +class MockServerConnection : public MockQuicConnection {
|
| public:
|
| MockServerConnection(QuicConnectionId connection_id,
|
| - MockConnectionHelper* helper,
|
| + MockQuicConnectionHelper* helper,
|
| MockAlarmFactory* alarm_factory,
|
| QuicDispatcher* dispatcher)
|
| - : MockConnection(connection_id,
|
| - helper,
|
| - alarm_factory,
|
| - Perspective::IS_SERVER),
|
| + : MockQuicConnection(connection_id,
|
| + helper,
|
| + alarm_factory,
|
| + Perspective::IS_SERVER),
|
| dispatcher_(dispatcher) {}
|
|
|
| void UnregisterOnConnectionClosed() {
|
| @@ -145,7 +145,7 @@ QuicServerSessionBase* CreateSession(
|
| const QuicConfig& config,
|
| QuicConnectionId connection_id,
|
| const IPEndPoint& client_address,
|
| - MockConnectionHelper* helper,
|
| + MockQuicConnectionHelper* helper,
|
| MockAlarmFactory* alarm_factory,
|
| const QuicCryptoServerConfig* crypto_config,
|
| QuicCompressedCertsCache* compressed_certs_cache,
|
| @@ -158,7 +158,7 @@ QuicServerSessionBase* CreateSession(
|
| ON_CALL(*connection, CloseConnection(_, _, _))
|
| .WillByDefault(WithoutArgs(Invoke(
|
| connection, &MockServerConnection::UnregisterOnConnectionClosed)));
|
| - EXPECT_CALL(*reinterpret_cast<MockConnection*>((*session)->connection()),
|
| + EXPECT_CALL(*reinterpret_cast<MockQuicConnection*>((*session)->connection()),
|
| ProcessUdpPacket(_, client_address, _));
|
|
|
| return *session;
|
| @@ -181,12 +181,12 @@ class QuicDispatcherTest : public ::testing::Test {
|
|
|
| ~QuicDispatcherTest() override {}
|
|
|
| - MockConnection* connection1() {
|
| - return reinterpret_cast<MockConnection*>(session1_->connection());
|
| + MockQuicConnection* connection1() {
|
| + return reinterpret_cast<MockQuicConnection*>(session1_->connection());
|
| }
|
|
|
| - MockConnection* connection2() {
|
| - return reinterpret_cast<MockConnection*>(session2_->connection());
|
| + MockQuicConnection* connection2() {
|
| + return reinterpret_cast<MockQuicConnection*>(session2_->connection());
|
| }
|
|
|
| // Process a packet with an 8 byte connection id,
|
| @@ -266,9 +266,15 @@ class QuicDispatcherTest : public ::testing::Test {
|
| time_wait_list_manager_);
|
| }
|
|
|
| + string SerializeCHLO() {
|
| + CryptoHandshakeMessage client_hello;
|
| + client_hello.set_tag(kCHLO);
|
| + return client_hello.GetSerialized().AsStringPiece().as_string();
|
| + }
|
| +
|
| EpollServer eps_;
|
| QuicEpollConnectionHelper helper_;
|
| - MockConnectionHelper mock_helper_;
|
| + MockQuicConnectionHelper mock_helper_;
|
| QuicEpollAlarmFactory alarm_factory_;
|
| MockAlarmFactory mock_alarm_factory_;
|
| QuicConfig config_;
|
| @@ -290,7 +296,7 @@ TEST_F(QuicDispatcherTest, ProcessPackets) {
|
| &dispatcher_, config_, 1, client_address, &mock_helper_,
|
| &mock_alarm_factory_, &crypto_config_,
|
| QuicDispatcherPeer::GetCache(&dispatcher_), &session1_)));
|
| - ProcessPacket(client_address, 1, true, false, "foo");
|
| + ProcessPacket(client_address, 1, true, false, SerializeCHLO());
|
| EXPECT_EQ(client_address, dispatcher_.current_client_address());
|
| EXPECT_EQ(server_address_, dispatcher_.current_server_address());
|
|
|
| @@ -299,39 +305,23 @@ TEST_F(QuicDispatcherTest, ProcessPackets) {
|
| &dispatcher_, config_, 2, client_address, &mock_helper_,
|
| &mock_alarm_factory_, &crypto_config_,
|
| QuicDispatcherPeer::GetCache(&dispatcher_), &session2_)));
|
| - ProcessPacket(client_address, 2, true, false, "bar");
|
| + ProcessPacket(client_address, 2, true, false, SerializeCHLO());
|
|
|
| - EXPECT_CALL(*reinterpret_cast<MockConnection*>(session1_->connection()),
|
| + EXPECT_CALL(*reinterpret_cast<MockQuicConnection*>(session1_->connection()),
|
| ProcessUdpPacket(_, _, _))
|
| .Times(1)
|
| .WillOnce(testing::WithArgs<2>(
|
| Invoke(this, &QuicDispatcherTest::ValidatePacket)));
|
| - ProcessPacket(client_address, 1, false, false, "eep");
|
| + ProcessPacket(client_address, 1, false, false, "data");
|
| }
|
|
|
| TEST_F(QuicDispatcherTest, StatelessVersionNegotiation) {
|
| - ValueRestore<bool> old_flag(&FLAGS_quic_stateless_version_negotiation, true);
|
| IPEndPoint client_address(net::test::Loopback4(), 1);
|
| server_address_ = IPEndPoint(net::test::Any4(), 5);
|
|
|
| EXPECT_CALL(dispatcher_, CreateQuicSession(1, client_address)).Times(0);
|
| QuicVersion version = static_cast<QuicVersion>(QuicVersionMin() - 1);
|
| - ProcessPacket(client_address, 1, true, version, "foo",
|
| - PACKET_8BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER, 1);
|
| -}
|
| -
|
| -TEST_F(QuicDispatcherTest, StatefulVersionNegotiation) {
|
| - ValueRestore<bool> old_flag(&FLAGS_quic_stateless_version_negotiation, false);
|
| - IPEndPoint client_address(net::test::Loopback4(), 1);
|
| - server_address_ = IPEndPoint(net::test::Any4(), 5);
|
| -
|
| - EXPECT_CALL(dispatcher_, CreateQuicSession(1, client_address))
|
| - .WillOnce(testing::Return(CreateSession(
|
| - &dispatcher_, config_, 1, client_address, &mock_helper_,
|
| - &mock_alarm_factory_, &crypto_config_,
|
| - QuicDispatcherPeer::GetCache(&dispatcher_), &session1_)));
|
| - QuicVersion version = static_cast<QuicVersion>(QuicVersionMin() - 1);
|
| - ProcessPacket(client_address, 1, true, version, "foo",
|
| + ProcessPacket(client_address, 1, true, version, SerializeCHLO(),
|
| PACKET_8BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER, 1);
|
| }
|
|
|
| @@ -344,9 +334,9 @@ TEST_F(QuicDispatcherTest, Shutdown) {
|
| &mock_alarm_factory_, &crypto_config_,
|
| QuicDispatcherPeer::GetCache(&dispatcher_), &session1_)));
|
|
|
| - ProcessPacket(client_address, 1, true, false, "foo");
|
| + ProcessPacket(client_address, 1, true, false, SerializeCHLO());
|
|
|
| - EXPECT_CALL(*reinterpret_cast<MockConnection*>(session1_->connection()),
|
| + EXPECT_CALL(*reinterpret_cast<MockQuicConnection*>(session1_->connection()),
|
| CloseConnection(QUIC_PEER_GOING_AWAY, _, _));
|
|
|
| dispatcher_.Shutdown();
|
| @@ -363,7 +353,7 @@ TEST_F(QuicDispatcherTest, TimeWaitListManager) {
|
| &dispatcher_, config_, connection_id, client_address, &mock_helper_,
|
| &mock_alarm_factory_, &crypto_config_,
|
| QuicDispatcherPeer::GetCache(&dispatcher_), &session1_)));
|
| - ProcessPacket(client_address, connection_id, true, false, "foo");
|
| + ProcessPacket(client_address, connection_id, true, false, SerializeCHLO());
|
|
|
| // Close the connection by sending public reset packet.
|
| QuicPublicResetPacket packet;
|
| @@ -382,11 +372,11 @@ TEST_F(QuicDispatcherTest, TimeWaitListManager) {
|
| .WillOnce(WithoutArgs(Invoke(
|
| reinterpret_cast<MockServerConnection*>(session1_->connection()),
|
| &MockServerConnection::UnregisterOnConnectionClosed)));
|
| - EXPECT_CALL(*reinterpret_cast<MockConnection*>(session1_->connection()),
|
| + EXPECT_CALL(*reinterpret_cast<MockQuicConnection*>(session1_->connection()),
|
| ProcessUdpPacket(_, _, _))
|
| .WillOnce(
|
| - Invoke(reinterpret_cast<MockConnection*>(session1_->connection()),
|
| - &MockConnection::ReallyProcessUdpPacket));
|
| + Invoke(reinterpret_cast<MockQuicConnection*>(session1_->connection()),
|
| + &MockQuicConnection::ReallyProcessUdpPacket));
|
| dispatcher_.ProcessPacket(IPEndPoint(), client_address, *received);
|
| EXPECT_TRUE(time_wait_list_manager_->IsConnectionIdInTimeWait(connection_id));
|
|
|
| @@ -397,7 +387,7 @@ TEST_F(QuicDispatcherTest, TimeWaitListManager) {
|
| .Times(1);
|
| EXPECT_CALL(*time_wait_list_manager_, AddConnectionIdToTimeWait(_, _, _, _))
|
| .Times(0);
|
| - ProcessPacket(client_address, connection_id, true, false, "foo");
|
| + ProcessPacket(client_address, connection_id, true, false, "data");
|
| }
|
|
|
| TEST_F(QuicDispatcherTest, NoVersionPacketToTimeWaitListManager) {
|
| @@ -413,7 +403,62 @@ TEST_F(QuicDispatcherTest, NoVersionPacketToTimeWaitListManager) {
|
| .Times(1);
|
| EXPECT_CALL(*time_wait_list_manager_, AddConnectionIdToTimeWait(_, _, _, _))
|
| .Times(1);
|
| - ProcessPacket(client_address, connection_id, false, false, "data");
|
| + ProcessPacket(client_address, connection_id, false, false, SerializeCHLO());
|
| +}
|
| +
|
| +TEST_F(QuicDispatcherTest, ProcessPacketWithZeroPort) {
|
| + CreateTimeWaitListManager();
|
| +
|
| + IPEndPoint client_address(net::test::Loopback4(), 0);
|
| + server_address_ = IPEndPoint(net::test::Any4(), 5);
|
| +
|
| + // dispatcher_ should drop this packet.
|
| + EXPECT_CALL(dispatcher_, CreateQuicSession(1, client_address)).Times(0);
|
| + EXPECT_CALL(*time_wait_list_manager_, ProcessPacket(_, _, _, _, _)).Times(0);
|
| + EXPECT_CALL(*time_wait_list_manager_, AddConnectionIdToTimeWait(_, _, _, _))
|
| + .Times(0);
|
| + ProcessPacket(client_address, 1, true, false, SerializeCHLO());
|
| +}
|
| +
|
| +TEST_F(QuicDispatcherTest, OKSeqNoPacketProcessed) {
|
| + IPEndPoint client_address(net::test::Loopback4(), 1);
|
| + QuicConnectionId connection_id = 1;
|
| + server_address_ = IPEndPoint(net::test::Any4(), 5);
|
| +
|
| + EXPECT_CALL(dispatcher_, CreateQuicSession(1, client_address))
|
| + .WillOnce(testing::Return(CreateSession(
|
| + &dispatcher_, config_, 1, client_address, &mock_helper_,
|
| + &mock_alarm_factory_, &crypto_config_,
|
| + QuicDispatcherPeer::GetCache(&dispatcher_), &session1_)));
|
| + // A packet whose packet number is the largest that is allowed to start a
|
| + // connection.
|
| + ProcessPacket(client_address, connection_id, true, false, SerializeCHLO(),
|
| + PACKET_8BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER,
|
| + kDefaultPathId,
|
| + QuicDispatcher::kMaxReasonableInitialPacketNumber);
|
| + EXPECT_EQ(client_address, dispatcher_.current_client_address());
|
| + EXPECT_EQ(server_address_, dispatcher_.current_server_address());
|
| +}
|
| +
|
| +TEST_F(QuicDispatcherTest, TooBigSeqNoPacketToTimeWaitListManager) {
|
| + CreateTimeWaitListManager();
|
| +
|
| + IPEndPoint client_address(net::test::Loopback4(), 1);
|
| + QuicConnectionId connection_id = 1;
|
| + // Dispatcher forwards this packet for this connection_id to the time wait
|
| + // list manager.
|
| + EXPECT_CALL(dispatcher_, CreateQuicSession(_, _)).Times(0);
|
| + EXPECT_CALL(*time_wait_list_manager_,
|
| + ProcessPacket(_, _, connection_id, _, _))
|
| + .Times(1);
|
| + EXPECT_CALL(*time_wait_list_manager_, AddConnectionIdToTimeWait(_, _, _, _))
|
| + .Times(1);
|
| + // A packet whose packet number is one to large to be allowed to start a
|
| + // connection.
|
| + ProcessPacket(client_address, connection_id, true, false, SerializeCHLO(),
|
| + PACKET_8BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER,
|
| + kDefaultPathId,
|
| + QuicDispatcher::kMaxReasonableInitialPacketNumber + 1);
|
| }
|
|
|
| // Enables mocking of the handshake-confirmation for stateless rejects.
|
| @@ -526,61 +571,6 @@ class QuicDispatcherStatelessRejectTest
|
| MockQuicCryptoServerStream* crypto_stream1_;
|
| };
|
|
|
| -TEST_F(QuicDispatcherTest, ProcessPacketWithZeroPort) {
|
| - CreateTimeWaitListManager();
|
| -
|
| - IPEndPoint client_address(net::test::Loopback4(), 0);
|
| - server_address_ = IPEndPoint(net::test::Any4(), 5);
|
| -
|
| - // dispatcher_ should drop this packet.
|
| - EXPECT_CALL(dispatcher_, CreateQuicSession(1, client_address)).Times(0);
|
| - EXPECT_CALL(*time_wait_list_manager_, ProcessPacket(_, _, _, _, _)).Times(0);
|
| - EXPECT_CALL(*time_wait_list_manager_, AddConnectionIdToTimeWait(_, _, _, _))
|
| - .Times(0);
|
| - ProcessPacket(client_address, 1, true, false, "foo");
|
| -}
|
| -
|
| -TEST_F(QuicDispatcherTest, OKSeqNoPacketProcessed) {
|
| - IPEndPoint client_address(net::test::Loopback4(), 1);
|
| - QuicConnectionId connection_id = 1;
|
| - server_address_ = IPEndPoint(net::test::Any4(), 5);
|
| -
|
| - EXPECT_CALL(dispatcher_, CreateQuicSession(1, client_address))
|
| - .WillOnce(testing::Return(CreateSession(
|
| - &dispatcher_, config_, 1, client_address, &mock_helper_,
|
| - &mock_alarm_factory_, &crypto_config_,
|
| - QuicDispatcherPeer::GetCache(&dispatcher_), &session1_)));
|
| - // A packet whose packet number is the largest that is allowed to start a
|
| - // connection.
|
| - ProcessPacket(client_address, connection_id, true, false, "data",
|
| - PACKET_8BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER,
|
| - kDefaultPathId,
|
| - QuicDispatcher::kMaxReasonableInitialPacketNumber);
|
| - EXPECT_EQ(client_address, dispatcher_.current_client_address());
|
| - EXPECT_EQ(server_address_, dispatcher_.current_server_address());
|
| -}
|
| -
|
| -TEST_F(QuicDispatcherTest, TooBigSeqNoPacketToTimeWaitListManager) {
|
| - CreateTimeWaitListManager();
|
| -
|
| - IPEndPoint client_address(net::test::Loopback4(), 1);
|
| - QuicConnectionId connection_id = 1;
|
| - // Dispatcher forwards this packet for this connection_id to the time wait
|
| - // list manager.
|
| - EXPECT_CALL(dispatcher_, CreateQuicSession(_, _)).Times(0);
|
| - EXPECT_CALL(*time_wait_list_manager_,
|
| - ProcessPacket(_, _, connection_id, _, _))
|
| - .Times(1);
|
| - EXPECT_CALL(*time_wait_list_manager_, AddConnectionIdToTimeWait(_, _, _, _))
|
| - .Times(1);
|
| - // A packet whose packet number is one to large to be allowed to start a
|
| - // connection.
|
| - ProcessPacket(client_address, connection_id, true, false, "data",
|
| - PACKET_8BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER,
|
| - kDefaultPathId,
|
| - QuicDispatcher::kMaxReasonableInitialPacketNumber + 1);
|
| -}
|
| -
|
| INSTANTIATE_TEST_CASE_P(QuicDispatcherStatelessRejectTests,
|
| QuicDispatcherStatelessRejectTest,
|
| ::testing::ValuesIn(GetStatelessRejectTestParams()));
|
| @@ -598,7 +588,7 @@ TEST_P(QuicDispatcherStatelessRejectTest, ParameterizedBasicTest) {
|
| CreateSessionBasedOnTestParams(connection_id, client_address)));
|
|
|
| // Process the first packet for the connection.
|
| - ProcessPacket(client_address, connection_id, true, false, "foo");
|
| + ProcessPacket(client_address, connection_id, true, false, SerializeCHLO());
|
| if (ExpectStatelessReject()) {
|
| // If this is a stateless reject, the crypto stream will close the
|
| // connection.
|
| @@ -618,13 +608,13 @@ TEST_P(QuicDispatcherStatelessRejectTest, ParameterizedBasicTest) {
|
| .Times(1);
|
| } else {
|
| // The second packet will trigger a packet-validation
|
| - EXPECT_CALL(*reinterpret_cast<MockConnection*>(session1_->connection()),
|
| + EXPECT_CALL(*reinterpret_cast<MockQuicConnection*>(session1_->connection()),
|
| ProcessUdpPacket(_, _, _))
|
| .Times(1)
|
| .WillOnce(testing::WithArgs<2>(
|
| Invoke(this, &QuicDispatcherTest::ValidatePacket)));
|
| }
|
| - ProcessPacket(client_address, connection_id, true, false, "foo");
|
| + ProcessPacket(client_address, connection_id, true, false, "data");
|
| }
|
|
|
| // Verify the stopgap test: Packets with truncated connection IDs should be
|
| @@ -684,14 +674,14 @@ class QuicDispatcherWriteBlockedListTest : public QuicDispatcherTest {
|
| &dispatcher_, config_, 1, client_address, &helper_, &alarm_factory_,
|
| &crypto_config_, QuicDispatcherPeer::GetCache(&dispatcher_),
|
| &session1_)));
|
| - ProcessPacket(client_address, 1, true, false, "foo");
|
| + ProcessPacket(client_address, 1, true, false, SerializeCHLO());
|
|
|
| EXPECT_CALL(dispatcher_, CreateQuicSession(_, client_address))
|
| .WillOnce(testing::Return(CreateSession(
|
| &dispatcher_, config_, 2, client_address, &helper_, &alarm_factory_,
|
| &crypto_config_, QuicDispatcherPeer::GetCache(&dispatcher_),
|
| &session2_)));
|
| - ProcessPacket(client_address, 2, true, false, "bar");
|
| + ProcessPacket(client_address, 2, true, false, SerializeCHLO());
|
|
|
| blocked_list_ = QuicDispatcherPeer::GetWriteBlockedList(&dispatcher_);
|
| }
|
| @@ -710,7 +700,7 @@ class QuicDispatcherWriteBlockedListTest : public QuicDispatcherTest {
|
| }
|
|
|
| protected:
|
| - MockConnectionHelper helper_;
|
| + MockQuicConnectionHelper helper_;
|
| MockAlarmFactory alarm_factory_;
|
| BlockingWriter* writer_;
|
| QuicDispatcher::WriteBlockedList* blocked_list_;
|
|
|