| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/tools/quic/quic_server.h" | 5 #include "net/tools/quic/quic_server.h" |
| 6 | 6 |
| 7 #include "net/quic/crypto/quic_random.h" | 7 #include "net/quic/crypto/quic_random.h" |
| 8 #include "net/quic/quic_utils.h" | 8 #include "net/quic/quic_utils.h" |
| 9 #include "net/tools/quic/test_tools/mock_quic_dispatcher.h" | 9 #include "net/tools/quic/test_tools/mock_quic_dispatcher.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 | 11 |
| 12 using ::testing::_; | 12 using ::testing::_; |
| 13 | 13 |
| 14 namespace net { | 14 namespace net { |
| 15 namespace tools { | 15 namespace tools { |
| 16 namespace test { | 16 namespace test { |
| 17 | 17 |
| 18 namespace { | 18 namespace { |
| 19 | 19 |
| 20 class QuicServerDispatchPacketTest : public ::testing::Test { | 20 class QuicServerDispatchPacketTest : public ::testing::Test { |
| 21 public: | 21 public: |
| 22 QuicServerDispatchPacketTest() | 22 QuicServerDispatchPacketTest() |
| 23 : crypto_config_("blah", QuicRandom::GetInstance()), | 23 : crypto_config_("blah", QuicRandom::GetInstance()), |
| 24 dispatcher_(config_, crypto_config_, 1234, &eps_) {} | 24 dispatcher_(config_, crypto_config_, 1234, &eps_) {} |
| 25 | 25 |
| 26 | 26 void DispatchPacket(const QuicEncryptedPacket& packet) { |
| 27 void MaybeDispatchPacket(const QuicEncryptedPacket& packet) { | |
| 28 IPEndPoint client_addr, server_addr; | 27 IPEndPoint client_addr, server_addr; |
| 29 QuicServer::MaybeDispatchPacket(&dispatcher_, packet, | 28 dispatcher_.ProcessPacket(server_addr, client_addr, packet); |
| 30 client_addr, server_addr); | |
| 31 } | 29 } |
| 32 | 30 |
| 33 protected: | 31 protected: |
| 34 QuicConfig config_; | 32 QuicConfig config_; |
| 35 QuicCryptoServerConfig crypto_config_; | 33 QuicCryptoServerConfig crypto_config_; |
| 36 EpollServer eps_; | 34 EpollServer eps_; |
| 37 MockQuicDispatcher dispatcher_; | 35 MockQuicDispatcher dispatcher_; |
| 38 }; | 36 }; |
| 39 | 37 |
| 40 TEST_F(QuicServerDispatchPacketTest, DoNotDispatchPacketWithoutGUID) { | 38 TEST_F(QuicServerDispatchPacketTest, DispatchPacket) { |
| 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); | |
| 45 | |
| 46 // We expect the invalid packet to be dropped, and ProcessPacket should never | |
| 47 // be called. | |
| 48 EXPECT_CALL(dispatcher_, ProcessPacket(_, _, _, _, _)).Times(0); | |
| 49 MaybeDispatchPacket(encrypted_invalid_packet); | |
| 50 } | |
| 51 | |
| 52 TEST_F(QuicServerDispatchPacketTest, DispatchValidPacket) { | |
| 53 unsigned char valid_packet[] = { | 39 unsigned char valid_packet[] = { |
| 54 // public flags (8 byte guid) | 40 // public flags (8 byte guid) |
| 55 0x3C, | 41 0x3C, |
| 56 // guid | 42 // guid |
| 57 0x10, 0x32, 0x54, 0x76, | 43 0x10, 0x32, 0x54, 0x76, |
| 58 0x98, 0xBA, 0xDC, 0xFE, | 44 0x98, 0xBA, 0xDC, 0xFE, |
| 59 // packet sequence number | 45 // packet sequence number |
| 60 0xBC, 0x9A, 0x78, 0x56, | 46 0xBC, 0x9A, 0x78, 0x56, |
| 61 0x34, 0x12, | 47 0x34, 0x12, |
| 62 // private flags | 48 // private flags |
| 63 0x00 }; | 49 0x00 }; |
| 64 QuicEncryptedPacket encrypted_valid_packet(QuicUtils::AsChars(valid_packet), | 50 QuicEncryptedPacket encrypted_valid_packet(QuicUtils::AsChars(valid_packet), |
| 65 arraysize(valid_packet), false); | 51 arraysize(valid_packet), false); |
| 66 | 52 |
| 67 EXPECT_CALL(dispatcher_, ProcessPacket(_, _, _, _, _)).Times(1); | 53 EXPECT_CALL(dispatcher_, ProcessPacket(_, _, _)).Times(1); |
| 68 MaybeDispatchPacket(encrypted_valid_packet); | 54 DispatchPacket(encrypted_valid_packet); |
| 69 } | 55 } |
| 70 | 56 |
| 71 } // namespace | 57 } // namespace |
| 72 } // namespace test | 58 } // namespace test |
| 73 } // namespace tools | 59 } // namespace tools |
| 74 } // namespace net | 60 } // namespace net |
| OLD | NEW |