summaryrefslogtreecommitdiffstats
path: root/net/quic/quic_crypto_server_stream_test.cc
diff options
context:
space:
mode:
authorrch@chromium.org <rch@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-13 03:23:57 +0000
committerrch@chromium.org <rch@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-13 03:23:57 +0000
commit72818ea6b7334c2a4b94aa78c4907c01e9720c1c (patch)
tree43520232e1d1a3a2d834d102af8984a67ecd61ce /net/quic/quic_crypto_server_stream_test.cc
parent1ba66adaad90e014692e02290cdb83c7b038a286 (diff)
downloadchromium_src-72818ea6b7334c2a4b94aa78c4907c01e9720c1c.zip
chromium_src-72818ea6b7334c2a4b94aa78c4907c01e9720c1c.tar.gz
chromium_src-72818ea6b7334c2a4b94aa78c4907c01e9720c1c.tar.bz2
Add QuicCryptoServerStream (and test) and get CryptoUtils working.
Review URL: https://chromiumcodereview.appspot.com/12452007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@187757 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/quic/quic_crypto_server_stream_test.cc')
-rw-r--r--net/quic/quic_crypto_server_stream_test.cc122
1 files changed, 122 insertions, 0 deletions
diff --git a/net/quic/quic_crypto_server_stream_test.cc b/net/quic/quic_crypto_server_stream_test.cc
new file mode 100644
index 0000000..995cb6b
--- /dev/null
+++ b/net/quic/quic_crypto_server_stream_test.cc
@@ -0,0 +1,122 @@
+// Copyright (c) 2012 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/quic/quic_crypto_server_stream.h"
+
+#include <map>
+#include <vector>
+
+#include "base/memory/scoped_ptr.h"
+#include "net/quic/crypto/crypto_framer.h"
+#include "net/quic/crypto/crypto_handshake.h"
+#include "net/quic/crypto/crypto_protocol.h"
+#include "net/quic/crypto/crypto_utils.h"
+#include "net/quic/crypto/quic_decrypter.h"
+#include "net/quic/crypto/quic_encrypter.h"
+#include "net/quic/quic_protocol.h"
+#include "net/quic/quic_session.h"
+#include "net/quic/test_tools/crypto_test_utils.h"
+#include "net/quic/test_tools/quic_test_utils.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace net {
+class QuicConnection;
+class ReliableQuicStream;
+} // namespace net
+
+using testing::_;
+
+namespace net {
+namespace test {
+namespace {
+
+// TODO(agl): Use rch's utility class for parsing a message when committed.
+class TestQuicVisitor : public NoOpFramerVisitor {
+ public:
+ TestQuicVisitor() {}
+
+ // NoOpFramerVisitor
+ virtual void OnStreamFrame(const QuicStreamFrame& frame) {
+ frame_ = frame;
+ }
+
+ QuicStreamFrame* frame() { return &frame_; }
+
+ private:
+ QuicStreamFrame frame_;
+
+ DISALLOW_COPY_AND_ASSIGN(TestQuicVisitor);
+};
+
+class TestSession: public QuicSession {
+ public:
+ TestSession(QuicConnection* connection, bool is_server)
+ : QuicSession(connection, is_server) {
+ }
+
+ MOCK_METHOD1(CreateIncomingReliableStream,
+ ReliableQuicStream*(QuicStreamId id));
+ MOCK_METHOD0(GetCryptoStream, QuicCryptoStream*());
+ MOCK_METHOD0(CreateOutgoingReliableStream, ReliableQuicStream*());
+};
+
+class QuicCryptoServerStreamTest : public ::testing::Test {
+ public:
+ QuicCryptoServerStreamTest()
+ : guid_(1),
+ addr_(),
+ connection_(new PacketSavingConnection(guid_, addr_)),
+ session_(connection_, true),
+ stream_(&session_) {
+ }
+
+ void ConstructHandshakeMessage() {
+ CryptoFramer framer;
+ message_data_.reset(framer.ConstructHandshakeMessage(message_));
+ }
+
+ void CompleteCryptoHandshake() {
+ CryptoTestUtils::HandshakeWithFakeClient(connection_, &stream_);
+ }
+
+ protected:
+ QuicGuid guid_;
+ IPEndPoint addr_;
+ PacketSavingConnection* connection_;
+ TestSession session_;
+ QuicCryptoServerStream stream_;
+ CryptoHandshakeMessage message_;
+ scoped_ptr<QuicData> message_data_;
+};
+
+TEST_F(QuicCryptoServerStreamTest, NotInitiallyConected) {
+ EXPECT_FALSE(stream_.handshake_complete());
+}
+
+TEST_F(QuicCryptoServerStreamTest, ConnectedAfterCHLO) {
+ CompleteCryptoHandshake();
+ EXPECT_TRUE(stream_.handshake_complete());
+}
+
+TEST_F(QuicCryptoServerStreamTest, MessageAfterHandshake) {
+ CompleteCryptoHandshake();
+ EXPECT_CALL(*connection_, SendConnectionClose(
+ QUIC_CRYPTO_MESSAGE_AFTER_HANDSHAKE_COMPLETE));
+ message_.tag = kCHLO;
+ ConstructHandshakeMessage();
+ stream_.ProcessData(message_data_->data(), message_data_->length());
+}
+
+TEST_F(QuicCryptoServerStreamTest, BadMessageType) {
+ message_.tag = kSHLO;
+ ConstructHandshakeMessage();
+ EXPECT_CALL(*connection_, SendConnectionClose(
+ QUIC_INVALID_CRYPTO_MESSAGE_TYPE));
+ stream_.ProcessData(message_data_->data(), message_data_->length());
+}
+
+} // namespace
+} // namespace test
+} // namespace net