1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "net/tools/quic/quic_server.h"
7 #include "net/quic/crypto/quic_random.h"
8 #include "net/quic/quic_utils.h"
9 #include "net/tools/quic/test_tools/mock_quic_dispatcher.h"
10 #include "testing/gtest/include/gtest/gtest.h"
20 class QuicServerDispatchPacketTest
: public ::testing::Test
{
22 QuicServerDispatchPacketTest()
23 : crypto_config_("blah", QuicRandom::GetInstance()),
24 dispatcher_(config_
, crypto_config_
, 1234, &eps_
) {}
27 void MaybeDispatchPacket(const QuicEncryptedPacket
& packet
) {
28 IPEndPoint client_addr
, server_addr
;
29 QuicServer::MaybeDispatchPacket(&dispatcher_
, packet
,
30 client_addr
, server_addr
);
35 QuicCryptoServerConfig crypto_config_
;
37 MockQuicDispatcher dispatcher_
;
40 TEST_F(QuicServerDispatchPacketTest
, DoNotDispatchPacketWithoutGUID
) {
41 // Packet too short to be considered valid.
42 unsigned char invalid_packet
[] = { 0x00 };
43 QuicEncryptedPacket
encrypted_invalid_packet(
44 QuicUtils::AsChars(invalid_packet
), arraysize(invalid_packet
), false);
46 // We expect the invalid packet to be dropped, and ProcessPacket should never
48 EXPECT_CALL(dispatcher_
, ProcessPacket(_
, _
, _
, _
)).Times(0);
49 MaybeDispatchPacket(encrypted_invalid_packet
);
52 TEST_F(QuicServerDispatchPacketTest
, DispatchValidPacket
) {
53 unsigned char valid_packet
[] = {
54 // public flags (8 byte guid)
57 0x10, 0x32, 0x54, 0x76,
58 0x98, 0xBA, 0xDC, 0xFE,
59 // packet sequence number
60 0xBC, 0x9A, 0x78, 0x56,
64 QuicEncryptedPacket
encrypted_valid_packet(QuicUtils::AsChars(valid_packet
),
65 arraysize(valid_packet
), false);
67 EXPECT_CALL(dispatcher_
, ProcessPacket(_
, _
, _
, _
)).Times(1);
68 MaybeDispatchPacket(encrypted_valid_packet
);