summaryrefslogtreecommitdiffstats
path: root/net/tools/quic/quic_server_test.cc
diff options
context:
space:
mode:
authorrtenneti@chromium.org <rtenneti@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-07 10:06:37 +0000
committerrtenneti@chromium.org <rtenneti@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-07 10:06:37 +0000
commit76c35b092f13604b1dc552587b4854fc61394945 (patch)
treee0b1ff382f85bc69898976239ca8998990658386 /net/tools/quic/quic_server_test.cc
parent8e687077172d62eccbc3e150fc3fe8a36d1972f7 (diff)
downloadchromium_src-76c35b092f13604b1dc552587b4854fc61394945.zip
chromium_src-76c35b092f13604b1dc552587b4854fc61394945.tar.gz
chromium_src-76c35b092f13604b1dc552587b4854fc61394945.tar.bz2
Land Recent QUIC changes.
Move calls to dispatcher->ProcessPacket into a unit-testable method inside QuicServer. Currently checks if GUID is readable (and drops packet if not). Further checks on packet validity can be added here in future if this refactor looks ok. Added quic_server_test.cc for QuicServerDispatchPacketTest. Merge internal change: 50037642 QUIC - Added a comment to add getter/setter for Config class. Merge internal change: 50024203 Minor fix to finish using the retransmission_it before inserting a new entry into the retransmission_map_. Found when doing a code review for internal bug 10031572. Merge internal change: 49988308 Minor change to improve readability of CreateStreamFrame's sizing test. Merge internal change: 49942445 Added a comment to port LOG_IF_EVERY_N and control quic_packet_manager warnings. Merge internal change: 49834369 R=rch@chromium.org Review URL: https://chromiumcodereview.appspot.com/22253008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@216145 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/tools/quic/quic_server_test.cc')
-rw-r--r--net/tools/quic/quic_server_test.cc74
1 files changed, 74 insertions, 0 deletions
diff --git a/net/tools/quic/quic_server_test.cc b/net/tools/quic/quic_server_test.cc
new file mode 100644
index 0000000..7d1d669
--- /dev/null
+++ b/net/tools/quic/quic_server_test.cc
@@ -0,0 +1,74 @@
+// Copyright 2013 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 "net/tools/quic/quic_server.h"
+
+#include "net/quic/crypto/quic_random.h"
+#include "net/quic/quic_utils.h"
+#include "net/tools/quic/test_tools/mock_quic_dispatcher.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+using ::testing::_;
+
+namespace net {
+namespace tools {
+namespace test {
+
+namespace {
+
+class QuicServerDispatchPacketTest : public ::testing::Test {
+ public:
+ QuicServerDispatchPacketTest()
+ : crypto_config_("blah", QuicRandom::GetInstance()),
+ dispatcher_(config_, crypto_config_, 1234, &eps_) {}
+
+
+ void MaybeDispatchPacket(const QuicEncryptedPacket& packet) {
+ IPEndPoint client_addr, server_addr;
+ QuicServer::MaybeDispatchPacket(&dispatcher_, packet,
+ client_addr, server_addr);
+ }
+
+ protected:
+ QuicConfig config_;
+ QuicCryptoServerConfig crypto_config_;
+ EpollServer eps_;
+ MockQuicDispatcher dispatcher_;
+};
+
+TEST_F(QuicServerDispatchPacketTest, DoNotDispatchPacketWithoutGUID) {
+ // Packet too short to be considered valid.
+ unsigned char invalid_packet[] = { 0x00 };
+ QuicEncryptedPacket encrypted_invalid_packet(
+ QuicUtils::AsChars(invalid_packet), arraysize(invalid_packet), false);
+
+ // We expect the invalid packet to be dropped, and ProcessPacket should never
+ // be called.
+ EXPECT_CALL(dispatcher_, ProcessPacket(_, _, _, _)).Times(0);
+ MaybeDispatchPacket(encrypted_invalid_packet);
+}
+
+TEST_F(QuicServerDispatchPacketTest, DispatchValidPacket) {
+ unsigned char valid_packet[] = {
+ // public flags (8 byte guid)
+ 0x3C,
+ // guid
+ 0x10, 0x32, 0x54, 0x76,
+ 0x98, 0xBA, 0xDC, 0xFE,
+ // packet sequence number
+ 0xBC, 0x9A, 0x78, 0x56,
+ 0x34, 0x12,
+ // private flags
+ 0x00 };
+ QuicEncryptedPacket encrypted_valid_packet(QuicUtils::AsChars(valid_packet),
+ arraysize(valid_packet), false);
+
+ EXPECT_CALL(dispatcher_, ProcessPacket(_, _, _, _)).Times(1);
+ MaybeDispatchPacket(encrypted_valid_packet);
+}
+
+} // namespace
+} // namespace test
+} // namespace tools
+} // namespace net